I have an app which simply loops reading an i2c device then pushes it out via a serial port. I initially implemented this using only the mbed library which is added by default when a new project is created. Specifically Serial, I2C (400,000 freq), DigitalOut, and DigitalIn classes. Plain vanilla - single threaded - not even using interrupts - no wait calls. My read routine:
ret_val = num_bytes;
port = i2c_ports[i2c_port];
eight_bit_addr = (i2c_addr & 0x7F) << 1;
port->start();
if (port->write(eight_bit_addr) &&
port->write(reg_addr)) {
port->start(); // <-----<<<< Start in question
if (port->write(eight_bit_addr | 0x1)) {
while (num_bytes-- != 1) {
*(current++) = port->read(1);
}
*current = port->read(0);
} else
ret_val = -1;
} else
ret_val = -1;
port->stop();
This works fine. In a test app I cycled through 100,000 samples several times without issue.
As soon as I added the mbed_rtos library and compiled (without even using any of the functionality - not even including a header - no source change on either the mbed target code or my test app) I started getting I2C problems. I noticed them because I started getting odd data (nothing but 0xD1) frequent enough for my eye to notice it scrolling through the test app streaming data. I haven't done extensive runs to estimate statistical confidences but the failure rate is around 0.57% the few times I've done 100,000 sample runs.
I didn't immediately make the connection of the rtos influencing the behavior. I double checked my code and wiring connections then pulled out my trusty Open Bench logic sniffer to see what is going on.
What I found is the START condition following the register address write is missing, thus the switch to reading data doesn't occur as expected. As soon I as remove the mbed-rtos library, behavior goes back to zero errors on 100,000 sample runs.
Here is a good read for comparison:
I didn't yet hookup my LPC1768 so I don't know if it is limited to just this model. If I'm doing something wrong please let me know, otherwise I guess this is a bug.
Regards,
Anthony Loeppert
I have an app which simply loops reading an i2c device then pushes it out via a serial port. I initially implemented this using only the mbed library which is added by default when a new project is created. Specifically Serial, I2C (400,000 freq), DigitalOut, and DigitalIn classes. Plain vanilla - single threaded - not even using interrupts - no wait calls. My read routine:
This works fine. In a test app I cycled through 100,000 samples several times without issue. As soon as I added the mbed_rtos library and compiled (without even using any of the functionality - not even including a header - no source change on either the mbed target code or my test app) I started getting I2C problems. I noticed them because I started getting odd data (nothing but 0xD1) frequent enough for my eye to notice it scrolling through the test app streaming data. I haven't done extensive runs to estimate statistical confidences but the failure rate is around 0.57% the few times I've done 100,000 sample runs.
I didn't immediately make the connection of the rtos influencing the behavior. I double checked my code and wiring connections then pulled out my trusty Open Bench logic sniffer to see what is going on.
What I found is the START condition following the register address write is missing, thus the switch to reading data doesn't occur as expected. As soon I as remove the mbed-rtos library, behavior goes back to zero errors on 100,000 sample runs.
Here is a good read for comparison:
I didn't yet hookup my LPC1768 so I don't know if it is limited to just this model. If I'm doing something wrong please let me know, otherwise I guess this is a bug.
Regards, Anthony Loeppert