lib eeprom
Fork of eeprom by
Diff: eeprom.cpp
- Revision:
- 2:c648c5e93d5e
- Parent:
- 0:80245aff63ce
--- a/eeprom.cpp Tue Aug 25 11:59:20 2015 +0000 +++ b/eeprom.cpp Mon Oct 26 16:43:07 2015 +0000 @@ -3,6 +3,7 @@ Date: 27 december 2011 Version: 1.0 ************************************************************/ +#include "mbed.h" #include "eeprom.h" #define BIT_SET(x,n) (x=x | (0x01<<n)) @@ -50,10 +51,14 @@ break; case T24C32 : case T24C64 : + if(address > 7) { _errnum = EEPROM_BadAddress; } + _address = _address << 1; + + _page_write = 32; _page_number = 1; break; @@ -98,7 +103,7 @@ _size = T24C1024; // Set I2C frequency - _i2c.frequency(400000); + _i2c.frequency(100000); } void EEPROM::write(uint16_t address, int8_t data) @@ -149,7 +154,7 @@ cmd[2] = (uint8_t) data; } - //printf("len %d address %02x cmd[0] %02x cmd[1] %02x cmd[2] %02x\n",len,addr,cmd[0],cmd[1],cmd[2]); + // printf("len %d address %02x cmd[0] %02x cmd[1] %02x cmd[2] %02x\n",len,addr,cmd[0],cmd[1],cmd[2]); ack = _i2c.write((int)addr,(char *)cmd,len); if(ack != 0) { @@ -448,7 +453,7 @@ memcpy(cmd,&data,4); write(address,cmd,4); - + } void EEPROM::write(uint16_t address, float data) @@ -744,12 +749,13 @@ addr = EEPROM_Address | _address; cmd = 0; - + /* // Wait end of write do { ack = _i2c.write((int)addr,(char *)cmd,0); } while(ack != 0); - +*/ + wait_ms(5); } uint32_t EEPROM::getSize(void)