Skip to content

Commit 803cfa4

Browse files
committed
[rtl872x] hal: fix I2C detection.
1 parent 7f0408e commit 803cfa4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

hal/src/rtl872x/i2c_hal.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,22 @@ class I2cClass {
360360
setAddress(transConfig_.address);
361361

362362
uint32_t quantity = txBuffer_.data();
363+
if (quantity == 0) {
364+
// Clear flags
365+
uint32_t temp = i2cDev_->IC_CLR_TX_ABRT;
366+
(void)temp;
367+
if (i2cDev_->IC_TX_ABRT_SOURCE & 0x00000001) {
368+
return SYSTEM_ERROR_I2C_ABORT;
369+
}
370+
// Send the slave address only
371+
i2cDev_->IC_DATA_CMD = (transConfig_.address << 1) | (1 << 11);
372+
HAL_Delay_Milliseconds(5);
373+
if (i2cDev_->IC_TX_ABRT_SOURCE & 0x00000001) {
374+
return SYSTEM_ERROR_I2C_ABORT;
375+
}
376+
return SYSTEM_ERROR_NONE;
377+
}
378+
363379
for (uint32_t i = 0; i < quantity; i++) {
364380
if (!WAIT_TIMED(transConfig_.timeout_ms, I2C_CheckFlagState(i2cDev_, BIT_IC_STATUS_TFNF) == 0)) {
365381
reset();

0 commit comments

Comments
 (0)