This driver is a stripped down version of the Radiohead 1.45 driver, and covers fewer radios. Threading and an event queue have been added to make the ISR's more stable across architectures. Specifically The STM32L4 parts
Dependents: Threaded_LoRa_Modem
Diff: RH_RF95.cpp
- Revision:
- 1:dfeb5e8b199a
- Parent:
- 0:ab4e012489ef
- Child:
- 3:6ffa8c82a713
--- a/RH_RF95.cpp Thu Oct 15 01:27:00 2015 +0000 +++ b/RH_RF95.cpp Fri Apr 30 15:16:24 2021 +0000 @@ -34,6 +34,7 @@ bool RH_RF95::init() { + printf("Initializing...\n"); if (!RHSPIDriver::init()) return false; @@ -44,6 +45,7 @@ return false; #endif + // No way to check the device type :-( // Set sleep mode, so we can also set LORA mode: @@ -52,7 +54,7 @@ // Check we are in sleep mode, with LORA set if (spiRead(RH_RF95_REG_01_OP_MODE) != (RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE)) { -// Serial.println(spiRead(RH_RF95_REG_01_OP_MODE), HEX); + printf("Mode:%x\n",spiRead(RH_RF95_REG_01_OP_MODE)); return false; // No device present? } @@ -80,6 +82,7 @@ _deviceForInterrupt[_myInterruptIndex] = this; #if (RH_PLATFORM == RH_PLATFORM_MBED) + _interruptPin.mode(PullDown); if (_myInterruptIndex == 0) _interruptPin.rise(&isr0); else if (_myInterruptIndex == 1) @@ -101,6 +104,7 @@ // Set up FIFO // We configure so that we can use the entire 256 byte FIFO for either receive // or transmit, but not both at the same time + printf("using ISR %d\n",_myInterruptIndex); spiWrite(RH_RF95_REG_0E_FIFO_TX_BASE_ADDR, 0); spiWrite(RH_RF95_REG_0F_FIFO_RX_BASE_ADDR, 0); @@ -121,7 +125,7 @@ setFrequency(434.0); // Lowish power setTxPower(13); - + printf("Ready!\n"); return true; } @@ -208,8 +212,10 @@ bool RH_RF95::available() { - if (_mode == RHModeTx) - return false; + if (_mode == RHModeTx){ + return false; + } + setModeRx(); return _rxBufValid; // Will be set by the interrupt handler when a good message is received } @@ -299,17 +305,20 @@ { if (_mode != RHModeIdle) { - spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_STDBY); - _mode = RHModeIdle; + printf("---- Idle\n"); + spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_STDBY); + _mode = RHModeIdle; } } bool RH_RF95::sleep() { + if (_mode != RHModeSleep) { - spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_SLEEP); - _mode = RHModeSleep; + printf("---- Sleep\n"); + spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_SLEEP); + _mode = RHModeSleep; } return true; } @@ -318,9 +327,10 @@ { if (_mode != RHModeRx) { - spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_RXCONTINUOUS); - spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x00); // Interrupt on RxDone - _mode = RHModeRx; + printf("---- RX\n"); + spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_RXCONTINUOUS); + spiWrite(RH_RF95_REG_40_DIO_MAPPING1, RH_RF95_DIOMAPPING1_DIO0MAPPING_01); // Interrupt on RxDone + _mode = RHModeRx; } } @@ -328,9 +338,10 @@ { if (_mode != RHModeTx) { - spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_TX); - spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x40); // Interrupt on TxDone - _mode = RHModeTx; + printf("---- TX\n"); + spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_TX); + spiWrite(RH_RF95_REG_40_DIO_MAPPING1, RH_RF95_DIOMAPPING1_DIO0MAPPING_00); // Interrupt on TxDone + _mode = RHModeTx; } }