diff --git a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino index 1d993a77..b09c455e 100644 --- a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino +++ b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino @@ -112,6 +112,11 @@ void loop() { } + // clean up after transmission is finished + // this will ensure transmitter is disabled, + // RF switch is powered down etc. + radio.finishTransmit(); + // wait a second before transmitting again delay(1000); diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp index cd1365f3..9f0f3b1a 100644 --- a/src/modules/CC1101/CC1101.cpp +++ b/src/modules/CC1101/CC1101.cpp @@ -114,8 +114,7 @@ int16_t CC1101::transmit(uint8_t* data, size_t len, uint8_t addr) { _mod->yield(); if(_mod->micros() - start > timeout) { - standby(); - SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX); + finishTransmit(); return(RADIOLIB_ERR_TX_TIMEOUT); } } @@ -126,19 +125,12 @@ int16_t CC1101::transmit(uint8_t* data, size_t len, uint8_t addr) { _mod->yield(); if(_mod->micros() - start > timeout) { - standby(); - SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX); + finishTransmit(); return(RADIOLIB_ERR_TX_TIMEOUT); } } - // set mode to standby - standby(); - - // flush Tx FIFO - SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX); - - return(state); + return(finishTransmit()); } int16_t CC1101::receive(uint8_t* data, size_t len) { @@ -329,6 +321,16 @@ int16_t CC1101::startTransmit(uint8_t* data, size_t len, uint8_t addr) { return (state); } +int16_t CC1101::finishTransmit() { + // set mode to standby to disable transmitter/RF switch + int16_t state = standby(); + + // flush Tx FIFO + SPIsendCommand(RADIOLIB_CC1101_CMD_FLUSH_TX); + + return(state); +} + int16_t CC1101::startReceive() { // set mode to standby standby(); @@ -730,7 +732,7 @@ int16_t CC1101::setOOK(bool enableOOK) { return(setOutputPower(_power)); } -float CC1101::getRSSI() { +float CC1101::getRSSI() { float rssi; if (_directMode) { diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h index 037ee091..2c9a9714 100644 --- a/src/modules/CC1101/CC1101.h +++ b/src/modules/CC1101/CC1101.h @@ -666,6 +666,13 @@ class CC1101: public PhysicalLayer { */ int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override; + /*! + \brief Clean up after transmission is done. + + \returns \ref status_codes + */ + int16_t finishTransmit() override; + /*! \brief Interrupt-driven receive method. GDO0 will be activated when full packet is received.