Interface library for Ramtron FRAM memory, FM25VXX series.
Embed:
(wiki syntax)
Show/hide line numbers
FRAMSPI.h
00001 /* FRAM_SPI - Ramtron FRAM FM24VXX series driver 00002 * Copyright (c) 2012 Oleg Evsegneev 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 * 00005 * Datasheet http://www.ramtron.com/files/datasheets/FM25V02_ds.pdf 00006 */ 00007 00008 #ifndef FRAMSPI_ 00009 #define FRAMSPI_ 00010 00011 #include "mbed.h" 00012 00013 // commands 00014 #define READ 0x03 00015 #define WRITE 0x02 00016 #define READ_STATUS 0x05 // RDSR 00017 #define WRITE_ENABLED 0x06 // WREN 00018 #define WRITE_STATUS 0x01 // WRSR 00019 #define READ_ID 0x9F // RDID 00020 #define READ_SN 0xC3 // RSN 00021 00022 /** An interface for the Ramtron FM25VXX FRAM over SPI 00023 * 00024 * 00025 * 00026 * @code 00027 * #include "mbed.h" 00028 * #include "FRAMSPI.h" 00029 * 00030 * SPI spi(p5,p6,p7); 00031 * FRAMSPI fram(spi,p8); 00032 * Serial pc(USBTX, USBRX); 00033 * 00034 * int main() { 00035 * char wdata[] = "Hello world!"; 00036 * char rdata[14]; 00037 * 00038 * fram.write(0, wdata, 13); // 12 symbols + zero terminator 00039 * fram.read(0, rdata, 13); 00040 * 00041 * pc.printf("data: %s", rdata); 00042 * } 00043 * @endcode 00044 * connections: 00045 * chip pin 1 to any GPIO. Chip select (!S) 00046 * chip pin 2 SO to MISO. Write (!W) 00047 * chip pin 3 to Vout or N/C 00048 * chip pin 4 to Gnd 00049 * chip pin 5 SI to MOSI 00050 * chip pin 6 SCK to sck 00051 * chip pin 7 to Vout. !Hold 00052 * chip pin 8 to Vout 00053 */ 00054 00055 class FRAMSPI { 00056 00057 public: 00058 /** Create an interface 00059 * 00060 * @param spi An SPI object 00061 * @param ncs Chip select pin 00062 */ 00063 FRAMSPI(SPI& spi, PinName ncs); 00064 00065 /** read chip 8 byte device ID 00066 */ 00067 void readID(char *buff); 00068 00069 /** read chip 2 byte serial number 00070 */ 00071 void readSN(char *buff); 00072 00073 /** read a byte from FRAM 00074 * @param addr The address to read from 00075 * @return the byte at that address 00076 */ 00077 char read(int addr); 00078 00079 /** read multiple bytes from FRAM into a buffer 00080 * @param addr The FRAM address to read from 00081 * @param buff The buffer to read into (must be big enough!) 00082 * @param cnt The number of bytes to read 00083 */ 00084 void read(int addr, char *buff, int cnt); 00085 00086 /** write a byte to FRAM 00087 * @param addr The address SFRAM to write to 00088 * @param data The byte to write there 00089 */ 00090 void write(int addr, char data); 00091 00092 /** write multiple bytes to FRAM from a buffer 00093 * @param addr The FRAM address write to 00094 * @param buff The buffer to write from 00095 * @param cnt The number of bytes to write 00096 */ 00097 void write(int addr, char *buff, int cnt); 00098 00099 private: 00100 SPI& _spi; 00101 DigitalOut _ncs; 00102 void prepareCommand(char cmd, int addr); 00103 void select(); 00104 void deselect(); 00105 }; 00106 00107 #endif
Generated on Sat Jul 16 2022 22:38:01 by
1.7.2
Oleg Evsegneev