cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_I2C_ErrorCallback occurred randomly in I2C communication

ArunyaS
Associate II

Hi, 

Currently, we are working with STM32L476JGY6TR MCU. 

We are facing HAL_I2C_ErrorCallback - 0x00000004 error randomly while communicating with MCU.

 

 We are communicating with the MCU Frequently with particular time intervals. In this scenario, some of our communication to MCU fails and shows the above ErrorCallback in MCU, and The Slave I2C gets reset.

 

May I know the reason for HAL_I2C_ErrorCallback occurs and NACK receives?

How could I debug this issue?

 

Configuration : 

We configured i2c-2 as a slave in MCU and communicated from the host with the 400kHZ frequency. 

We use a 4.7k ohm pull-up resistor with a 1.8V source. 

We use the HSI Internal oscillator. 

 

Kindly help to solve this.

Thank you!

3 REPLIES 3
ONadr.1
Senior III

The device does not respond for some unspecified reason. This can be caused by noise on the data bus or inappropriate bus topology. I would recommend reducing the impedance of the terminal resistors. This situation can normally occur in communication and must be handled, for example by resetting the I2C device and repeating the last command (or block of commands).

TDK
Guru

Probably a bug in the code. Slave might only be set up to send 4 bytes while the master is expecting 6, for instance.

Or it's a normal communication. The last byte of data received/sent can be NACKd to indicate the operation is complete.

If you feel a post has answered your question, please click "Accept as Solution".
ArunyaS
Associate II

Hi,

Initially, I used an HSI internal oscillator with a 24 MHz frequency to I2C.

For debugging, I have changed the I2C clock Frequency to 48Mhz from the MSI oscillator source. In this case, Issue occurrence will be reduced almost. But not resolved.

 

In some instances, the I2C clock held low, Unable to communicate after that due to I2C Timeout error. Even, I kept the I2C clock stretch as I2C_NOSTRETCH_DISABLE.  This will happen with both oscillator clock frequencies.

 

Can anybody tell me the reason for this?