Hello everybody.
I came across a problem with the I2C library Read function "i2c.read(addr, cmd, 2);" when it face a slave the stretches the clock.
I found, for example, that if the Mbed tries to read two, or more, byte from the slave that holds the clock low "ie clock stretching" that it would wait for the first byte but not for the second and return the array filled in with the first byte.
Anybody else faced this problem?
Code Example: (Master Reading 16 byte from slave)
#include "mbed.h"
Serial pc(USBTX, USBRX);
I2C i2c(p28, p27);
DigitalOut myled(LED1);
int main() {
char buffer[20];
pc.printf("Test message\n\r");
int retval = i2c.read( (0x41 << 1) | 1, buffer, 16);
if (retval == 1)
{
error("FAILED!\n\r");
}
else
{
printf("SUCCESS!\n\r");
buffer[16] = 0;
printf("%s\n\r", buffer);
while(1);
}
}
Hello everybody.
I came across a problem with the I2C library Read function "i2c.read(addr, cmd, 2);" when it face a slave the stretches the clock.
I found, for example, that if the Mbed tries to read two, or more, byte from the slave that holds the clock low "ie clock stretching" that it would wait for the first byte but not for the second and return the array filled in with the first byte.
Anybody else faced this problem?
Code Example: (Master Reading 16 byte from slave)