Skip to main content
AZube.2
Associate III
Jul 13, 2022 9:21 AM UTC
Question

After initialization, I2C is always busy

I am using the Nucelo board and communicating with an IKS02A1 trough I2C2 using PINs PA11 and PA12 with the following configuration:

0693W00000QL5xUQAT.png 

I have initializaed the I2C folowing the guidelines in "stm32wlxx_hal_i2c.c", and when I use "HAL_I2C_IsDeviceReady()" function I always get BUSY_ERROR.

The initialization is done through:

0693W00000QL6HAQA1.png 0693W00000QL6PhQAL.pngDMA and interrups are both initialized even though I am not still usign them. I tried not initializing them them and the results are the same.

If I do not check "HAL_I2C_IsDeviceReady()" function and I directly use "HAL_I2C_Mem_Read()" or "HAL_I2C_Mem_Write()", I get ERROR_PERIPH_FAILURE.

I can not fix this and I am going crazy please help!

This topic has been closed for replies.

6 replies

Tesla DeLorean
Guru
Jul 13, 2022 12:08 PM UTC

What do the levels / signals look like on SDA and SCL ?

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
AZube.2
AZube.2Author
Associate III
Jul 14, 2022 11:00 AM UTC

Problem fixed finally, thanks.

Louis AUDOLY
ST Employee
Jul 19, 2022 2:12 PM UTC

Hi @AZube.2​ ,

Glad you manage to fix your issue.

Can you share your solution in case someone else encounter the same issue ?

Thank you

Best regards

AZube.2
AZube.2Author
Associate III
Jul 19, 2022 2:21 PM UTC

Hi @Louis AUDOLY​ ,

I am sorry to say that I did not strictly find a solution for the issue. What I did was to start a new project and trust the CubeMX initialization code (which was the same thing I did when I got the issue). For some reason that is unknown to me, this time the issue never appeared.

Hope this helps to someone :)

Best regards

S.Ma
Principal
Jul 20, 2022 12:38 AM UTC

It could be a io vs i2c init sequencd and timing marginality. If it happened once, it could reappear when compile option changes or else. Get ready, implement a sw bit bang gpio function that generates 9 stop bits. Use it if sda is low or busy is set prior starting bus transaction to flush the bus.

Typically happens when debugging, reading data from slave and reset the mcu [and not the slave] by restarting the code.

Real application test would be esd gun near pcb i2c lines. Old test was use a drilling machine near the board.... rugged sw ? Knowledge makes the difference in the long term....

AZube.2
AZube.2Author
Associate III
Jul 20, 2022 7:00 AM UTC

Sounds interesting, I would like to try it @S.Ma​ . Do you know any example I could use?