Skip to main content
Stecklo
Senior
December 18, 2019
Solved

I2C NACKs when BLE is running

  • December 18, 2019
  • 1 reply
  • 935 views

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?

This topic has been closed for replies.
Best answer by JRAUL.1

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

1 reply

JRAUL.1
JRAUL.1Answer
ST Employee
December 18, 2019

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

Stecklo
SteckloAuthor
Senior
December 18, 2019

Thanks a lot. It works now