AN501-00002-2v0-E Memory FRAM 64 K (8 K x 8) Bit I2C MB85RC64 The example of the connection between I2C FRAM and FM3 MCU AN501-00002-2v0-E All Rights Reserved. ・FUJITSU SEMICONDUCTOR LIMITED, its subsidiaries and affiliates (collectively, “FUJITSU SEMICONDUCTOR”) reserves the right to make changes to the information contained in this document without notice. Please contact your FUJITSU SEMICONDUCTOR sales representatives before order of FUJITSU SEMICONDUCTOR device. ・Information contained in this document, such as descriptions of function and application circuit examples is presented solely for reference to examples of operations and uses of FUJITSU SEMICONDUCTOR device. FUJITSU SEMICONDUCTOR disclaims any and all warranties of any kind, whether express or implied, related to such information, including, without limitation, quality, accuracy, performance, proper operation of the device or non-infringement. If you develop equipment or product incorporating the FUJITSU SEMICONDUCTOR device based on such information, you must assume any responsibility or liability arising out of or in connection with such information or any use thereof. FUJITSU SEMICONDUCTOR assumes no responsibility or liability for any damages whatsoever arising out of or in connection with such information or any use thereof. ・Nothing contained in this document shall be construed as granting or conferring any right under any patents, copyrights, or any other intellectual property rights of FUJITSU SEMICONDUCTOR or any third party by license or otherwise, express or implied. . FUJITSU SEMICONDUCTOR assumes no responsibility or liability for any infringement of any intellectual property rights or other rights of third parties resulting from or in connection with the information contained herein or use thereof. ・The products described in this document are designed, developed and manufactured as contemplated for general use including without limitation, ordinary industrial use, general office use, personal use, and household use, but are not designed, developed and manufactured as contemplated (1) for use accompanying fatal risks or dangers that, unless extremely high levels of safety is secured, could lead directly to death, personal injury, severe physical damage or other loss (including, without limitation, use in nuclear facility, aircraft flight control system, air traffic control system, mass transport control system, medical life support system and military application), or (2) for use requiring extremely high level of reliability (including, without limitation, submersible repeater and artificial satellite). FUJITSU SEMICONDUCTOR shall not be liable for you and/or any third party for any claims or damages arising out of or in connection with above-mentioned uses of the products. ・Any semiconductor devices fail or malfunction with some probability. You are responsible for providing adequate designs and safeguards against injury, damage or loss from such failures or malfunctions, by incorporating safety design measures into your facility, equipments and products such as redundancy, fire protection, and prevention of overcurrent levels and other abnormal operating conditions. ・The products and technical information described in this document are subject to the Foreign Exchange and Foreign Trade Control Law of Japan, and may be subject to export or import laws or regulations in U.S. or other countries. You are responsible for ensuring compliance with such laws and regulations relating to export or re-export of the products and technical information described herein. ・All company names, brand names and trademarks herein are property of their respective owners. Copyright© 2012 FUJITSU SEMICONDUCTOR LIMITED all rights reserved 1 AN501-00002-2v0-E Revision History Rev Date Remark 2.0 2012.12.21 First Edition 2 AN501-00002-2v0-E Table of Contents Revision History...................................................................................................................... 2 Table of Contents.................................................................................................................... 3 Target products ....................................................................................................................... 4 1 Introduction...................................................................................................................... 5 2 I2C Interface Features ..................................................................................................... 6 3 MB85RC64 Features ...................................................................................................... 7 4 Sample Program ............................................................................................................. 8 4.1 Hardware.................................................................................................................. 8 4.1.1 5 Connection Example ........................................................................................ 8 4.2 Software ................................................................................................................... 9 4.3 Sample Program Structure .................................................................................... 10 4.3.1 Basic Operation .............................................................................................. 10 4.3.2 FRAM Driver .................................................................................................... 11 4.3.3 Example of FRAM Driver ................................................................................ 12 Other Information .......................................................................................................... 17 3 AN501-00002-2v0-E Target products This application note is described below products; Product Number MB85RC64 64 K(8 K x 8) Bit I2C FRAM 4 AN501-00002-2v0-E 1 Introduction This application note describes the communication method with FRAM by using the I2C interface of MB9B500 series and the sample program for communication. FRAM uses MB85RC64. 5 AN501-00002-2v0-E 2 I2C Interface Features The I2C interface is a data bus configured by only 2 signal wires, which are the serial data line (SDA) and the serial data clock (SCL). Specifying a unique address is possible for each device connected to the data bus. In addition, the relationship of master and slave is always established between devices. 8-bit bidirectional serial data transfer is possible at the maximum of 100 kbit/s in the standard mode, the maximum of 400 kbit/s in the fast mode, and the maximum of 3.4 Mbit/s in the high-speed mode. Our FRAM corresponds to the maximum of 1 Mbit/s. For details of the I2C interface, see the specifications and specialized books. 6 AN501-00002-2v0-E 3 MB85RC64 Features MB85RC64 is Ferroelectric Random Access Memory (FRAM) with 8,192 word x 8 bit structure, which has a 2-wire serial interface (world standard I2C BUS-compliant). Communication from MCU that has an I2C interface is possible. FRAM completes the write process in high speed when compared to the Flash memory or EEPROM. Therefore, FRAM does not have a sequence to wait for completion of the write process. The following section indicates the pin arrangement diagram and pin names. Fig. 3-1: MB85RC64 Pin arrangement diagram A0,A1,A2 Device Address VSS Ground SDA Serial data input/output SCL Serial clock WP Write protect VDD Power supply voltage Table 3-1: Pin names and functions 7 AN501-00002-2v0-E 4 Sample Program 4.1 Hardware 4.1.1 Connection Example The following figure indicates the circuit diagram that connects MB9BF506R and MB85RC64 and executes I2C communication. In addition, the sample program is created based on this connection example. Fig. 4-1: Example of MB9BF506R and MB85RC64 connection 8 AN501-00002-2v0-E 4.2 Software The sample program that connects MB9BF506R and MB85RC64 and executes communication has the following functions. By using the I2C function of MB9BF506R, write the specified size data from the beginning address of MB85RC64 with the Page Write function. Then, read the data of the same size as the write data from the beginning address with the Sequential Read function. Compare the write data and the read data, and confirm that the values are the same. This sample program is created with the prerequisite of the connection in Figure 4-1. The pin connections are as follows. MB9BF506R Pin No. MB9BF506R Pin Name MB85RC64 Pin Name 83 MCSX4 WP 98 SOT4_2 SDA 99 SCK4_2 SCL Table 4-1: Pin connection between MB9BF506R and MB85RC64 of the sample program 9 AN501-00002-2v0-E 4.3 Sample Program Structure 4.3.1 Basic Operation In this sample program, the specified size data are written from the beginning address of MB85RC64. Data of the same size as the write data are read from the beginning address of MB85RC64. Then, both data are compared to check for errors. 10 AN501-00002-2v0-E 4.3.2 FRAM Driver This section explains the driver function in the sample program that communicates with MB85RC64 by using MB9BF506R I2C function. All function groups in this source are global functions. Include fram_i2c.h when using the functions. Fig. 4-2: Flowchart of the sample program 11 AN501-00002-2v0-E 4.3.3 Example of FRAM Driver Function fram_i2c_init Name Parameter void Return Value int Introduction Initializes the I2C function that is necessary for communication with FRAM. When initialization fails, returns ERROR(-1). When succeeds, returns SUCCESS(0). Function fram_i2c_uninit Name Parameter void Return Value int Introduction Cancels initialization of I2C function. When initialization canceling fails, returns ERROR(-1). When succeeds, returns SUCCESS(0). 12 AN501-00002-2v0-E Function fram_i2c_write Name Parameter unsigned short addr, unsigned char* data, int32_t size Return Value int Introduction By using I2C, executes the Write command to FRAM. Parameter addr is the write address to FRAM. Parameter data is the write data pointer. Parameter size is the write byte size. The return value becomes SUCCESS(0) after the stop condition is issued and returns ERROR(-1) when parameter addr value is out of the FRAM area, when size is 0 or when the added value with addr is out of the FRAM area, or when parameter data is NULL. In addition, when the return value is ERROR, it does not execute writing and returns to the call source. Example of usage 1. unsigned short addr; 2. unsigned char data[3]; 3. int32_t size; 4. int ret; 5. addr = 0x0010; 6. data[0] = 0x00; data[1] = 0x01; data[2] = 0x02; 7. size = 3; 8. re t= fram_i2c_write(addr,data,size); By using fram_i2c_write, data writing with specified size is possible from the specified address. In above example, substitute the write address to the declared variable addr, the write data to data, and a number of bytes to size. Then call the function by specifying to the parameter as shown in item 8 above. In the above case, 0x00 is written to the address 0x0010, 0x01 to address 0x0011, and 0x02 to address 0x0012. In addition, substitute 0x000 to size. Or, when the total sum of addr and size exceeds 0x2000, the write process is not executed and returns an error. 13 AN501-00002-2v0-E Fig. 4-4: Flowchart of function fram_i2c_write 14 AN501-00002-2v0-E Function fram_i2c_read Name Parameter unsigned short addr, unsigned char* data, int32_t size Return Value int Introduction Execute the Read command to FRAM by using I2C. Parameter addr is the read address to FRAM. Parameter data is the read destination pointer. Parameter size is the read byte size. The return value becomes SUCCESS(0) after the stop condition is issued and returns ERROR(-1) when parameter addr value is out of the FRAM area, when size is 0 or when the added value with addr is out of the FRAM area, or when parameter data is NULL. In addition, when the return value is ERROR, Reading is not executed and returns to the call source. Example of usage 1. unsigned short addr; 2. unsigned char data[3]; 3. int32_t size; 4. int ret; 5. addr = 0x0010; 6. data[0] = 0x00; data[1] = 0x00; data[2] = 0x00; 7. size = 3; 8. ret = fram_i2c_read(addr,data,size); fram_i2c_read can continuously repeat Read until the stop condition is issued. In above example, substitute the read beginning address to declared variable addr, a number of read bytes to size. Then call the function by specifying to the parameter as shown in item 8 above. In the above case, read values of address 0x0010 is stored in data[0], address 0x0011 in data[1], and address 0x0012 in data[2]. In addition, substitute 0x000 to size. Or, when the total sum of addr and size exceeds 0x2000, reading is not executed and returns an error. 15 AN501-00002-2v0-E Fig. 4-5: Flowchart of function fram_i2c_read 16 AN501-00002-2v0-E 5 Other Information See the following website for details of MB85RC64 and MB9BF506, and other information regarding Fujitsu FRAM products and micro controller products. http://jp.fujitsu.com/fsl/ 17