cancel
Showing results for 
Search instead for 
Did you mean: 

I2C NACKs when BLE is running

Stecklo
Senior

I'm trying to perform I2C read from external EEPROM upon characteristic value change.

I'm able to read from EEPROM before advertisement stage.

I'm using sequencer to put char_value_handler in the main thread.

But HAL_I2C_Mem_Read() returns HAL_ERROR.

The reason is NACK flag is set after writing device & memory address.

I've noticed, that if I put a breakpoint before calling HAL_I2C_Mem_Read(), then release it manually everything is OK. The same result is with placing a 0.5 second delay just before HAL_I2C_Mem_Read().

I can also put HAL_I2C_Mem_Read() in a while loop and it succeeds on a fourth try.

I thought hat it could be some interrupt or hci_event but _disable_irq() makes no change. And no hci_notify_asynch_evt() is called after a HAL_I2C_Mem_Read() call.

Maybe I sould use some mutex or status flag before calling HAL_I2C_Mem_Read() but I've already tried everything I could think of.

Of course I could proceed with that 0.5 s delay or a while loop but it is so lame.

Any ideas what is the reason for this behaviour?

1 ACCEPTED SOLUTION

Accepted Solutions
JRAUL.1
ST Employee

Hi,

Best practice for EEPROM access is to use the interface HAL_I2C_IsDeviceReady.

And then when device confirmed as ready. You can call the other mem interface.

Hope that help

Regards

View solution in original post

2 REPLIES 2
JRAUL.1
ST Employee

Hi,

Best practice for EEPROM access is to use the interface HAL_I2C_IsDeviceReady.

And then when device confirmed as ready. You can call the other mem interface.

Hope that help

Regards

Thanks a lot. It works now