You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, i2c_master_write and i2c_master_read returned I2C_OK if
first HAL call returned HAL_BUSY which was not correct.
Now make sure the i2c is ready, which guarantees a good
initialization of the read or write sequence.
Fixesstm32duino#1774
Signed-off-by: Frederic Pillon <[email protected]>
uint32_tXferOptions=obj->handle.XferOptions; // save XferOptions value, because handle can be modified by HAL, which cause issue in case of NACK from slave
858
858
#endif
859
-
860
859
#if defined(I2C_OTHER_FRAME)
861
-
if (HAL_I2C_Master_Seq_Transmit_IT(&(obj->handle), dev_address, data, size, XferOptions) ==HAL_OK) {
860
+
while (HAL_I2C_Master_Seq_Transmit_IT(&(obj->handle), dev_address, data, size, XferOptions) ==HAL_BUSY) {
862
861
#else
863
-
if (HAL_I2C_Master_Transmit_IT(&(obj->handle), dev_address, data, size) ==HAL_OK) {
862
+
while (HAL_I2C_Master_Transmit_IT(&(obj->handle), dev_address, data, size) ==HAL_BUSY) {
864
863
#endif
864
+
// Ensure i2c ready
865
+
delta= (HAL_GetTick() -tickstart);
866
+
if (delta>I2C_TIMEOUT_TICK) {
867
+
ret=I2C_BUSY;
868
+
break;
869
+
}
870
+
}
871
+
if (ret==I2C_OK) {
872
+
tickstart=HAL_GetTick();
865
873
// wait for transfer completion
866
874
while ((HAL_I2C_GetState(&(obj->handle)) !=HAL_I2C_STATE_READY) && (delta<I2C_TIMEOUT_TICK)) {
0 commit comments