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.
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
I am having a problem using NUCLEO-F401RE board for testing the i2c slave. I was using the mbed OS 5 i2c slave example (https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/interfaces/digital/I2CSlave/) with the bit rate standard 100K bit/s. I used the Total Phase Aardvark I2C host adapter sending bytes (8 bytes) to NUCLEO-F401RE board. The NUCLEO-F401RE i2c slave always holds down the SCL line forever in middle of the data transfer, which can be viewed clearly by a oscilloscope or a I2C protocol analyzer. Please help!
The following is the test code:
I2C {{/media/uploads/jingxizhang/img_20160821_173429772.jpg}} Slave test
include "mbed.h" I2CSlave slave(PB_9, PB_8); int main() { char buf[10]; char msg[] = "Slave!"; slave.address(0x0A); while (1) { int i = slave.receive(); switch (i) { case I2CSlave::ReadAddressed: slave.write(msg, strlen(msg) + 1); // Includes null char break; case I2CSlave::WriteGeneral: slave.read(buf, 10); printf("Read G: %s\n", buf); break; case I2CSlave::WriteAddressed: slave.read(buf, 10); printf("Read A: %s\n", buf); break; } for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer } }