EEPROM 24LC01 libraly

Files at this revision

API Documentation at this revision

Comitter:
Info
Date:
Sat Jul 29 13:09:33 2017 +0000
Commit message:
EEPROM libraly for mille-feuille device boards.

Changed in this revision

EEPROM24LC01.cpp Show annotated file Show diff for this revision Revisions of this file
EEPROM24LC01.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EEPROM24LC01.cpp	Sat Jul 29 13:09:33 2017 +0000
@@ -0,0 +1,58 @@
+/*
+ ***************************************************************************
+ * File Name    : EEPROM24LC01.cpp
+ *
+ * Revision     : 1.0
+ * Notes        :
+ * Target Board : mbed LPC
+ *
+ * Revision History:
+ ***************************************************************************
+ */
+#include "EEPROM24LC01.h"
+#include "mbed.h"
+
+EEPROM24LC01::EEPROM24LC01(I2C *i2c, const int address):
+    _i2c_address(address<<1), _i2c(i2c)
+{
+}
+
+int EEPROM24LC01::byte8_write(char *data)
+{
+    int res;
+    char buf[9];
+    int i = 0;
+
+    buf[0] = 0;        // Address
+
+    for(i=0;i<8;++i){
+        buf[i+1] = data[i];
+    }
+/*    buf[1] = data[0];
+    buf[2] = data[1];
+    buf[3] = data[2];
+    buf[4] = data[3];
+    buf[5] = data[4];
+    buf[6] = data[5];
+    buf[7] = data[6];
+    buf[8] = data[7];
+*/
+    res = _i2c->write(_i2c_address, buf, sizeof(buf), false);
+
+    wait_ms(5);         // 5mS
+
+    return res;
+}
+
+
+int EEPROM24LC01::readAll( char *data, int size )
+{
+    int res;
+    char buf[1];
+
+    buf[0] = 0;        // Read Address High byte set
+    res = _i2c->write(_i2c_address, buf, sizeof(buf), true);
+    res = _i2c->read(_i2c_address, (char *)data, size, false);
+
+    return res;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EEPROM24LC01.h	Sat Jul 29 13:09:33 2017 +0000
@@ -0,0 +1,31 @@
+/*
+ ***************************************************************************
+ * File Name    : EEPROM24LC01.h
+ *
+ * Revision     : 1.0
+ * Notes        :
+ * Target Board : mbed LPC
+ *
+ * Revision History:
+ ***************************************************************************
+ */
+
+#ifndef _EEPROM24LC01_H_
+#define _EEPROM24LC01_H_
+
+#include "mbed.h"
+#define     I2C_ADDR_EEPROM24LC01        0x50
+
+class EEPROM24LC01
+{
+private:
+    int _i2c_address;
+    I2C *_i2c;
+
+public:
+    EEPROM24LC01(I2C *i2c, const int address=I2C_ADDR_EEPROM24LC01 );
+    int byte8_write( char *data );
+    int readAll( char *data, int size );
+};
+
+#endif /* _EEPROM24LC01_H_ */
\ No newline at end of file