AN501-00003-2v0-E Memory FRAM 64 K (8 K x 8) Bit SPI MB85RS64 The example of connection between SPI FRAM and FM3 MCU AN501-00003-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-00003-2v0-E Revision History Rev Date Remark 2.0 2012.12.21 First Edition 2 AN501-00003-2v0-E Table of Contents Revision History...................................................................................................................... 2 Table of Contents.................................................................................................................... 3 Target products ....................................................................................................................... 4 1 Introduction...................................................................................................................... 5 2 SPI Interface Features .................................................................................................... 6 3 MB85RS64 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 .................................................................................................... 10 4.3.1 Basic Operation .............................................................................................. 10 4.3.2 FRAM Driver .................................................................................................... 11 4.3.3 Explanation of FRAM Driver Function ............................................................ 12 Other Information .......................................................................................................... 17 3 AN501-00003-2v0-E Target products This application note is described below products; Product Number MB85RS64 64 K(8 K x 8) Bit SPI FRAM 4 AN501-00003-2v0-E 1 Introduction This application note describes the communication method with FRAM by using the SPI interface of MB9B500 series and the sample program for communication. FRAM uses MB85RS64. 5 AN501-00003-2v0-E 2 SPI Interface Features The SPI interface is configured by 3 lines, which are data output (MOSI) from the master, data input (MISO) to the master, and serial clock (SCK). Each device connected to the bus can be specified by the chip select (CS). In addition, the relationship of master and slave is always established between devices. For details of the SPI interface, see the specifications and specialized books. 6 AN501-00003-2v0-E 3 MB85RS64 Features MB85RS64 is Ferroelectric Random Access Memory (FRAM) with 8,192 words x 8 bit structure. Access from MCU is possible by using the 3 wire serial interface (corresponds to SPI mode 0(0,0) and mode 2(1,1)). FRAM completes the write process at 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: MB85RS64 Pin arrangement diagram CS Chip select WP Write protect HOLD Hold SCK Serial clock SI Serial data input SO Serial data output VDD Power supply voltage GND Ground Table 3-1: Pin names and functions 7 AN501-00003-2v0-E 4 Sample Program 4.1 Hardware 4.1.1 Connection Example The following figure indicates the circuit diagram that connects MB9BF506R and MB85RS64 and executes SPI communication. In addition, the sample program is created based on this connection example. Fig. 4-1: Example of MB9BF506R and MB85RS64 connection 8 AN501-00003-2v0-E 4.2 Software The sample program that connects MB9BF506R and MB85RS64 and executes communication has the following functions. By using SPI function of MB9BF506R, write the specified size data from the beginning address of MB85RS64. Then, read the data of the same size as the write data from the beginning address. 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 of MB9BF506R and MB85RS64 in the foregoing figure. The pin connections are as follows. MB9BF506R Pin No. MB9BF506R Pin Name MB85RS64 Pin Name 81 MCSX6 CS 83 MCSX4 HOLD 84 SOT2_1 WP 97 SIN4_2 SI 98 SOT4_2 SO 99 SCK4_2 SCK Table 4-1: Pin connection of MB9BF506R of the sample program 9 AN501-00003-2v0-E 4.3 Sample Program 4.3.1 Basic Operation In this sample program, the specified size data are written from the beginning address of MB85RS64. Data of the same size as the write data are read from the beginning address of MB85RS64. Then, both data are compared to check for errors. 10 AN501-00003-2v0-E 4.3.2 FRAM Driver This section explains the driver function in the sample program that communicates with MB85RS64 by using the MB9BF506R SPI function. All function groups in this source are global functions. Include fram_spi.h when using the functions. Fig. 4-2: Flowchart of the sample program 11 AN501-00003-2v0-E 4.3.3 Explanation of FRAM Driver Function Function Name fram_spi_init Parameter void Return Value int Introduction Initializes the SPI function that is necessary for communication with FRAM. When initialization fails, returns ERROR(-1). When succeeds, returns SUCCESS(0). Function Name fram_spi_uninit Parameter void Return Value int Introduction Cancels initialization of SPI function. When initialization fails, returns ERROR(-1). When succeeds, returns SUCCESS(0). Function Name CSLow Parameter void Return Value void Introduction Sets CS Pin to Low. Function Name CSHigh Parameter void Return Value void Introduction Sets CS Pin to High. 12 AN501-00003-2v0-E Function Name fram_spi_write Parameter unsigned short addr, unsigned char* data, int32_t size Return Value int Introduction By using SPI, executes the Write command to FRAM. Parameter addr is the write address to FRAM. Parameter data is the write source pointer. Parameter size is the write byte size. The return value becomes SUCCESS(0) after the completion of write process 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, Writing 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] = 0x01; data[2] = 0x02; 7. size = 3; 8. ret = fram_spi_write(addr,data,size); By using fram_spi_write, data writing with specified size is possible from the specified address. In above example, substitute the write address to 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, do not execute the write process and returns an error. 13 AN501-00003-2v0-E Fig. 4-4: Flowchart of function fram_spi_write 14 AN501-00003-2v0-E Function Name fram_spi_write Parameter unsigned short addr, unsigned char* data, int32_t size Return Value int Introduction By using SPI, executes the Write command to FRAM. Parameter addr is the write address to FRAM. Parameter data is the write source pointer. Parameter size is the write byte size. The return value becomes SUCCESS(0) after the completion of write process 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, Writing is not executed and returns to the call source. Example of usage 9. unsigned short addr; 10. unsigned char data[3]; 11. int32_t size; 12. int ret; 13. addr = 0x0010; 14. data[0] = 0x00; data[1] = 0x01; data[2] = 0x02; 15. size = 3; 16. ret = fram_spi_write(addr,data,size); By using fram_spi_write, data writing with specified size is possible from the specified address. In above example, substitute the write address to 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, do not execute the write process and returns an error. 15 AN501-00003-2v0-E Fig. 4-5: Flowchart of function fram_spi_write 16 AN501-00003-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