diff --git a/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino b/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino index cf54ed75..163f8273 100644 --- a/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino +++ b/examples/SX127x/SX127x_Channel_Activity_Detection/SX127x_Channel_Activity_Detection.ino @@ -19,8 +19,9 @@ // SX1278 has the following connections: // NSS pin: 10 // DIO0 pin: 2 +// RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 3); +SX1278 lora = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino index 1c8cd1da..f9c89154 100644 --- a/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino +++ b/examples/SX127x/SX127x_FSK_Modem/SX127x_FSK_Modem.ino @@ -19,8 +19,9 @@ // SX1278 has the following connections: // NSS pin: 10 // DIO0 pin: 2 +// RESET pin: 9 // DIO1 pin: 3 -SX1278 fsk = new Module(10, 2, 3); +SX1278 fsk = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/SX127x/SX127x_Receive/SX127x_Receive.ino b/examples/SX127x/SX127x_Receive/SX127x_Receive.ino index c3c3392e..5627bdc3 100644 --- a/examples/SX127x/SX127x_Receive/SX127x_Receive.ino +++ b/examples/SX127x/SX127x_Receive/SX127x_Receive.ino @@ -23,8 +23,9 @@ // SX1278 has the following connections: // NSS pin: 10 // DIO0 pin: 2 +// RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 3); +SX1278 lora = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino index d204348b..fbc20651 100644 --- a/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino +++ b/examples/SX127x/SX127x_Receive_Interrupt/SX127x_Receive_Interrupt.ino @@ -24,8 +24,9 @@ // SX1278 has the following connections: // NSS pin: 10 // DIO0 pin: 2 +// RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 3); +SX1278 lora = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino index 63fbc9cc..681c76d2 100644 --- a/examples/SX127x/SX127x_Settings/SX127x_Settings.ino +++ b/examples/SX127x/SX127x_Settings/SX127x_Settings.ino @@ -23,14 +23,16 @@ // SX1278 has the following connections: // NSS pin: 10 // DIO0 pin: 2 +// RESET pin: 9 // DIO1 pin: 3 -SX1278 loraSX1278 = new Module(10, 2, 3); +SX1278 loraSX1278 = new Module(10, 2, 9, 3); // SX1272 has different connections: // NSS pin: 9 // DIO0 pin: 4 -// DIO1 pin: 5 -SX1272 loraSX1272 = new Module(9, 4, 5); +// RESET pin: 5 +// DIO1 pin: 6 +SX1272 loraSX1272 = new Module(9, 4, 5, 6); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino index 2573a41d..d14e76f7 100644 --- a/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino +++ b/examples/SX127x/SX127x_Transmit/SX127x_Transmit.ino @@ -19,8 +19,9 @@ // SX1278 has the following connections: // NSS pin: 10 // DIO0 pin: 2 +// RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 3); +SX1278 lora = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino index 08681c9e..8368a7d4 100644 --- a/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino +++ b/examples/SX127x/SX127x_Transmit_Interrupt/SX127x_Transmit_Interrupt.ino @@ -20,8 +20,9 @@ // SX1278 has the following connections: // NSS pin: 10 // DIO0 pin: 2 +// RESET pin: 9 // DIO1 pin: 3 -SX1278 lora = new Module(10, 2, 3); +SX1278 lora = new Module(10, 2, 9, 3); // or using RadioShield // https://github.com/jgromes/RadioShield diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 9347f44c..23bd0785 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -7,7 +7,12 @@ SX127x::SX127x(Module* mod) : PhysicalLayer(SX127X_CRYSTAL_FREQ, SX127X_DIV_EXPO int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength) { // set module properties - _mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_BOTH); + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); + Module::pinMode(_mod->getGpio(), INPUT); + + // reset the module + reset(); // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { @@ -54,7 +59,11 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK) { // set module properties - _mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_BOTH); + _mod->init(RADIOLIB_USE_SPI); + Module::pinMode(_mod->getIrq(), INPUT); + + // reset the module + reset(); // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { @@ -145,6 +154,15 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB return(state); } +void SX127x::reset() { + Module::pinMode(_mod->getRst(), OUTPUT); + Module::digitalWrite(_mod->getRst(), LOW); + delayMicroseconds(100); + Module::digitalWrite(_mod->getRst(), HIGH); + Module::pinMode(_mod->getRst(), INPUT); + delay(5); +} + int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { // set mode to standby int16_t state = setMode(SX127X_STANDBY); @@ -172,7 +190,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for packet transmission or timeout start = micros(); - while(!digitalRead(_mod->getInt0())) { + while(!digitalRead(_mod->getIrq())) { if(micros() - start > timeout) { clearIRQFlags(); return(ERR_TX_TIMEOUT); @@ -191,7 +209,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) { // wait for transmission end or timeout start = micros(); - while(!digitalRead(_mod->getInt0())) { + while(!digitalRead(_mod->getIrq())) { if(micros() - start > timeout) { clearIRQFlags(); standby(); @@ -226,8 +244,8 @@ int16_t SX127x::receive(uint8_t* data, size_t len) { } // wait for packet reception or timeout (100 LoRa symbols) - while(!digitalRead(_mod->getInt0())) { - if(digitalRead(_mod->getInt1())) { + while(!digitalRead(_mod->getIrq())) { + if(digitalRead(_mod->getGpio())) { clearIRQFlags(); return(ERR_RX_TIMEOUT); } @@ -245,7 +263,7 @@ int16_t SX127x::receive(uint8_t* data, size_t len) { // wait for packet reception or timeout uint32_t start = micros(); - while(!digitalRead(_mod->getInt0())) { + while(!digitalRead(_mod->getIrq())) { if(micros() - start > timeout) { clearIRQFlags(); return(ERR_RX_TIMEOUT); @@ -281,8 +299,8 @@ int16_t SX127x::scanChannel() { } // wait for channel activity detected or timeout - while(!digitalRead(_mod->getInt0())) { - if(digitalRead(_mod->getInt1())) { + while(!digitalRead(_mod->getIrq())) { + if(digitalRead(_mod->getGpio())) { clearIRQFlags(); return(PREAMBLE_DETECTED); } @@ -411,11 +429,11 @@ int16_t SX127x::startReceive(uint8_t len, uint8_t mode) { } void SX127x::setDio0Action(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, RISING); + attachInterrupt(digitalPinToInterrupt(_mod->getIrq()), func, RISING); } void SX127x::setDio1Action(void (*func)(void)) { - attachInterrupt(digitalPinToInterrupt(_mod->getInt1()), func, RISING); + attachInterrupt(digitalPinToInterrupt(_mod->getGpio()), func, RISING); } int16_t SX127x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { diff --git a/src/modules/SX127x/SX127x.h b/src/modules/SX127x/SX127x.h index c805f5f9..2d1f0328 100644 --- a/src/modules/SX127x/SX127x.h +++ b/src/modules/SX127x/SX127x.h @@ -563,6 +563,11 @@ class SX127x: public PhysicalLayer { */ int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength); + /*! + \brief Reset method. Will reset the chip to the default state using RST pin. + */ + void reset(); + /*! \brief Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class.