SPI COMMUNICATION TO/FROM SERIAL EEPROM

Similar documents
F²MC-16LX FAMILY MB90F897 DUAL OPERATION FLASH 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

FR FAMILY FR60 FAMILY ISR DOUBLE EXECUTION 32-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

Fujitsu Microelectronics Europe Application Note MCU-AN E-V12 F²MC-16FX FAMILY 16-BIT MICROCONTROLLER ALL SERIES CLOCK OUTPUT APPLICATION NOTE

MB90F3XX/F4XX/F5XX/F8XX/F9XX

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 FR FAMILY 32-BIT MICROCONTROLLER MB91460 REAL TIME CLOCK APPLICATION NOTE

F²MC-16FX FAMILY ALL SERIES FLASH SECURITY 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

F²MC-8L FAMILY MB89201 SERIES FLASH PROGRAMMING 8-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

CPU369-Module Documentation. Fujitsu Microelectronics Europe GmbH Am Siebenstein Dreieich-Buchschlag, Germany

F²MC-16LX FAMILY MB90XXX RELOCATED INTERRUPT VECTOR TABLE 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

F²MC-8FX FAMILY MB951XX SERIES SYNCHRONOUS FLASH PROGRAMMING 8-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

EMULATOR SETUP MB BIT COMPACT-ICE

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 F²MC-FR FAMILY 32-BIT MICROCONTROLLER MB91460 RELOAD TIMER APPLICATION NOTE

TRACE APPLICATION NOTE VERSION MB86R0X 'JADE' SERIES DEVICES & GREENHILLS TOOLCHAIN. Fujitsu Microelectronics Europe Application Note

F2MC MB90385 series Evaluation Board Documentation. Revision Date Comment V New document

Errata Sheet MB86296 Coral PA

APIX AUTOMOTIVE SHELL SW-EMULATION USE CASE

The Bootconcept. of Fujitsu s MB91360 Devices

16-Bit Emulator Setup for MB2141 and MB

F²MC-16FX FAMILY MB96340 KEY MATRIX INTERFACE USING I/O PORT 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

GRAPHICS CONTROLLERS SPRITE ENGINE PERFORMANCE MB88F332 'INDIGO' MB88F333 'INDIGO-L' APPLICATION NOTE GRAPHICS COMPETENCE CENTER

F²MC-8FX FAMILY MB95100 SERIES EMULATOR HW SETUP 8-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

Fujitsu Semiconductor Europe User Manual. FSEUGCC-UM_SK-86R12-CPU01_Rev1.1 EMERALD-P CPU MODULE SK-86R12-CPU01 USERGUIDE

Application Note. EMC Design Guide. F 2 MC-8L Family. History 04 th Jul 02 NFL V1.0 new version

F²MC-16FX FAMILY ALL SERIES STANDBY MODES & POWER MANAGEMENT 16-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

JASMINE- Subboard Documentation. Fujitsu Microelectronics Europe GmbH Am Siebenstein Dreieich-Buchschlag, Germany

FAQ list for MB86290 Cremson

Application Note. Connecting standard LCD modules to. the MB90670/5 series. History 01 th Feb. 97 MM V1.0 started 28 th June 00 TKa V1.

The following document contains information on Cypress products.

Emulator Setup Instructions for MB91360

Application Note. Startup DevKit16. History 19 th June 00 TKa V1.0 started 20 th June 00 TKa V1.1 Some minor text corrections

EMULATOR SYSTEM MB

FR FAMILY MB91460 SERIES MB91461 EMULATION 32-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

Software Porting Access Library V02 to V03

LAMP CONTROL AND MONITOR WITH PPG AND ADC

Fujitsu Semiconductor Europe Application Note. an-mb86r12-apixprbs-rev0-20 MB86R12 EMERALD-P REV 0.2 APIX PRBS APPLICATION NOTE

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 FR FAMILY 32-BIT MICROCONTROLLER MB91460 EDSU/MPU APPLICATION NOTE

GRAPHICS CONTROLLERS DEVICE SETUP AND FUJITSU DEVELOPER SUITE

MB88F334 Indigo2 MB88F335 Indigo2-S MB88F336 Indigo2-N

FR FAMILY SK MAIN V1.2 EVALUATION BOARD USER GUIDE. Fujitsu Microelectronics Europe User Guide FMEMCU-UG

Fujitsu Microelectronics Europe Application Note MCU-AN E-V10 FR FAMILY 32-BIT MICROCONTROLLER MB91460 USART APPLICATION NOTE

Application Note APIX PRBS

F²MC-8L/16LX/FR FAMILY ALL SERIES GALEP-4 8/16/32-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

SC2000 Smart Kit Selection Checklist

Fujitsu Semiconductor Europe User Manual. FSEUGCC-UM_SK-88F336-01_Rev1.0 INDIGO2-N STARTERKIT SK-88F USER MANUAL

F²MC-16LX/FRLITE FAMILY COMPARISON OF MB90340 AND MB91270 SERIES MCU

Fujitsu Microelectronics Europe Application Note MCU-AN E-V13 FR FAMILY 32-BIT MICROCONTROLLER MB91460 SWB MONITOR DEBUGGER APPLICATION NOTE

F²MC-8L/16LX/16FX/FR FAMILY

FR30 example interface to external Flash Memory

Fujitsu Microelectronics Europe User Guide FMEMCU-SG MB88121 SERIES MB91460 SERIES EVALUATION BOARD SK-91F467-FLEXRAY SOFTWARE GUIDE

Errata Sheet MB86298 'Ruby'

GRAPHICS CONTROLLERS

1.2. MCU64 Board User Guide. Development tools for 16LX Family FUJITSU MICROELECTRONICS EUROPE. Version

GRAPHICS CONTROLLERS APIX PCB-DESIGN GUIDELINE

F²MC-8FX FAMILY MB95200H/210H SERIES LIN-UART 8-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics (Shanghai) Co., Ltd.

MB86297A Carmine PCB Design Guide

Tutorial. How to use Keil µvision with Spansion templates Spansion Inc.

1. Specifications Functions Used Operation Software Flowcharts Program Listing... 13

Fujitsu Microelectronics Europe Application Note MCU-AN E-V12 FR FAMILY 32-BIT MICROCONTROLLER MB91265 SERIES 16-BIT MAC UNIT APPLICATION NOTE

AN F²MC-16FX Family, I2C. Contents. 1 Introduction. This application note describes how to communicate via I2C with a Serial EEPROM.

Using LPC11Axx EEPROM (with IAP)

AN Multifunction Serial Interface of FM MCU. Contents. 1 Introduction

Fujitsu Microelectronics Europe User Guide FMEMCU-UG MB88121 SERIES MB91460 SERIES STARTER KIT SK-91F467-FLEXRAY USER GUIDE

Fujitsu Semiconductor Europe User Manual. FSEUGCC-UM_MB86R11_Rev1.4 EMERALD-L EVALUATION BASE BOARD SK-86R11-BASE USERGUIDE

STARTERKIT SK-86R03 'JADE-L' USERS GUIDE

Application Note, V1.0, Jul AP XC16x. Interfacing the XC16x Microcontroller to a Serial SPI EEPROM. Microcontrollers

FR FAMILY MB91460 SERIES FLASH PROGRAMMING 32-BIT MICROCONTROLLER APPLICATION NOTE. Fujitsu Microelectronics Europe Application Note

End User License Agreement

Section 5 SERCOM. Tasks SPI. In this section you will learn:

Fujitsu Microelectronics Europe User Guide FMEMCU-UG MB88121 SERIES MB91460 SERIES STARTER KIT SK-91F467-FLEXRAY USER GUIDE

Ethernet1 Xplained Pro

ssj1708 User s Manual Version 1.3 Revised February 2nd, 2009 Created by the J1708 Experts

FME FR FLASHPROGRAMMER

Multifunction Serial Interface (PDL_MFS) Features. General Description. When to Use a PDL_MFS Component. Quick Start 1.0

USER GUIDE EDBG. Description

< W3150A+ / W5100 Application Note for SPI >

AN510 Using SPI protocol with pressure sensor modules

PCMCIA Flash Card User Guide

AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Features. Introduction. AVR 8-bit Microcontrollers APPLICATION NOTE

SOFTUNE WORKBENCH MONITOR DEBUGGER FOR 8FX

EDBG. Description. Programmers and Debuggers USER GUIDE

ATAES132A Firmware Development Library. Introduction. Features. Atmel CryptoAuthentication USER GUIDE

FAQ list for Coral. Fujitsu Microelectronics Europe GmbH

One 32-bit counter that can be free running or generate periodic interrupts

VAR-EXT-CB8 Datasheet Camera Extension Board for VAR-DT8MCustomBoard & SPEAR-MX8CustomBoard V 1.x

More on the 9S12 SPI Using the Dallas Semiconductor DS1302 Real Time Clock with the 9S12 SPI

ATECC108/ATSHA204 USER GUIDE. Atmel Firmware Library. Features. Introduction

F²MC-8FX FAMILY MB95200H/210H SERIES HOW TO USE DBG PIN 8-BIT MICROCONTROLLER APPLICATION NOTE

USER GUIDE. Wireless Production Test Reference Protocol Specification Document. Atmel MCU Wireless. Description

EE 456 Fall, Table 1 SPI bus signals. Figure 1 SPI Bus exchange of information between a master and a slave.

AtlonA. 1x12 HDMI Distribution Amplifier v1.3 AT-HD-V112. User Manual

F²MC-8FX FAMILY MB95F310 SERIES. Parallel Programming Reference Solution 8-BIT MICROCONTROLLER APPLICATION NOTE

Instruction Sheet. PCS Series. Fiber\Cable Management Spool

Smart Card Bridge to Full-Speed USB, SPI, and UART Interfaces

Emulating Dual SPI Using FlexIO

UM2330 User manual. ST8500 boot. Introduction

EVB-USB2640 Evaluation Board Revision A

F²MC-8FX FAMILY MB95200H/210H SERIES HOW TO USE DBG PIN 8-BIT MICROCONTROLLER APPLICATION NOTE

AVR1315: Accessing the XMEGA EEPROM. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

How to use the NTAG I²C plus for bidirectional communication. Rev June

(Version 1.0) 2011 WIZnet Co., Ltd. All Rights Reserved. For more information, visit our website at

Transcription:

Fujitsu Microelectronics Europe Application ote MCU-A-390104-E-V11 F²MC-8L/16LX FAMIL 8/16-BIT MICROCOTROLLER MB90340 SPI COMMUICATIO TO/FROM SERIAL EEPROM (for M93CS46) APPLICATIO OTE

SPI COMMUICATIO TO/FROM SERIAL EEPROM Revision History Revision History Date 2003-04-26 V1.0; MWi 2003-04-29 V1.1: MWi; Flowcharts added Issue This document contains 19 pages. MCU-A-390104-E-V11-2 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Warranty and Disclaimer Warranty and Disclaimer To the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH restricts its warranties and its liability for all products delivered free of charge (eg. software include or header files, application examples, target boards, evaluation boards, engineering samples of IC s etc.), its performance and any consequential damages, on the use of the Product in accordance with (i) the terms of the License Agreement and the Sale and Purchase Agreement under which agreements the Product has been delivered, (ii) the technical descriptions and (iii) all accompanying written materials. In addition, to the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH disclaims all warranties and liabilities for the performance of the Product and any consequential damages in cases of unauthorised decompiling and/or reverse engineering and/or disassembling. ote, all these products are intended and must only be used in an evaluation laboratory environment. 1. Fujitsu Microelectronics Europe GmbH warrants that the Product will perform substantially in accordance with the accompanying written materials for a period of 90 days form the date of receipt by the customer. Concerning the hardware components of the Product, Fujitsu Microelectronics Europe GmbH warrants that the Product will be free from defects in material and workmanship under use and service as specified in the accompanying written materials for a duration of 1 year from the date of receipt by the customer. 2. Should a Product turn out to be defect, Fujitsu Microelectronics Europe GmbH s entire liability and the customer s exclusive remedy shall be, at Fujitsu Microelectronics Europe GmbH s sole discretion, either return of the purchase price and the license fee, or replacement of the Product or parts thereof, if the Product is returned to Fujitsu Microelectronics Europe GmbH in original packing and without further defects resulting from the customer s use or the transport. However, this warranty is excluded if the defect has resulted from an accident not attributable to Fujitsu Microelectronics Europe GmbH, or abuse or misapplication attributable to the customer or any other third party not relating to Fujitsu Microelectronics Europe GmbH. 3. To the maximum extent permitted by applicable law Fujitsu Microelectronics Europe GmbH disclaims all other warranties, whether expressed or implied, in particular, but not limited to, warranties of merchantability and fitness for a particular purpose for which the Product is not designated. 4. To the maximum extent permitted by applicable law, Fujitsu Microelectronics Europe GmbH s and its suppliers liability is restricted to intention and gross negligence. O LIABILIT FOR COSEQUETIAL DAMAGES To the maximum extent permitted by applicable law, in no event shall Fujitsu Microelectronics Europe GmbH and its suppliers be liable for any damages whatsoever (including but without limitation, consequential and/or indirect damages for personal injury, assets of substantial value, loss of profits, interruption of business operation, loss of information, or any other monetary or pecuniary loss) arising from the use of the Product. Should one of the above stipulations be or become invalid and/or unenforceable, the remaining stipulations shall stay in full effect Fujitsu Microelectronics Europe GmbH - 3 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Contents Contents REVISIO HISTOR... 2 WARRAT AD DISCLAIMER... 3 COTETS... 4 0 ITRODUCTIO... 5 1 M93CS46... 6 1.1 EEPROM... 6 1.2 Connection to MB90340... 6 1.3 Communication Timing... 7 1.3.1 Write Cycle Timing of M93CS46... 7 1.3.2 Read Cycle Timing of M93CS46... 7 1.3.3 EEPROM Busy Timing... 7 1.3.4 Leading Zeros... 8 1.4 Used EEPROM Commands... 8 1.5 Example Code... 8 1.5.1 Initial Functions and Declarations... 9 1.5.1.1 Flowchart... 9 1.5.1.2 C Code... 10 1.5.2 Write Enable and Write Disable... 11 1.5.2.1 Flowchart... 11 1.5.2.2 C Code... 12 1.5.3 Write to EEPROM... 13 1.5.3.1 Flowchart... 13 1.5.3.2 C Code... 14 1.5.4 Read from EEPROM... 15 1.5.4.1 Flowchart... 15 1.5.4.2 C Code... 16 1.5.5 Example of usage of EEPROM functions in Main Function... 17 1.5.5.1 Flowchart... 17 1.5.5.2 C Code... 18 2 BIBLIOGRAPH... 19 2.1 Related Documents... 19 MCU-A-390104-E-V11-4 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Introduction 0 Introduction This application note describes how to communicate via SPI using the MB90340-UART with a serial EEPROM. In this note a M93CS46 EEPROM from ational Semiconductor is used. Please note, that this document only gives a rough overview about the communication. The described source codes were written for understanding not for code size or speed. either interrupts nor timer were used. Time critical program code is always performed by simple flag polling or wait loops. Please also refer to the Application ote mcu-an-300002-e-spi for further SPI specification and nomenclature. Fujitsu Microelectronics Europe GmbH - 5 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1 M93CS46 THIS CHAPTER DESCRIBES HOW TO COMMUICATE WITH THE M93CS46 EEPROM 1.1 EEPROM The M93CS46 serial EEPROM from ational Semiconductor has 2048-Bit memory size, organized as 64 16-Bit-Words. The M93CS46 has the following pin-out: CS 1 8 Vcc SK 2 7 PRE DI 3 6 PE DO 4 5 GD Pin names: CS SK DI DO GD PE PRE* Vcc Chip Select Serial Data Clock Serial Data Input Serial Data Output Ground Program Enable Protect Register Enable Power Supply (+ 5 volts) 1.2 Connection to MB90340 The EEPROM can be connected as in the following schematic. Please note, that no power supply pins and other MCU-Pins are drawn than those for the connection to the EEPROM. * * PRE is not used in the code example below. MCU-A-390104-E-V11-6 - Fujitsu Microelectronics Europe GmbH-10

1.3 Communication Timing SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 Detailed description of the timing and timing parameters can be found in the corresponding datasheet of the M93CS46 EEPROM. 1.3.1 Write Cycle Timing of M93CS46 A write cycle (write to EEPROM) has the following bit timing (SPI-CPOL = 1, SPI-CPHA = 1): CS SCK SOT (DI) D7 D6 D5 D4 D3 D2 D1 D0 Data sampling of the EEPROM is performed at the rising edge of the SCK signal. 1.3.2 Read Cycle Timing of M93CS46 Unfortunately the read cycle has a different timing. The M93CS46-EEPROM does not assert the first data bit after CS goes 0, but on the rising edge of the first serial clock: CS SCK SI (DO) D7 D6 D5 D4 D3 D2 D1 D0 The red arrow denotes the sampling time of the UART, if the clock delay by a half cycle (SPI-CPHA) is disabled (ECCR-SCDE = 0). The workaround, which is presented here, is to switch the SPI-CPHA = 0 (SCDE = 0) just before reading the EEPROM out. This can be performed, because writing to and reading from the EEPROM does not overlap. After reading the bits, the communication is set back to SPI-CPHA = 1 (ECCR-SCDE = 1). 1.3.3 EEPROM Busy Timing After writing data to the EEPROM it signals a busy state by setting a 0 to the serial output (DO/SI). After the busy state the pin goes to 1. In the code example below, this busy wait is simply performed by polling the serial input of the UART (ESCR-SIOP) in two steps. First step is waiting for 0, the second is waiting for 1. Fujitsu Microelectronics Europe GmbH - 7 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 Because the busy state can take up to 10 ms, a time critical software should use a timer for this, to save CPU performance. 1.3.4 Leading Zeros The commands to the EEPROM are 9-Bit or 25-Bit wide. This does not fit into the 8-Bit pattern of the UART synchronous mode. In the code example below a workaround for this is used. Because the EEPROM ignores leading Zero-Bits, the first byte is used to adjust the bit stream, using leading Zeros. Example: A WE (Write enable) command is sent to the EEPROM, which is composed of the following bit stream: 1 0011 XXXX. These are 9 Bits. The UART sends the following bit stream instead: 0000 0001 0011 XXXX. The blue 0s are the leading Zeros, which are ignored by the EEPROM. This bit stream is represented by the bytes 0x01 and 0x3X (MSB first). 1.4 Used EEPROM Commands The following EEPROM commands are used in the code example below: Instr. Op Code Address Data PE Pin Comments READ 110 A5-A0 X Read data stored in memory WE 100 11XXXX 1 Enable programming (write enable) WRITE 101 A5-A0 D15-D0 1 Write data to address WDS 100 00XXXX D15-D0 1 Disable programming (write disable) Commands which need the PRE-Pin are not used in the code example below. 1.5 Example Code The following code shows how to establish a communication to and from the EEPROM. MCU-A-390104-E-V11-8 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.1 Initial Functions and Declarations 1.5.1.1 Flowchart InitUART InitPorts wait Set Baud rate Set clock inversion (ESCR-SCES = 1) Set clock delay (ECCR-SCDE = 1) Set Port-Register 9 to 0x00 Set Port 90, 91, 92 to Output for CS-, PE- and PRE-Pin Argument: j Do loop of 4 OPs from 0 to j Reception and Transmission enable Set Mode 2, enable SCLK, enable SOT Set MSB first Fujitsu Microelectronics Europe GmbH - 9 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.1.2 C Code #define DATASIZE 64 // eeprom memory size in words (16 Bit) unsigned int data[datasize]; // data to sent to EEPROM unsigned int readbuffer[datasize]; // data received from EEPROM void InitUART(void) BGR0 = 15; // 1M Bit/s @ 16 MHz ESCR0 = 0x01; // SCES = 1 => CPOL = 1 ECCR0 = 0x10; // SCDE = 1 => CPHA = 1 SCR0 = 0x03; // reception and transmission enable SMR0 = 0x83; // Mode 2, SCLK enable, SOT enable SSR0 = 0x04; // MSB first, no interrupts void InitPorts(void) // Bit#2: CS, Bit#1: PE, Bit#0: PRE PDR9 = 0x00; // All Low DDR9 = 0x07; // CS, PE, PRE to output PDR0 = 0x00; DDR0 = 0xFF; // LED-Port on Flash-CA-100P-340 void wait(unsigned int j) volatile unsigned int i; for (i = 0; i < j; i++) #pragma asm OP OP OP OP #pragma endasm MCU-A-390104-E-V11-10 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.2 Write Enable and Write Disable 1.5.2.1 Flowchart write_enable Set CS=1 (PDR92 =1) write_disable Set CS=1 (PDR92 =1) TDRE == 0? TDRE == 0? Send Start-Bit with leading zeros (TDR = 0x01) Send Start-Bit with leading zeros (TDR = 0x01) TDRE == 0? TDRE == 0? Send WE command (TDR = 0x30) Send WDS command (TDR = 0x00) Transmission end? Transmission end? CS = 0 (PDR92 = 0) CS = 0 (PDR92 = 0) Fujitsu Microelectronics Europe GmbH - 11 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.2.2 C Code void write_enable(void) PDR9_P92 = 1; // CS = 1 while (SSR0_TDRE == 0); TDR0 = 0x01; while (SSR0_TDRE == 0); TDR0 = 0x30; while (ECCR0 & 0x01); while (!(ECCR0 & 0x01)); // Start-Bit (with "leading zeros") // WE command // wait for start of transmission // (or ongoing) // wait for transmission finished PDR9_P92 = 0; // CS = 0 void write_disable(void) PDR9_P92 = 1; // CS = 1 while (SSR0_TDRE == 0); TDR0 = 0x01; while (SSR0_TDRE == 0); TDR0 = 0x00; while (ECCR0 & 0x01); while (!(ECCR0 & 0x01)); // Start-Bit (with "leading zeros") // WDS command // wait for start of transmission // (or ongoing) // wait for transmission finished PDR9_P92 = 0; // CS = 0 ote, that the expression(eccr & 0x01) masks the Transmission Bus Idle Bit (TBI). MCU-A-390104-E-V11-12 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.3 Write to EEPROM 1.5.3.1 Flowchart Write_eeprom CS = 1 (P92 = 1) TDRE == 0? Send LSB Send Start-Bit with leading zeros (TDRE = 0x01) Calculate Command/Address-Byte Transmission end? CS = 0 (P92 = 0) Wait some ms TDRE == 0? CS = 1 (P92 = 1) Send Command/Address- Byte Busy? (SIOP == 1)? TDRE == 0? Send MSB TDRE == 0? Ready? (SIOP == 0)? CS = 0 (P92 = 0) Fujitsu Microelectronics Europe GmbH - 13 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.3.2 C Code void write_eeprom(unsigned char adr) unsigned char dout, command; PDR9_P92 = 1; // CS = 1 while (SSR0_TDRE == 0); TDR0 = 0x01; // Start-Bit (with "leading zeros") command = (adr & 0x3F) 0x40; // Address and Write-Instruction dout = command; while (SSR0_TDRE == 0); TDR0 = dout; dout = (data[adr] >> 8) & 0xFF; // MSB while (SSR0_TDRE == 0); TDR0 = dout; dout = data[adr] & 0xFF; while (SSR0_TDRE == 0); TDR0 = dout; while (ECCR0 & 0x01); while (!(ECCR0 & 0x01)); // LSB // wait for start of transmission // (or ongoing) // wait for transmission finished PDR9_P92 = 0; // CS = 0 wait(1); // ext function (waiting for busy release) is made by // polling. Please note, that for the M93CS46 EEPROM the // wait time can take till 10 ms! I. e. the CPU is then // also busy. For fast application a timer should be used, // which generates an interrupt after 10 ms from here, // so that the CPU can perform other jobs in this time. PDR9_P92 = 1; // CS = 1 while(escr0_siop == 1); // wait for eeprom busy while(escr0_siop == 0); // wait for eeprom busy release PDR9_P92 = 0; // CS = 0 ote, that the expression(eccr & 0x01) masks the Transmission Bus Idle Bit (TBI). MCU-A-390104-E-V11-14 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.4 Read from EEPROM 1.5.4.1 Flowchart Read_eeprom CS = 1 (P92 = 1) Send Start-Bit with leading zeros (TDRE = 0x01) Calculate Command/Address- Byte Clear possible reception errors (CRE = 1) Disable Clock delay for reception (SCDE = 0) Send dummy data to produce SCLK RDRF == 0? RDRF == 0? Flush Reception Register Read MSB Send Command/Address- Byte Send dummy data to produce SCLK RDRF == 0? RDRF == 0? Flush Reception Register Read LSB Re-enable Clock delay (SCDE = 1) CS = 0 (P92 = 0) Fujitsu Microelectronics Europe GmbH - 15 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.4.2 C Code void read_eeprom(unsigned char adr) unsigned char din, command, dout; PDR9_P92 = 1; // CS = 1 TDR0 = 0x01; // Start-Bit (with "leading zeros") command = (adr & 0x3F) 0x80; // Address and Write-Instruction dout = command; while (SSR0_RDRF == 0); // transmission finished (via // reception)? din = RDR0; // flush reception register TDR0 = dout; while (SSR0_RDRF == 0); din = RDR0; SCR0_CRE = 1; // transmission finished (via // reception)? // flush reception register // Clear possible errors, reset // reception state machine // OTE: Make sure, that SCK is "0" while setting SCDE to "0" // (ECCR0 = 0x00;) // In this case (1M bps) no check is needed. Be careful with // slower baud rates! ECCR0 = 0x00; TDR0 = 0x00; // SCDE = 0 => CPHA = 0 : eeded // for special read timing of // used EEPROM (may be not // necessary for other EEPROMs) // set dummy byte to produce SCLK while (SSR0_RDRF == 0); din = RDR0; readbuffer[adr] = (din << 8); while (SSR0_TDRE == 0); TDR0 = 0x00; // transmission finished (via // reception)? // MSB // set dummy byte to produce SCLK while (SSR0_RDRF == 0); din = RDR0; // LSB readbuffer[adr] = (readbuffer[adr] din); ECCR0 = 0x10; // SCDE = 1 => CPHA = 1 : Set back // for write timing PDR9_P92 = 0; // CS = 0 ote: Because reception is enabled and the UART is synchronous master, the UART always receives (dummy) data from SI. Therefore the Reception Data Register Full Flag (RDRF) can be used to determine transmission end, because UART generates the serial clock during (dummy) transmission. This is an alternative to using the Transmission Bus Idle Flag (TBI). MCU-A-390104-E-V11-16 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.5 Example of usage of EEPROM functions in Main Function 1.5.5.1 Flowchart main Create data (not in example) Flush Reception Register PE = 1 (P91 = 1) Call write_enable Clear possible Reception Errors Write data: Call write_eeprom Read data: Call read_eeprom All data written? All data read? READ PE = 0 (P91 = 0) WRITE Fujitsu Microelectronics Europe GmbH - 17 - MCU-A-390104-E-V11

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 1 M93CS46 1.5.5.2 C Code void main(void) unsigned char i, error, dummy; InitPorts(); InitUART(); // Initialize PRE, PE, and CS // Init UART for SPI communication // Put code or function call here to produce data for EEPROM // write data PDR9_P91 = 1; write_enable(); for (i = 0; i < DATASIZE; i++) write_eeprom(i); write_disable(); PDR9_P91 = 0; // Do something else... // PE = 1 must be set here // PE = 0 must be set here // read data dummy = RDR0; // flush read buffer SCR0_CRE = 1; // clear possible overruns for (i = 0; i < DATASIZE; i++) read_eeprom(i); // Add further code here... The code above writes to/reads from all 64 16-Bit-Words of the EEPROM. The functions void write_eeprom(unsigned char address) and void read_eeprom(unsigned char address) can also be used separately for single address access. MCU-A-390104-E-V11-18 - Fujitsu Microelectronics Europe GmbH-10

SPI COMMUICATIO TO/FROM SERIAL EEPROM Chapter 2 Bibliography 2 Bibliography THIS CHAPTER AMES THE RELATED DOCUMETS 2.1 Related Documents mcu-an-300002-e-spi Fujitsu Application ote about SPI Modes DS 93CS46 ational Semiconductor data sheet of M93CS46 Fujitsu Microelectronics Europe GmbH - 19 - MCU-A-390104-E-V11