Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 9 months ago.
F401RE I2C library does not work?
Hello,
For few days, i had problems with I2C communication. I try to write and read byte to 24LC02 EEPROMs with following code:
#include "mbed.h" I2C eeprom(I2C_SDA, I2C_SCL); Serial pc(USBTX, USBRX); int main() { pc.printf("Hello\r\n"); eeprom.frequency(100000); int ack; char ret; int device_address_write = 0xA0; int device_address_read = 0xA1; int data = 0x6F; // WRITE OPERATION eeprom.start(); ack = eeprom.write(device_address_write); wait_ms(10); printf("%d", ack); ack = eeprom.write(0x00); wait_ms(10); printf("%d", ack); ack = eeprom.write(data); wait_ms(10); printf("%d", ack); eeprom.stop(); wait_ms(10); // READ OPERATION eeprom.start(); ack = eeprom.write(device_address_write); wait_ms(5); printf("%d", ack); ack = eeprom.write(0x00); wait_ms(5); printf("%d", ack); eeprom.start(); ack = eeprom.write(device_address_read); wait_ms(5); printf("%d", ack); ret = eeprom.read(0); wait_ms(5); eeprom.stop(); pc.printf("Written:%2X, Read:%2X", 0x6F, ret); }
Are there any known issues in embed I2C library or am I making mistake(s)?
1 Answer
9 years, 9 months ago.
In general don't use the the 1 byte read/write functions. I think the only reason they haven't been removed yet is because a few devices use non-standard I2C communication. I don't know if it could be better supported in the F401, but I do know in enough mbed devices it is already supported with hacks, since most I2C peripherals were never intended to be controlled per byte.
Hello again,
At last i manage to write and read 1 byte data to Microchip 24LC02.. The primitive read and write functions of I2C mbed library does not work.. So we use other wrtie and read functions.
The below code writes and read 100 (decimal) to EEPROM address 0x00. (random address read and write)
While writing 0x0A is the device address (10100000), while reading the address is 0xA1 (10100001).