From 6bc57d61b4b423e50fd3fbebb0054e3a76176239 Mon Sep 17 00:00:00 2001 From: TMRh20 Date: Wed, 3 Jul 2024 05:00:57 -0600 Subject: [PATCH] Allow reconfig of radio, add getRSSI() - Remove the `radioConfigured` variable so the radio will be reconfigured every time begin() is called like with RF24 - Add `getRSSI()` function - remove `begin()` from `powerUp()` function, as users will typically call `begin()` afterward - Set DPL to false in `begin()`, remove from `powerDown()` function. --- src/nrf_to_nrf.cpp | 22 +++++++++++++--------- src/nrf_to_nrf.h | 8 +++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/nrf_to_nrf.cpp b/src/nrf_to_nrf.cpp index 22ac7f6..e88748a 100644 --- a/src/nrf_to_nrf.cpp +++ b/src/nrf_to_nrf.cpp @@ -70,7 +70,6 @@ nrf_to_nrf::nrf_to_nrf() ackPayloadsEnabled = false; ackPipe = 0; inRxMode = false; - radioConfigured = false; ARC = 0; addressWidth = 5; ackTimeout = ACK_TIMEOUT_1MBPS; @@ -98,10 +97,6 @@ nrf_to_nrf::nrf_to_nrf() bool nrf_to_nrf::begin() { - if (radioConfigured) { - return 1; - } - NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; NRF_CLOCK->TASKS_HFCLKSTART = 1; @@ -149,7 +144,7 @@ bool nrf_to_nrf::begin() NRF_RADIO->SHORTS = 1 << 19; NRF_RADIO->FREQUENCY = 0x4C; - radioConfigured = true; + DPL = false; return 1; } @@ -1198,17 +1193,26 @@ bool nrf_to_nrf::testRPD(uint8_t RSSI) /**********************************************************************************************************/ +uint8_t nrf_to_nrf::getRSSI() +{ + NRF_RADIO->EVENTS_RSSIEND = 0; + NRF_RADIO->TASKS_RSSISTART = 1; + while (!NRF_RADIO->EVENTS_RSSIEND) { + } + return (uint8_t)NRF_RADIO->RSSISAMPLE; +} + +/**********************************************************************************************************/ + void nrf_to_nrf::powerUp() { - radioConfigured = false; - begin(); + NRF_RADIO->POWER = 1; } /**********************************************************************************************************/ void nrf_to_nrf::powerDown() { - DPL = false; NRF_RADIO->POWER = 0; } diff --git a/src/nrf_to_nrf.h b/src/nrf_to_nrf.h index f6c1b9f..c4bd75d 100644 --- a/src/nrf_to_nrf.h +++ b/src/nrf_to_nrf.h @@ -395,6 +395,13 @@ class nrf_to_nrf */ bool testRPD(uint8_t RSSI = 65); + /** + * A new function specific to the NRF52x devices, not available on NRF24 + * @return The function will return the RSSI, which is measured continuously and the value + * filtered using a single-pole IIR filter. This is a negative value: received signal strength = -A dBm + */ + uint8_t getRSSI(); + /** * Same as NRF24 */ @@ -488,7 +495,6 @@ class nrf_to_nrf uint32_t rxPrefix; uint32_t txBase; uint32_t txPrefix; - bool radioConfigured; bool ackPayloadAvailable; uint8_t ackAvailablePipeNo; uint8_t lastPacketCounter;