128K Serial EEPROM read write erase chip erase functions SPI EEPROM Nucleo F767ZI

Dependents:   SPI_EEPROM

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EE25LC1024.h Source File

EE25LC1024.h

00001 // EE25LC1024.h
00002 
00003 #ifndef EE25LC1024_H
00004 #define EE25LC1024_H
00005 
00006 #include "mbed.h"
00007 #include <string>
00008 
00009 #define SPI_Freq        10000000                 //Change SPI Frequency Here
00010 #define SPI_MODE        0                       // SPI Mode can be 0 or 3 . see data sheet
00011 #define SPI_NBIT        8                       // Number of bits 8.
00012 
00013 
00014 
00015 #define DUMMY_ADDR      0x00
00016 #define WAIT_TIME       1
00017 
00018 #define ADDR_BMASK3     0xff000000
00019 #define ADDR_BMASK2     0x00ff0000
00020 #define ADDR_BMASK1     0x0000ff00
00021 #define ADDR_BMASK0     0x000000ff
00022 
00023 #define ADDR_BSHIFT3    24
00024 #define ADDR_BSHIFT2    16
00025 #define ADDR_BSHIFT1    8
00026 #define ADDR_BSHIFT0    0
00027 
00028 
00029 #define     READ            0x03        //0000 0011 Read data from memory array beginning at selected address
00030 #define     WRITE           0x02        //0000 0010 Write data to memory array beginning at selected address
00031 #define     WREN            0x06        //0000 0110 Set the write enable latch (enable write operations)
00032 #define     WRDI            0x04        //0000 0100 Reset the write enable latch (disable write operations)
00033 #define     RDSR            0x05        //0000 0101 Read STATUS register
00034 #define     WRSR            0x01        //0000 0001 Write STATUS register
00035 #define     PE              0x42        //0100 0010 Page Erase – erase one page in memory array
00036 #define     SE              0xD8        //1101 1000 Sector Erase – erase one sector in memory array
00037 #define     CE              0xC7        //1100 0111 Chip Erase – erase all sectors in memory array
00038 #define     Readid          0xAB        //1010 1011 Release from Deep power-down and read electronic signature
00039 #define     DPD             0xB9        //1011 1001 Deep Power-Down mode
00040 #define     DUMMYBYTE       0x00        //Dummy byte for Read Operation
00041 
00042 class EE25LC1024: public SPI {
00043 public:
00044     EE25LC1024(PinName mosi, PinName miso, PinName sclk, PinName cs);
00045     
00046     void deepPowerDown(void);
00047     
00048     
00049     int readByte(int addr);                                 // takes a 24-bit (3 bytes) address and returns the data (1 byte) at that location                   
00050     void readStream(int addr, char* buf, int count);        // takes a 24-bit address, reads count bytes, and stores results in buf
00051     int ReleaseDPD_ReadSign(void);
00052     void writeByte(int addr, int data);                     // takes a 24-bit (3 bytes) address and a byte of data to write at that location
00053     void writeStream(int addr, char* buf, int count);       // write count bytes of data from buf to memory, starting at addr  
00054     void writeString(int add, string str);
00055     void sectorErase(int addr);
00056     void pageErase(int addr);
00057     void chipErase();                                       //erase all data on chip
00058     uint8_t readRegister();  
00059     uint8_t checkIfBusy();                                  // Check if IC is bury writing or erasing 
00060     void writeRegister(uint8_t regValue);                   // Write status register or configuration register                                   
00061     long readLong(int address);                             // Read long int number
00062     void writeLong(int addr, long value);                   // Write Long Integer Number
00063 private:
00064     void writeEnable();                                     // write enable
00065     void writeDisable();                                    // write disable
00066     void chipEnable();                                      // chip enable
00067     void chipDisable();  
00068                                       // chip disable
00069     
00070    // SPI _spi;
00071     DigitalOut _cs;
00072 };
00073 
00074 #endif