Skip to content

Commit 6a12954

Browse files
agdlsandeepmistry
authored andcommitted
Allow General Calls on I2C bus (aka brodcast)
1 parent 3cb328a commit 6a12954

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

cores/arduino/SERCOM.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void SERCOM::enableWIRE()
370370
{
371371
// I2C Master and Slave modes share the ENABLE bit function.
372372

373-
// Enable the I²C master mode
373+
// Enable the I2C master mode
374374
sercom->I2CM.CTRLA.bit.ENABLE = 1 ;
375375

376376
while ( sercom->I2CM.SYNCBUSY.bit.ENABLE != 0 )
@@ -391,7 +391,7 @@ void SERCOM::disableWIRE()
391391
{
392392
// I2C Master and Slave modes share the ENABLE bit function.
393393

394-
// Enable the I²C master mode
394+
// Enable the I2C master mode
395395
sercom->I2CM.CTRLA.bit.ENABLE = 0 ;
396396

397397
while ( sercom->I2CM.SYNCBUSY.bit.ENABLE != 0 )
@@ -400,17 +400,20 @@ void SERCOM::disableWIRE()
400400
}
401401
}
402402

403-
void SERCOM::initSlaveWIRE( uint8_t ucAddress )
403+
void SERCOM::initSlaveWIRE( uint8_t ucAddress, bool broadcast )
404404
{
405405
// Initialize the peripheral clock and interruption
406406
initClockNVIC() ;
407407
resetWIRE() ;
408408

409409
// Set slave mode
410-
sercom->I2CS.CTRLA.bit.MODE = I2C_SLAVE_OPERATION ;
410+
sercom->I2CS.CTRLA.bit.MODE = I2C_SLAVE_OPERATION;
411411

412412
sercom->I2CS.ADDR.reg = SERCOM_I2CS_ADDR_ADDR( ucAddress & 0x7Ful ) | // 0x7F, select only 7 bits
413-
SERCOM_I2CS_ADDR_ADDRMASK( 0x00ul ) ; // 0x00, only match exact address
413+
SERCOM_I2CS_ADDR_ADDRMASK( 0x00ul ); // 0x00, only match exact address
414+
if (broadcast) {
415+
sercom->I2CS.ADDR.reg |= SERCOM_I2CS_ADDR_GENCEN; // enable general call (address 0x00)
416+
}
414417

415418
// Set the interrupt register
416419
sercom->I2CS.INTENSET.reg = SERCOM_I2CS_INTENSET_PREC | // Stop

cores/arduino/SERCOM.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class SERCOM
184184
bool isReceiveCompleteSPI( void ) ;
185185

186186
/* ========== WIRE ========== */
187-
void initSlaveWIRE(uint8_t address) ;
187+
void initSlaveWIRE(uint8_t address, bool broadcast = false) ;
188188
void initMasterWIRE(uint32_t baudrate) ;
189189

190190
void resetWIRE( void ) ;

libraries/Wire/Wire.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ void TwoWire::begin(void) {
4343
pinPeripheral(_uc_pinSCL, g_APinDescription[_uc_pinSCL].ulPinType);
4444
}
4545

46-
void TwoWire::begin(uint8_t address) {
46+
void TwoWire::begin(uint8_t address, bool broadcast) {
4747
//Slave mode
48-
sercom->initSlaveWIRE(address);
48+
sercom->initSlaveWIRE(address, broadcast);
4949
sercom->enableWIRE();
5050

5151
pinPeripheral(_uc_pinSDA, g_APinDescription[_uc_pinSDA].ulPinType);

libraries/Wire/Wire.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TwoWire : public Stream
3434
public:
3535
TwoWire(SERCOM *s, uint8_t pinSDA, uint8_t pinSCL);
3636
void begin();
37-
void begin(uint8_t);
37+
void begin(uint8_t, bool broadcast = false);
3838
void end();
3939
void setClock(uint32_t);
4040

0 commit comments

Comments
 (0)