79600202

Date: 2025-04-30 11:16:57
Score: 2
Natty:
Report link

Thanks to Ihdina for the suggestion, I will improve this code in the future.

The problem has been solved, and this i2c_wait_ack is suitable for simulating i2c (sda is push-pull output pin), that is, i2c communication with only one master and slave.

The problem lies in the i2c_wait_ack function in software-i2c because the output DR Is always 1 because the host releases the bus (the sda pin is an open-drain output). This causes a timeout, outputs a stop signal, and a NACK condition occurs.

That is, at the beginning of i2c_wait_ack, the sda pin is configured as the input pin, and when the ack signal is obtained, the sda is set as the open-drain output pin.

enter image description here

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • No code block (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user30273815