Search code examples
microcontrollerstm32i2cstm32f4

I2C SCL line, clock issue on STM32F4


In I2C interface,

SCL, clock line will transmit clock signals even if there are no devices on the bus?

How can we debug the I2C?


Solution

  • The I2C bus master does not know if there are slave devices connected to the bus.

    All it can do is to initiate communication with a certain device by sending the slave's address to the bus (it can be a read or write operation). If the master receives an ACK, acknowledge, then that means the slave is ready (and presented on the bus) to communicate. A NACK, not acknowledge can mean that the slave is not ready. If the request time outs that means, there is no available devices on the bus with the specific address.

    Now, back to your question:

    SCL, clock line will transmit clock signals even if there are no devices on the bus?

    Yes, the clock line will be driven when the master initiates the communication, even if there are not any slaves. The clock is used, as there are data on the bus, the slave device address.

    It looks like in the image below, the only difference that the ACK won't be there if there are no slave device on the bus (with that address).

    enter image description here

    Now as for the debug, the best would be if you could buy a logic analyzer, (cheaper versions are available on eBay or aliexpress) to capture what is going on actually on the bus. The image above has been made using one.