py32-rs / py32-hal

Rust HAL implementation for py32 mcu.
4 stars 1 forks source link

I2C Support #8

Closed decaday closed 2 weeks ago

decaday commented 2 weeks ago

Currently experiencing a blocking issue where I2C fails to detect Start bit (SR1.START (SR1.SB)) after generating start signal (CR1.START), resulting in TIMEOUT error.

I've compared the implementation with cSDK HAL library code and found no obvious discrepancies. Additionally, comparing py32 cSDK HAL with stm32f1 SDK (they have similar I2C peripherals) didn't reveal the root cause. Logic analyzer tests confirm that the start signal is being correctly generated on the hardware level.

Side note: In some cases, it seems to work correctly or generate Arbitration errors when PA3/PA2 are configured as alternate function pins. However, this behavior is difficult to reproduce consistently.

decaday commented 2 weeks ago

I believe I've found the cause of this issue. While testing I2C, I only connected the logic analyzer to the I2C lines to verify the waveform generation and NACK response. Since the I2C GPIO pins were configured as AF_OD, the I2C pins were in an undefined state, which led to these problems. After connecting it to an actual I2C device, everything works perfectly.