From 978548e74975647981ac4317e8144e2f57dbbc5f Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Mon, 11 Mar 2024 02:38:21 +0100 Subject: [PATCH 1/2] Do not set LFCLKSRC as it will hang if no external crystal is present --- src/nrf_to_nrf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nrf_to_nrf.cpp b/src/nrf_to_nrf.cpp index d9ce0b3..d074625 100644 --- a/src/nrf_to_nrf.cpp +++ b/src/nrf_to_nrf.cpp @@ -90,10 +90,10 @@ bool nrf_to_nrf::begin() // Do nothing. } - NRF_CLOCK->LFCLKSRC = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos); NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; NRF_CLOCK->TASKS_LFCLKSTART = 1; + /* Wait for the low frequency clock to start up */ while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0) { // Do nothing. } From 95126e2b9e7ecc2bdc5341ad15bb1f59f68c8bfa Mon Sep 17 00:00:00 2001 From: Tobias Gunkel Date: Mon, 11 Mar 2024 02:36:24 +0100 Subject: [PATCH 2/2] Add support for 250kbps mode --- src/nrf_to_nrf.cpp | 20 ++++++++++++++++---- src/nrf_to_nrf.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/nrf_to_nrf.cpp b/src/nrf_to_nrf.cpp index d9ce0b3..a2767d6 100644 --- a/src/nrf_to_nrf.cpp +++ b/src/nrf_to_nrf.cpp @@ -2,6 +2,12 @@ #include "nrf_to_nrf.h" +// Note that 250Kbit mode is deprecated and might not work reliably on all devices. +// See: https://devzone.nordicsemi.com/f/nordic-q-a/78469/250-kbit-s-nordic-proprietary-radio-mode-on-nrf52840 +#ifndef RADIO_MODE_MODE_Nrf_250Kbit +#define RADIO_MODE_MODE_Nrf_250Kbit (2UL) +#endif + /**********************************************************************************************************/ // Function to do bytewise bit-swap on an unsigned 32-bit value @@ -448,8 +454,9 @@ bool nrf_to_nrf::write(void* buf, uint8_t len, bool multicast, bool doEncryption if (!DPL) { if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) { realAckTimeout -= ACK_TIMEOUT_1MBPS_OFFSET; - } - else { + } else if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_250Kbit << RADIO_MODE_MODE_Pos)) { + realAckTimeout -= ACK_TIMEOUT_250KBPS_OFFSET; + } else { realAckTimeout -= ACK_TIMEOUT_2MBPS_OFFSET; } }else{ @@ -1032,14 +1039,19 @@ bool nrf_to_nrf::isChipConnected() { return isValid(); } bool nrf_to_nrf::setDataRate(uint8_t speed) { - if (!speed) { + if (speed == NRF_1MBPS) { NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos); ackTimeout = ACK_TIMEOUT_1MBPS; } - else { + else if (speed == NRF_250KBPS) { + NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_250Kbit << RADIO_MODE_MODE_Pos); + ackTimeout = ACK_TIMEOUT_250KBPS; + } + else { // NRF_2MBPS NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos); ackTimeout = ACK_TIMEOUT_2MBPS; } + return 1; } diff --git a/src/nrf_to_nrf.h b/src/nrf_to_nrf.h index ab00abe..1edcffa 100644 --- a/src/nrf_to_nrf.h +++ b/src/nrf_to_nrf.h @@ -17,8 +17,10 @@ #define ACTUAL_MAX_PAYLOAD_SIZE 127 #define ACK_TIMEOUT_1MBPS 500 // 200 with static payloads #define ACK_TIMEOUT_2MBPS 300 // 165 with static payloads +#define ACK_TIMEOUT_250KBPS 500 #define ACK_TIMEOUT_1MBPS_OFFSET 300 #define ACK_TIMEOUT_2MBPS_OFFSET 135 +#define ACK_TIMEOUT_250KBPS_OFFSET 300 #define ACK_PAYLOAD_TIMEOUT_OFFSET 750 // AES CCM ENCRYPTION