Skip to content

Allow General Calls on I2C bus (aka broadcast) #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cores/arduino/SERCOM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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 )
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/SERCOM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ;
Expand Down
4 changes: 2 additions & 2 deletions libraries/Wire/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libraries/Wire/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down