4 years, 10 months ago.

Problems with I2C communication

How does the I2C read() and write() functions work exactly in the mbed built in platform? Suppose there are 2 micro-controllers, master and slave. I found out that if we put some random printf() statements in the code, the code get stuck indefinitely in the while loop for read/write. In this case, the value of the data registers are found to be either 126 or 255. Why does this happen. Is the read() and write() in mbed subject to small timing changes?

If I put write() statement in master, but do not put read() in slave, what exactly happens to the data being sent?

Any help is appreciated. Thanks.

Comment on this question

1 Answer

4 years, 10 months ago.

I2C slave implementation is still problematic on some mbed platforms. This is partly because of different I2C hardware implementations on different platforms. The software is yet not fully correct or fully robust for all platforms. This may show up when you change timing. In addition to possible software bugs you should also be aware that I2C masters and slaves must respond in a timely way. The mbed software lib will time-out and abort when the other end does not respond fast enough. Since the communications between master and slave are typically set up as some sort of statemachine an aborted message could lead to a stalemate because the statemachines get out of sync. Delays caused by printf could lead to aborted messages. Reading a value of 255 is something you typically get when the slave does not respond: the bus will float to 1 when the slave does not send anything. You should be able to detect some of the problems by checking the return status of the write() or read() operation. Solving I2C communication problems is difficult without proper equipment such as a logic analyser. Provide some example code so that others may do some testing when you dont have the right tools.


You need to log in to post a question