diff --git a/examples/CC1101/CC1101_Receive/CC1101_Receive.ino b/examples/CC1101/CC1101_Receive/CC1101_Receive.ino index 8c851088..57cd221b 100644 --- a/examples/CC1101/CC1101_Receive/CC1101_Receive.ino +++ b/examples/CC1101/CC1101_Receive/CC1101_Receive.ino @@ -17,10 +17,11 @@ #include // CC1101 has the following connections: -// NSS pin: 10 +// CS pin: 10 // GDO0 pin: 2 -// GDO2 pin: 3 -CC1101 cc = new Module(10, 2, 3); +// RST pin: unused +// GDO2 pin: 3 (optional) +CC1101 cc = new Module(10, 2, RADIOLIB_PIN_UNUSED, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino b/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino index 1f1aa5bf..95daa3b7 100644 --- a/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino +++ b/examples/CC1101/CC1101_Receive_Address/CC1101_Receive_Address.ino @@ -15,10 +15,11 @@ #include // CC1101 has the following connections: -// NSS pin: 10 +// CS pin: 10 // GDO0 pin: 2 -// GDO2 pin: 3 -CC1101 cc = new Module(10, 2, 3); +// RST pin: unused +// GDO2 pin: 3 (optional) +CC1101 cc = new Module(10, 2, RADIOLIB_PIN_UNUSED, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino index a4307ab4..2785fe4c 100644 --- a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino +++ b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino @@ -20,10 +20,11 @@ #include // CC1101 has the following connections: -// NSS pin: 10 +// CS pin: 10 // GDO0 pin: 2 -// GDO2 pin: 3 -CC1101 cc = new Module(10, 2, 3); +// RST pin: unused +// GDO2 pin: 3 (optional) +CC1101 cc = new Module(10, 2, RADIOLIB_PIN_UNUSED, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino index 7dca22ae..2f47ccb9 100644 --- a/examples/CC1101/CC1101_Settings/CC1101_Settings.ino +++ b/examples/CC1101/CC1101_Settings/CC1101_Settings.ino @@ -19,16 +19,18 @@ #include // CC1101 has the following connections: -// NSS pin: 10 +// CS pin: 10 // GDO0 pin: 2 -// GDO2 pin: 3 -CC1101 cc1 = new Module(10, 2, 3); +// RST pin: unused +// GDO2 pin: 3 (optional) +CC1101 cc1 = new Module(10, 2, RADIOLIB_PIN_UNUSED, 3); // second CC1101 has different connections: -// NSS pin: 9 +// CS pin: 9 // GDO0 pin: 4 -// GDO2 pin: 5 -CC1101 cc2 = new Module(9, 4, 5); +// RST pin: unused +// GDO2 pin: 5 (optional) +CC1101 cc2 = new Module(9, 4, RADIOLIB_PIN_UNUSED, 53); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino b/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino index 87bde6e1..672bed0a 100644 --- a/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino +++ b/examples/CC1101/CC1101_Transmit/CC1101_Transmit.ino @@ -15,10 +15,11 @@ #include // CC1101 has the following connections: -// NSS pin: 10 +// CS pin: 10 // GDO0 pin: 2 -// GDO2 pin: 3 -CC1101 cc = new Module(10, 2, 3); +// RST pin: unused +// GDO2 pin: 3 (optional) +CC1101 cc1 = new Module(10, 2, RADIOLIB_PIN_UNUSED, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino index b9e8a966..6c8205d5 100644 --- a/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino +++ b/examples/CC1101/CC1101_Transmit_Address/CC1101_Transmit_Address.ino @@ -15,10 +15,11 @@ #include // CC1101 has the following connections: -// NSS pin: 10 +// CS pin: 10 // GDO0 pin: 2 -// GDO2 pin: 3 -CC1101 cc = new Module(10, 2, 3); +// RST pin: unused +// GDO2 pin: 3 (optional) +CC1101 cc1 = new Module(10, 2, RADIOLIB_PIN_UNUSED, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino index 14bf31eb..abfae5ac 100644 --- a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino +++ b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino @@ -16,10 +16,11 @@ #include // CC1101 has the following connections: -// NSS pin: 10 +// CS pin: 10 // GDO0 pin: 2 -// GDO2 pin: 3 -CC1101 cc = new Module(10, 2, 3); +// RST pin: unused +// GDO2 pin: 3 (optional) +CC1101 cc1 = new Module(10, 2, RADIOLIB_PIN_UNUSED, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index 5be2e21e..d0770ef0 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -13,7 +13,8 @@ int16_t CC1101::begin(float freq, float br, float rxBw, float freqDev, int8_t po // set module properties _mod->SPIreadCommand = CC1101_CMD_READ; _mod->SPIwriteCommand = CC1101_CMD_WRITE; - _mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_0); + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); // try to find the CC1101 chip uint8_t i = 0; @@ -110,10 +111,10 @@ int16_t CC1101::transmit(uint8_t* data, size_t len, uint8_t addr) { } // wait for transmission start - while(!digitalRead(_mod->getInt0())); + while(!digitalRead(_mod->getIrq())); // wait for transmission end - while(digitalRead(_mod->getInt0())); + while(digitalRead(_mod->getIrq())); // set mode to standby standby(); @@ -132,10 +133,10 @@ int16_t CC1101::receive(uint8_t* data, size_t len) { } // wait for sync word - while(!digitalRead(_mod->getInt0())); + while(!digitalRead(_mod->getIrq())); // wait for packet end - while(digitalRead(_mod->getInt0())); + while(digitalRead(_mod->getIrq())); // read packet data return(readData(data, len)); @@ -187,11 +188,15 @@ int16_t CC1101::packetMode() { } void CC1101::setGdo0Action(void (*func)(void), uint8_t dir) { - attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, dir); + attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, dir); } void CC1101::setGdo2Action(void (*func)(void), uint8_t dir) { - attachInterrupt(digitalPinToInterrupt(_mod->getInt1()), func, dir); + if(_mod->getGpio() != RADIOLIB_PIN_UNUSED) { + return; + } + Module::pinMode(_mod->getGpio(), INPUT); + attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, dir); } int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { @@ -808,9 +813,9 @@ void CC1101::SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, size_t len) { } void CC1101::SPIsendCommand(uint8_t cmd) { - digitalWrite(_mod->getCs(), LOW); + Module::digitalWrite(_mod->getCs(), LOW); SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0)); SPI.transfer(cmd); SPI.endTransaction(); - digitalWrite(_mod->getCs(), HIGH); + Module::digitalWrite(_mod->getCs(), HIGH); }