Hello,
I’m trying to use a I2C EEPROM(24LC64) on a NULEOF446RE board but the read results are always wrong.
Could someone tell me what is wrong with this?
I’m using Mbed OS2.
SDA & SCL pins are pulled up by 2.2k resisters.
The EEPROM adress is A0(A0, A1 & A2 pins are tied to ground).
All pins are connected correctly.
And I don’t know why but with NUCLEO303RE, reading EEPROM succeed with totally the same code.
Here is my test code.
#include "mbed.h"
Serial pc(USBTX, USBRX);
I2C mem(D14, D15);
void writeEEPROM(unsigned int eeaddress, char *data, int size)
{
char i2cBuffer[size + 2];
i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
for (int i = 0; i < size; i++) {
i2cBuffer[i + 2] = data[i];
}
mem.start();
int result = mem.write(0xA0, i2cBuffer, size + 2, false);
wait_ms(6);
mem.stop();
}
void readEEPROM(unsigned int eeaddress, char *data, int size)
{
char i2cBuffer[2];
i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB
i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB
mem.start();
int result = mem.write(0xA0, i2cBuffer, 2, false);
wait_ms(6);
mem.read(0xA1, data, size);
wait_ms(6);
mem.stop();
}
int main()
{
mem.frequency(400000);
char wData[3] = {0,1,2};
writeEEPROM(0, wData,3);
char rData[3];
readEEPROM(0, rData,3);
pc.printf("%x, %x, %x\r\n",rData[0],rData[1],rData[2]);
}
With 446RE, I got 0, 0, 0.
With 303RE, I got 0, 1, 2.
Any advice would be appreciated.
Thank you.