2025-04-07 1:31 PM - edited 2025-04-07 1:37 PM
Hi,
I'm facing an I2C communication issue between an STM32F107RCT6 microcontroller and the MAX11612EUA ADC. I created a clean project in STM32CubeMX using HAL library v1.1.9.0. I'm using HAL_I2C_Master_Receive_IT() to read data, and in the callback I process the received 8 bytes (4 ADC channels, 2 bytes each). When the I2C bus is set to 400kHz (Fast Mode), I randomly receive incorrect values ("spikes") in the data. A Saleae logic analyzer shows that some frames contain only 7 bytes, and the master unexpectedly sends NACK and STOP. Switching to DMA (HAL_I2C_Master_Receive_DMA()) partly solves the issue — data is correct, but after some time communication hangs. The function returns HAL_BUSY, and HAL_I2C_GetError() reports HAL_I2C_ERROR_TIMEOUT. Recovery is only possible by calling HAL_I2C_DeInit() followed by HAL_I2C_Init(). When the I2C hangs, the entire main program stops for around 286 ms. I tested the same code on STM32F103 and STM32H563 — the issue does not occur. Has anyone experienced a similar problem?
2025-04-10 2:44 AM
Welcome @Dominik_Ciurej, to the community!
I2C problems are regularly discussed here in the community and can have a wide variety of causes. However, without more detailed information (pull-ups and their value, relevant sections of your programme, possibly scope images) it will be difficult to help you.
Regards
/Peter
2025-04-10 3:15 AM - edited 2025-04-10 4:05 AM
As @Peter BENSCH said, we need more detail.
Show your schematic.
Have you used an oscilloscope to look at the I2C lines? That would show up any "analogue" issues not visible on a logic analyser.
@Dominik_Ciurej wrote:A Saleae logic analyzer shows that some frames contain only 7 bytes,
Do those frames correspond to your spikes?
@Dominik_Ciurej wrote:I tested the same code on STM32F103 and STM32H563 — the issue does not occur.
Maybe instrument all three; compare & contrast ... ?
PS:
Have you tried lowering the speed?
@Dominik_Ciurej wrote:I tested the same code on STM32F103 and STM32H563
Check for any hardware differences.
Post the schematics