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

Dependents:   SPI_EEPROM

Files at this revision

API Documentation at this revision

Comitter:
shivanandgowdakr
Date:
Tue Oct 23 09:39:31 2018 +0000
Parent:
0:81848bf6dd4a
Commit message:
No Change

Changed in this revision

EE25LC1024.cpp Show annotated file Show diff for this revision Revisions of this file
EE25LC1024.h Show annotated file Show diff for this revision Revisions of this file
--- a/EE25LC1024.cpp	Fri Jun 01 12:54:02 2018 +0000
+++ b/EE25LC1024.cpp	Tue Oct 23 09:39:31 2018 +0000
@@ -1,12 +1,12 @@
 // EE25LC1024.cpp
-
+#include "includes.h"
 #include"EE25LC1024.h"
 
 // CONSTRUCTOR
 EE25LC1024::EE25LC1024(PinName mosi, PinName miso, PinName sclk, PinName cs) : SPI(mosi, miso, sclk), _cs(cs)
 {
     this->format(SPI_NBIT, SPI_MODE);
-    this->frequency(SPI_FREQ);
+    this->frequency(SPI_FREQ_EEPROM);
     chipDisable();
 }
 // READING
@@ -22,7 +22,7 @@
   int EE25LC1024::ReleaseDPD_ReadSign(void)
 { 
     chipEnable();
-    this->write(RDID);
+    this->write(ReadID);
     this->write(DUMMY_ADDR);
     this->write(DUMMY_ADDR);
     this->write(DUMMY_ADDR);
@@ -55,9 +55,10 @@
     this->write((addr & ADDR_BMASK0) >> ADDR_BSHIFT0);
     for (int i = 0; i < count; i++) {
         buf[i] =  this->write(DUMMY_ADDR);
-        printf("i= %d   :%c \r\n",i,buf[i]);
+       // printf("i= %d   :%c \r\n",i,buf[i]);
     }
     chipDisable();
+  //  wait_ms(2);
 }
 
 // WRITING
@@ -72,15 +73,24 @@
     this->write(data);
     chipDisable();
     writeDisable();
-    wait_ms(6);
+      uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy(); 
+     }
     // wait(WAIT_TIME);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
 }
 
 void EE25LC1024::writeStream(int addr, char* buf, int count)
 {
+
     if (count < 1)
         return;
+        
     writeEnable();
+    
+ 
+    
     chipEnable();
     this->write(WRITE);
     this->write((addr & ADDR_BMASK2) >> ADDR_BSHIFT2);
@@ -91,8 +101,15 @@
     }
     chipDisable();
     writeDisable();
-   wait_ms(6);
-}
+     wait_ms(2);
+   uint8_t busy= checkIfBusy(); 
+   while(busy==1)
+   {
+       //printf("Busy   :%d\r\n",busy);
+       wait_ms(1);
+       busy= checkIfBusy();
+    }
+    }
 
 void EE25LC1024::writeString(int addr, string str)
 {
@@ -108,7 +125,11 @@
         this->write(str.at(i));
     chipDisable();
     writeDisable();
-    wait_ms(6);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
+      uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy(); 
+     }//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
 }
 
 
@@ -132,7 +153,11 @@
     this->write(CE);
     chipDisable();
     writeDisable();
-    wait_ms(10);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
+      uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy(); 
+     }//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
 }
 
 
@@ -146,21 +171,31 @@
     this->write((addr & ADDR_BMASK0) >> ADDR_BSHIFT0);
     chipDisable();
     writeDisable();
-    wait_ms(10);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
+      uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy(); 
+     }//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
 }
 
 void EE25LC1024::pageErase(int addr)
 {
     
     writeEnable();
+    
     chipEnable();
+    
     this->write(SE);
     this->write((addr & ADDR_BMASK2) >> ADDR_BSHIFT2);
     this->write((addr & ADDR_BMASK1) >> ADDR_BSHIFT1);
     this->write((addr & ADDR_BMASK0) >> ADDR_BSHIFT0);
     chipDisable();
     writeDisable();
-    wait_ms(6);//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
+       uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy(); 
+     }//instead of wait poll for WIP flag of status reg or use checkIfBusy() function...see main for more dtails 
      
     
 }
@@ -169,11 +204,17 @@
 uint8_t EE25LC1024::checkIfBusy()
 {
     uint8_t value=readRegister();
-    printf("Value of Status Reg=%X\r\n\r\n",value);
-    if((value&0x01)==0x01)
+   // printf("\r\n Value of Status Reg=%X\r\n\r\n",value);
+    if((value & 0x01)==0x01 )
+    {
+        wait_ms(1);
         return 1;
+        }
     else
+    {
+        wait_ms(1);
         return 0;
+        }
 }
 
 void EE25LC1024::writeRegister(uint8_t regValue)
@@ -210,10 +251,14 @@
     this->write(one);
     chipDisable();
     writeDisable();
-    wait_ms(6);
+      uint8_t busy=checkIfBusy();
+    while(busy)
+    {  
+      busy=checkIfBusy(); 
+     }
 }
 
-long EE25LC1024::raedLong(int addr)
+long EE25LC1024::readLong1(int addr)
 {
     //Read the 4 bytes from the eeprom memory.
     chipEnable();
--- a/EE25LC1024.h	Fri Jun 01 12:54:02 2018 +0000
+++ b/EE25LC1024.h	Tue Oct 23 09:39:31 2018 +0000
@@ -6,7 +6,7 @@
 #include "mbed.h"
 #include <string>
 
-#define SPI_FREQ        5000000                 //Change SPI Frequency Here
+#define SPI_FREQ_EEPROM        5000000                 //Change SPI Frequency Here
 #define SPI_MODE        0                       // SPI Mode can be 0 or 3 . see data sheet
 #define SPI_NBIT        8                       // Number of bits 8.
 
@@ -35,7 +35,7 @@
 #define     PE              0x42        //0100 0010 Page Erase – erase one page in memory array
 #define     SE              0xD8        //1101 1000 Sector Erase – erase one sector in memory array
 #define     CE              0xC7        //1100 0111 Chip Erase – erase all sectors in memory array
-#define     RDID            0xAB        //1010 1011 Release from Deep power-down and read electronic signature
+#define     ReadID          0xAB        //1010 1011 Release from Deep power-down and read electronic signature
 #define     DPD             0xB9        //1011 1001 Deep Power-Down mode
 #define     DUMMYBYTE       0x00        //Dummy byte for Read Operation
 
@@ -43,9 +43,7 @@
 public:
     EE25LC1024(PinName mosi, PinName miso, PinName sclk, PinName cs);
     
-    void deepPowerDown(void);
-    
-    
+    void deepPowerDown(void);    
     int readByte(int addr);                                 // takes a 24-bit (3 bytes) address and returns the data (1 byte) at that location                   
     void readStream(int addr, char* buf, int count);        // takes a 24-bit address, reads count bytes, and stores results in buf
     int ReleaseDPD_ReadSign(void);
@@ -58,7 +56,7 @@
     uint8_t readRegister();  
     uint8_t checkIfBusy();                                  // Check if IC is bury writing or erasing 
     void writeRegister(uint8_t regValue);                   // Write status register or configuration register                                   
-    long raedLong(int address);                             // Read long int number
+    long readLong1(int address);                             // Read long int number
     void writeLong(int addr, long value);                   // Write Long Integer Number
 private:
     void writeEnable();                                     // write enable