From 87c5f7dc0b31ab0a46b460e1463c6c978072a1b4 Mon Sep 17 00:00:00 2001 From: agdl Date: Mon, 11 Dec 2017 16:10:42 +0100 Subject: [PATCH 1/2] Allow General Calls on I2C bus (aka brodcast) --- cores/arduino/SERCOM.cpp | 13 ++++++++----- cores/arduino/SERCOM.h | 2 +- libraries/Wire/Wire.cpp | 4 ++-- libraries/Wire/Wire.h | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cores/arduino/SERCOM.cpp b/cores/arduino/SERCOM.cpp index 42c46d015..223f8ad97 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 broadcast ) { // 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 (broadcast) { + 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..37b52b3c6 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 broadcast = false) ; void initMasterWIRE(uint32_t baudrate) ; void resetWIRE( void ) ; diff --git a/libraries/Wire/Wire.cpp b/libraries/Wire/Wire.cpp index 0326bf68f..3fd10d985 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 broadcast) { //Slave mode - sercom->initSlaveWIRE(address); + sercom->initSlaveWIRE(address, broadcast); sercom->enableWIRE(); pinPeripheral(_uc_pinSDA, g_APinDescription[_uc_pinSDA].ulPinType); diff --git a/libraries/Wire/Wire.h b/libraries/Wire/Wire.h index f437db894..01fb515fd 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 broadcast = false); void end(); void setClock(uint32_t); From d0dfd4acc847ef7233040309cb1a6c99c63c157f Mon Sep 17 00:00:00 2001 From: agdl Date: Fri, 15 Dec 2017 15:02:10 +0100 Subject: [PATCH 2/2] Changed boradcast variable to enableGeneralCall --- cores/arduino/SERCOM.cpp | 4 ++-- cores/arduino/SERCOM.h | 2 +- libraries/Wire/Wire.cpp | 4 ++-- libraries/Wire/Wire.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cores/arduino/SERCOM.cpp b/cores/arduino/SERCOM.cpp index 223f8ad97..555f02c38 100644 --- a/cores/arduino/SERCOM.cpp +++ b/cores/arduino/SERCOM.cpp @@ -400,7 +400,7 @@ void SERCOM::disableWIRE() } } -void SERCOM::initSlaveWIRE( uint8_t ucAddress, bool broadcast ) +void SERCOM::initSlaveWIRE( uint8_t ucAddress, bool enableGeneralCall ) { // Initialize the peripheral clock and interruption initClockNVIC() ; @@ -411,7 +411,7 @@ void SERCOM::initSlaveWIRE( uint8_t ucAddress, bool broadcast ) 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 - if (broadcast) { + if (enableGeneralCall) { sercom->I2CS.ADDR.reg |= SERCOM_I2CS_ADDR_GENCEN; // enable general call (address 0x00) } diff --git a/cores/arduino/SERCOM.h b/cores/arduino/SERCOM.h index 37b52b3c6..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, bool broadcast = false) ; + 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 3fd10d985..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, bool broadcast) { +void TwoWire::begin(uint8_t address, bool enableGeneralCall) { //Slave mode - sercom->initSlaveWIRE(address, broadcast); + 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 01fb515fd..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, bool broadcast = false); + void begin(uint8_t, bool enableGeneralCall = false); void end(); void setClock(uint32_t);