Skip to content

Commit 32eaa7b

Browse files
martinbuddendigitalentity
authored andcommitted
Fix to syma nrf24l01 protocol (#565)
1 parent f262154 commit 32eaa7b

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

src/main/drivers/rx_nrf24l01.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ void NRF24L01_SetupBasic(void)
261261
NRF24L01_WriteReg(NRF24L01_01_EN_AA, 0x00); // No auto acknowledgment
262262
NRF24L01_WriteReg(NRF24L01_02_EN_RXADDR, BV(NRF24L01_02_EN_RXADDR_ERX_P0));
263263
NRF24L01_WriteReg(NRF24L01_03_SETUP_AW, NRF24L01_03_SETUP_AW_5BYTES); // 5-byte RX/TX address
264-
NRF24L01_WriteReg(NRF24L01_08_OBSERVE_TX, 0x00); // Don't count lost or retransmitted packets
265264
NRF24L01_WriteReg(NRF24L01_1C_DYNPD, 0x00); // Disable dynamic payload length on all pipes
266265
}
267266

@@ -326,17 +325,23 @@ bool NRF24L01_ReadPayloadIfAvailable(uint8_t *data, uint8_t length)
326325
}
327326

328327
#ifndef UNIT_TEST
328+
/*
329+
* Fast read of payload, for use in interrupt service routine
330+
*/
329331
bool NRF24L01_ReadPayloadIfAvailableFast(uint8_t *data, uint8_t length)
330332
{
331333
// number of bits transferred = 8 * (3 + length)
332334
// for 16 byte payload, that is 8*19 = 152
333335
// at 50MHz clock rate that is approximately 3 microseconds
334336
bool ret = false;
335337
ENABLE_NRF24();
336-
nrf24TransferByte(R_REGISTER | (REGISTER_MASK & NRF24L01_17_FIFO_STATUS));
337-
const uint8_t fifoStatus = nrf24TransferByte(NOP);
338-
if ((fifoStatus & BV(NRF24L01_17_FIFO_STATUS_RX_EMPTY)) == 0) {
338+
nrf24TransferByte(R_REGISTER | (REGISTER_MASK & NRF24L01_07_STATUS));
339+
const uint8_t status = nrf24TransferByte(NOP);
340+
if ((status & BV(NRF24L01_07_STATUS_RX_DR)) == 0) {
339341
ret = true;
342+
// clear RX_DR flag
343+
nrf24TransferByte(W_REGISTER | (REGISTER_MASK & NRF24L01_07_STATUS));
344+
nrf24TransferByte(BV(NRF24L01_07_STATUS_RX_DR));
340345
nrf24TransferByte(R_RX_PAYLOAD);
341346
for (uint8_t i = 0; i < length; i++) {
342347
data[i] = nrf24TransferByte(NOP);

src/main/io/serial_cli.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ const clivalue_t valueTable[] = {
707707
#ifdef USE_RX_NRF24
708708
{ "nrf24rx_protocol", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.nrf24rx_protocol, .config.lookup = { TABLE_NRF24_RX }, 0 },
709709
{ "nrf24rx_id", VAR_UINT32 | MASTER_VALUE, &masterConfig.rxConfig.nrf24rx_id, .config.minmax = { 0, 0 }, 0 },
710-
{ "nrf24rx_rf_channel_count", VAR_UINT8 | MASTER_VALUE | MODE_LOOKUP, &masterConfig.rxConfig.nrf24rx_rf_channel_count, .config.minmax = { 0, 8 }, 0 },
710+
{ "nrf24rx_rf_channel_count", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.nrf24rx_rf_channel_count, .config.minmax = { 0, 8 }, 0 },
711711
#endif
712712
#ifdef SPEKTRUM_BIND
713713
{ "spektrum_sat_bind", VAR_UINT8 | MASTER_VALUE, &masterConfig.rxConfig.spektrum_sat_bind, .config.minmax = { SPEKTRUM_SAT_BIND_DISABLED, SPEKTRUM_SAT_BIND_MAX}, 0 },

src/main/rx/nrf24_syma.c

+17-22
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#include <string.h>
2424

2525
#include <platform.h>
26-
#include "build/build_config.h"
27-
2826

2927
#ifdef USE_RX_SYMA
3028

29+
#include "build/build_config.h"
30+
3131
#include "drivers/rx_nrf24l01.h"
3232
#include "drivers/system.h"
3333

@@ -54,7 +54,7 @@
5454
* uses address received in bind packets
5555
* hops between 4 channels generated from address received in bind packets
5656
*
57-
* SymaX5 Protocol
57+
* SymaX5C Protocol
5858
* No auto acknowledgment
5959
* Payload size is 16, static
6060
* Data rate is 1Mbps
@@ -222,47 +222,42 @@ static void setSymaXHoppingChannels(uint32_t addr)
222222
}
223223
}
224224

225-
static void symaSetBound(const uint8_t* rxTxAddr)
226-
{
227-
protocolState = STATE_DATA;
228-
// using protocol NRF24L01_SYMA_X, since NRF24L01_SYMA_X5C went straight into data mode
229-
// set the hopping channels as determined by the rxTxAddr received in the bind packet
230-
setSymaXHoppingChannels(rxTxAddr[0]);
231-
timeOfLastHop = micros();
232-
packetCount = 0;
233-
// set the NRF24 to use the rxTxAddr received in the bind packet
234-
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, rxTxAddr, RX_TX_ADDR_LEN);
235-
symaRfChannelIndex = 0;
236-
NRF24L01_SetChannel(symaRfChannels[0]);
237-
}
238-
239225
/*
240226
* This is called periodically by the scheduler.
241227
* Returns NRF24_RECEIVED_DATA if a data packet was received.
242228
*/
243229
nrf24_received_t symaNrf24DataReceived(uint8_t *payload)
244230
{
245231
nrf24_received_t ret = NRF24_RECEIVED_NONE;
246-
uint32_t timeNowUs;
232+
247233
switch (protocolState) {
248234
case STATE_BIND:
249235
if (NRF24L01_ReadPayloadIfAvailable(payload, payloadSize)) {
250236
const bool bindPacket = symaCheckBindPacket(payload);
251237
if (bindPacket) {
252238
ret = NRF24_RECEIVED_BIND;
253-
symaSetBound(rxTxAddr);
239+
protocolState = STATE_DATA;
240+
// using protocol NRF24L01_SYMA_X, since NRF24L01_SYMA_X5C went straight into data mode
241+
// set the hopping channels as determined by the rxTxAddr received in the bind packet
242+
setSymaXHoppingChannels(rxTxAddr[0]);
243+
// set the NRF24 to use the rxTxAddr received in the bind packet
244+
NRF24L01_WriteRegisterMulti(NRF24L01_0A_RX_ADDR_P0, rxTxAddr, RX_TX_ADDR_LEN);
245+
packetCount = 0;
246+
symaRfChannelIndex = 0;
247+
NRF24L01_SetChannel(symaRfChannels[0]);
254248
}
255249
}
256250
break;
257251
case STATE_DATA:
258252
// read the payload, processing of payload is deferred
259253
if (NRF24L01_ReadPayloadIfAvailable(payload, payloadSize)) {
254+
symaHopToNextChannel();
255+
timeOfLastHop = micros();
260256
ret = NRF24_RECEIVED_DATA;
261257
}
262-
timeNowUs = micros();
263-
if ((ret == NRF24_RECEIVED_DATA) || (timeNowUs > timeOfLastHop + hopTimeout)) {
258+
if (micros() > timeOfLastHop + hopTimeout) {
264259
symaHopToNextChannel();
265-
timeOfLastHop = timeNowUs;
260+
timeOfLastHop = micros();
266261
}
267262
break;
268263
}

src/main/target/CJMCU/target.h

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#define USE_RX_INAV
7474
#define USE_RX_SYMA
7575
#define USE_RX_V202
76+
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_SYMA_X5
7677
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_SYMA_X5C
7778
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_INAV
7879
//#define NRF24_DEFAULT_PROTOCOL NRF24RX_H8_3D

0 commit comments

Comments
 (0)