diff --git a/cores/arduino/SERCOM.cpp b/cores/arduino/SERCOM.cpp index 42c46d015..555f02c38 100644 --- a/cores/arduino/SERCOM.cpp +++ b/cores/arduino/SERCOM.cpp @@ -370,7 +370,7 @@ void SERCOM::enableWIRE() { // I2C Master and Slave modes share the ENABLE bit function. - // Enable the I�C master mode + // Enable the I2C master mode sercom->I2CM.CTRLA.bit.ENABLE = 1 ; while ( sercom->I2CM.SYNCBUSY.bit.ENABLE != 0 ) @@ -391,7 +391,7 @@ void SERCOM::disableWIRE() { // I2C Master and Slave modes share the ENABLE bit function. - // Enable the I�C master mode + // Enable the I2C master mode sercom->I2CM.CTRLA.bit.ENABLE = 0 ; while ( sercom->I2CM.SYNCBUSY.bit.ENABLE != 0 ) @@ -400,17 +400,20 @@ void SERCOM::disableWIRE() } } -void SERCOM::initSlaveWIRE( uint8_t ucAddress ) +void SERCOM::initSlaveWIRE( uint8_t ucAddress, bool enableGeneralCall ) { // Initialize the peripheral clock and interruption initClockNVIC() ; resetWIRE() ; // Set slave mode - sercom->I2CS.CTRLA.bit.MODE = I2C_SLAVE_OPERATION ; + sercom->I2CS.CTRLA.bit.MODE = I2C_SLAVE_OPERATION; sercom->I2CS.ADDR.reg = SERCOM_I2CS_ADDR_ADDR( ucAddress & 0x7Ful ) | // 0x7F, select only 7 bits - SERCOM_I2CS_ADDR_ADDRMASK( 0x00ul ) ; // 0x00, only match exact address + SERCOM_I2CS_ADDR_ADDRMASK( 0x00ul ); // 0x00, only match exact address + if (enableGeneralCall) { + sercom->I2CS.ADDR.reg |= SERCOM_I2CS_ADDR_GENCEN; // enable general call (address 0x00) + } // Set the interrupt register sercom->I2CS.INTENSET.reg = SERCOM_I2CS_INTENSET_PREC | // Stop diff --git a/cores/arduino/SERCOM.h b/cores/arduino/SERCOM.h index 6b7c703a7..3d4839b5d 100644 --- a/cores/arduino/SERCOM.h +++ b/cores/arduino/SERCOM.h @@ -184,7 +184,7 @@ class SERCOM bool isReceiveCompleteSPI( void ) ; /* ========== WIRE ========== */ - void initSlaveWIRE(uint8_t address) ; + void initSlaveWIRE(uint8_t address, bool enableGeneralCall = false) ; void initMasterWIRE(uint32_t baudrate) ; void resetWIRE( void ) ; diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 0326bf68f..b94389b0a 100644 --- a/libraries/Wire/Wire.cpp +++ b/libraries/Wire/Wire.cpp @@ -43,9 +43,9 @@ void TwoWire::begin(void) { pinPeripheral(_uc_pinSCL, g_APinDescription[_uc_pinSCL].ulPinType); } -void TwoWire::begin(uint8_t address) { +void TwoWire::begin(uint8_t address, bool enableGeneralCall) { //Slave mode - sercom->initSlaveWIRE(address); + sercom->initSlaveWIRE(address, enableGeneralCall); sercom->enableWIRE(); pinPeripheral(_uc_pinSDA, g_APinDescription[_uc_pinSDA].ulPinType); diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index f437db894..3ea958d92 100644 --- a/libraries/Wire/Wire.h +++ b/libraries/Wire/Wire.h @@ -34,7 +34,7 @@ class TwoWire : public Stream public: TwoWire(SERCOM *s, uint8_t pinSDA, uint8_t pinSCL); void begin(); - void begin(uint8_t); + void begin(uint8_t, bool enableGeneralCall = false); void end(); void setClock(uint32_t);