Skip to content

Commit

Permalink
Allow reconfig of radio, add getRSSI()
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
TMRh20 committed Jul 3, 2024
1 parent 89ee96e commit 6bc57d6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -149,7 +144,7 @@ bool nrf_to_nrf::begin()
NRF_RADIO->SHORTS = 1 << 19;
NRF_RADIO->FREQUENCY = 0x4C;

radioConfigured = true;
DPL = false;
return 1;
}

Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 7 additions & 1 deletion src/nrf_to_nrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6bc57d6

Please sign in to comment.