2019-12-18 05:51 AM
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?
Solved! Go to Solution.
2019-12-18 06:41 AM
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
2019-12-18 06:41 AM
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
2019-12-18 06:59 AM
Thanks a lot. It works now