Skip to content

Commit 289a272

Browse files
committed
I2C: clear ERROR flag before checking it
Commit ccfc7db introduced checks for INTFLAG::ERROR. From the datasheet: Bit 7 – ERROR Error This flag is cleared by writing '1' to it. This bit is set when any error is detected. Errors that will set this flag have corresponding status bits in the STATUS register. These status bits are LENERR, SEXTTOUT, MEXTTOUT, LOWTOUT, ARBLOST, and BUSERR. Writing '0' to this bit has no effect. Writing '1' to this bit will clear the flag. Also restore the change before commit 34d15d0, as the missing clear of the flag appears to cause the problem.
1 parent dd91ca4 commit 289a272

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cores/arduino/SERCOM.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ bool SERCOM::startTransmissionWIRE(uint8_t address, SercomWireReadWriteFlag flag
562562
}
563563

564564
// Send start and address
565+
sercom->I2CM.INTFLAG.bit.ERROR = 1;
565566
sercom->I2CM.ADDR.reg = SERCOM_I2CM_ADDR_ADDR(address) |
566567
((sercom->I2CM.CTRLA.bit.SPEED == 0x2) ? SERCOM_I2CM_ADDR_HS : 0);
567568

@@ -611,13 +612,16 @@ bool SERCOM::startTransmissionWIRE(uint8_t address, SercomWireReadWriteFlag flag
611612
bool SERCOM::sendDataMasterWIRE(uint8_t data)
612613
{
613614
//Send data
615+
sercom->I2CM.INTFLAG.bit.ERROR = 1;
614616
sercom->I2CM.DATA.bit.DATA = data;
615617

616618
//Wait transmission successful
617619
while(!sercom->I2CM.INTFLAG.bit.MB) {
618620
// If a data transfer error occurs, the MB bit may never be set.
619621
// Check the error bit and bail if it's set.
620-
if (sercom->I2CM.STATUS.bit.BUSERR) {
622+
// The data transfer errors that can occur (including BUSERR) are all
623+
// rolled up into INTFLAG.bit.ERROR from STATUS.reg
624+
if (sercom->I2CM.INTFLAG.bit.ERROR) {
621625
return false;
622626
}
623627
}

0 commit comments

Comments
 (0)