Seding a STOP works too and is less drastic
Code wasn't sending stop on certain timeout events or with any
error conditions.
@@ -301,11 +301,8 @@ hal_i2c_master_write(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
err:
if (regs && regs->EVENTS_ERROR) {
rc = regs->ERRORSRC;
+ regs->TASKS_STOP = 1;
regs->ERRORSRC = rc;
-
- // Disable/re-enable to release SCL after an error
- regs->ENABLE = TWI_ENABLE_ENABLE_Disabled;
- regs->ENABLE = TWI_ENABLE_ENABLE_Enabled;
}
return (rc);
}
@@ -352,6 +349,7 @@ hal_i2c_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
while (!regs->EVENTS_RXDREADY && !regs->EVENTS_ERROR) {
if (os_time_get() - start > timo) {
regs->SHORTS = TWI_SHORTS_BB_STOP_Msk;
+ regs->TASKS_STOP = 1;
goto err;
}
}
@@ -370,11 +368,8 @@ hal_i2c_master_read(uint8_t i2c_num, struct hal_i2c_master_data *pdata,
err:
if (regs && regs->EVENTS_ERROR) {
rc = regs->ERRORSRC;
+ regs->TASKS_STOP = 1;
regs->ERRORSRC = rc;
-
- // Disable/re-enable to release SCL after an error
- regs->ENABLE = TWI_ENABLE_ENABLE_Disabled;
- regs->ENABLE = TWI_ENABLE_ENABLE_Enabled;
}
return (rc);
}
