@@ -556,37 +556,35 @@ bool SERCOM::startTransmissionWIRE(uint8_t address, SercomWireReadWriteFlag flag
556556 // Address Transmitted
557557 if ( flag == WIRE_WRITE_FLAG ) // Write mode
558558 {
559- while ( !sercom->I2CM .INTFLAG .bit .MB )
560- {
559+ while ( !sercom->I2CM .INTFLAG .bit .MB ) {
561560 // Wait transmission complete
562561
563- // If certain errors occur, the MB bit may never be set (RFTM: SAMD21 sec:28.10.6; SAMD51 sec:36.10.7).
564- // The data transfer errors that can occur (including BUSERR) are all
565- // rolled up into INTFLAG.bit.ERROR from STATUS.reg
566- if (sercom->I2CM .INTFLAG .bit .ERROR ) {
567- return false ;
568- }
562+ // If certain errors occur, the MB bit may never be set (RFTM: SAMD21 sec:28.10.6; SAMD51 sec:36.10.7).
563+ // The data transfer errors that can occur (including BUSERR) are all
564+ // rolled up into INTFLAG.bit.ERROR from STATUS.reg
565+ if (sercom->I2CM .INTFLAG .bit .ERROR ) {
566+ return false ;
567+ }
569568 }
570569 }
571570 else // Read mode
572571 {
573- while ( !sercom->I2CM .INTFLAG .bit .SB )
574- {
575- // If the slave NACKS the address, the MB bit will be set.
576- // A variety of errors in the STATUS register can set the ERROR bit in the INTFLAG register
577- // In that case, send a stop condition and return false.
578- if (sercom->I2CM .INTFLAG .bit .ERROR || sercom->I2CM .INTFLAG .bit .MB ) {
579- sercom->I2CM .CTRLB .bit .CMD = 3 ; // Stop condition
580- return false ;
581- }
572+ while ( !sercom->I2CM .INTFLAG .bit .SB ) {
582573 // Wait transmission complete
574+
575+ // If the slave NACKS the address, the MB bit will be set.
576+ // A variety of errors in the STATUS register can set the ERROR bit in the INTFLAG register
577+ // In that case, send a stop condition and return false.
578+ if (sercom->I2CM .INTFLAG .bit .MB || sercom->I2CM .INTFLAG .bit .ERROR ) {
579+ sercom->I2CM .CTRLB .bit .CMD = 3 ; // Stop condition
580+ return false ;
581+ }
583582 }
584583
585584 // Clean the 'Slave on Bus' flag, for further usage.
586585 // sercom->I2CM.INTFLAG.bit.SB = 0x1ul;
587586 }
588587
589-
590588 // ACK received (0: ACK, 1: NACK)
591589 if (sercom->I2CM .STATUS .bit .RXNACK )
592590 {
@@ -605,11 +603,10 @@ bool SERCOM::sendDataMasterWIRE(uint8_t data)
605603
606604 // Wait transmission successful
607605 while (!sercom->I2CM .INTFLAG .bit .MB ) {
608-
609606 // If a data transfer error occurs, the MB bit may never be set.
610607 // Check the error bit and bail if it's set.
611608 // The data transfer errors that can occur (including BUSERR) are all
612- // rolled up into INTFLAG.bit.ERROR from STATUS.reg
609+ // rolled up into INTFLAG.bit.ERROR from STATUS.reg
613610 if (sercom->I2CM .INTFLAG .bit .ERROR ) {
614611 return false ;
615612 }
@@ -711,18 +708,17 @@ uint8_t SERCOM::readDataWIRE( void )
711708{
712709 if (isMasterWIRE ())
713710 {
714- while ( sercom->I2CM .INTFLAG .bit .SB == 0 )
715- {
711+ while (sercom->I2CM .INTFLAG .bit .SB == 0 ) {
716712 // Waiting complete receive
717- // A variety of errors in the STATUS register can set the ERROR bit in the INTFLAG register
713+ // A variety of errors in the STATUS register can set the ERROR bit in the INTFLAG register
718714 // In that case, send a stop condition and return false.
719- // readDataWIRE should really be able to indicate an error (which would never be used
720- // because the readDataWIRE callers (in Wire.cpp) should have checked availableWIRE() first and timed it
721- // out if the data never showed up
722- if (sercom->I2CM .INTFLAG .bit .ERROR || sercom->I2CM .INTFLAG .bit .MB ) {
723- sercom->I2CM .CTRLB .bit .CMD = 3 ; // Stop condition
724- return 0xFF ;
725- }
715+ // readDataWIRE should really be able to indicate an error (which would never be used
716+ // because the readDataWIRE callers (in Wire.cpp) should have checked availableWIRE() first and timed it
717+ // out if the data never showed up
718+ if (sercom->I2CM .INTFLAG .bit .MB || sercom->I2CM .INTFLAG .bit .ERROR ) {
719+ sercom->I2CM .CTRLB .bit .CMD = 3 ; // Stop condition
720+ return 0xFF ;
721+ }
726722 }
727723
728724 return sercom->I2CM .DATA .bit .DATA ;
0 commit comments