stm32f0xx-hal: First write on I2C bus never NACK's

Problem:

When performing the first write transaction of the i2c scanner example, there is never a NACK, even if no device is attached on the bus.

Hardware required:

1x STM32F072 Nucleo

2x appropriate (for example 4.7KOhm) pullup resistor (alternatively, use any known OK I2C breakout board with a known I2C address which already includes pullups)

1x https://github.com/stm32-rs/stm32f0xx-hal/blob/master/examples/i2c_find_address.rs (for easier pin access, you may want to change the SDA pin to be PB9 instead of PB7)

Steps to reproduce:

  1. Wire up the pull up resistors from SCL/SDA to 3v3.

  2. Run the i2c scanner example: https://github.com/stm32-rs/stm32f0xx-hal/blob/master/examples/i2c_find_address.rs

  • Expected: _devices == 0
  • Actual: _devices == 1, ACK at address 0
  • If you see a lot of ACKs, your pull-ups could be wrong
  1. Change start address in line 32: https://github.com/stm32-rs/stm32f0xx-hal/blob/fba9834b59fa7567ffd604afed2bcd8d07c4e904/examples/i2c_find_address.rs#L32 to e.g. 6 and re-run the scan.
  • Expected: _devices == 0
  • Actual: _devices == 1, ACK at address e.g. 6
  1. Before the scan loop, add this line: let _ = i2c.write(0x4, &[]); and re-run the scan.
  • Expected: _devices == 0
  • Actual: _devices == 0 (yay!)
  1. (Optional) Remove the line added in step 4. Attach an I2C sensor with known address to the bus and re-run the scan.
  • Expected: _devices == 1
  • Actual: _devices == 2

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Is there a solution to the problem now?