Diff: EE25LC1024.cpp
- Revision:
- 2:156c427681f0
- Parent:
- 0:81848bf6dd4a
diff -r 81848bf6dd4a -r 156c427681f0 EE25LC1024.cpp
--- a/EE25LC1024.cpp Fri Jun 01 12:54:02 2018 +0000
+++ b/EE25LC1024.cpp Tue Oct 23 10:22:19 2018 +0000
@@ -1,13 +1,14 @@
// EE25LC1024.cpp
-
+#include "mbed.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);
chipDisable();
+
}
// READING
@@ -22,7 +23,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 +56,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
@@ -78,9 +80,14 @@
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 +98,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)
{
@@ -153,7 +167,9 @@
{
writeEnable();
+
chipEnable();
+
this->write(SE);
this->write((addr & ADDR_BMASK2) >> ADDR_BSHIFT2);
this->write((addr & ADDR_BMASK1) >> ADDR_BSHIFT1);
@@ -169,11 +185,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)
@@ -213,7 +235,7 @@
wait_ms(6);
}
-long EE25LC1024::raedLong(int addr)
+long EE25LC1024::readLong(int addr)
{
//Read the 4 bytes from the eeprom memory.
chipEnable();