Skip to content

Commit 63366dd

Browse files
authored
check I2C baudrate prescaler range
1 parent f6148c3 commit 63366dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cores/arduino/SERCOM.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,12 @@ void SERCOM::initMasterWIRE( uint32_t baudrate )
458458
// sercom->I2CM.INTENSET.reg = SERCOM_I2CM_INTENSET_MB | SERCOM_I2CM_INTENSET_SB | SERCOM_I2CM_INTENSET_ERROR ;
459459

460460
// Synchronous arithmetic baudrate
461-
sercom->I2CM.BAUD.bit.BAUD = SystemCoreClock / ( 2 * baudrate) - 5 - (((SystemCoreClock / 1000000) * WIRE_RISE_TIME_NANOSECONDS) / (2 * 1000));
461+
baudrate = SystemCoreClock / ( 2 * baudrate) - 5 - (((SystemCoreClock / 1000000) * WIRE_RISE_TIME_NANOSECONDS) / (2 * 1000));
462+
if(baudrate > 255) // I2C baud rate is 8bit
463+
{
464+
baudrate = 255;
465+
}
466+
sercom->I2CM.BAUD.bit.BAUD = baudrate;
462467
}
463468

464469
void SERCOM::prepareNackBitWIRE( void )

0 commit comments

Comments
 (0)