From 549d3ad6537eb6af17d073890e4ba8f2ee65aefb Mon Sep 17 00:00:00 2001 From: Frankie Arzu <32604366+frankiearzu@users.noreply.github.com> Date: Mon, 18 Dec 2023 12:02:57 +0100 Subject: [PATCH] Fix for DSM-Auto Bind on Lemon-RX Gen2 (#918) * #916 Fix for Auto-Bind on Lemon-RX Gen2 Tested with multiple brands (Spektrum, OrangeRX, Lemon-Rx, Admiral). Even some old DSM 2 receivers. All work with "Auto" now. Just in case one needs a LONG bind sending period, when not using "Auto" works the same as before. * Use 1.8s for Bind Send Removed the short and long bind count logic. --- Multiprotocol/DSM_cyrf6936.ino | 57 +++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/Multiprotocol/DSM_cyrf6936.ino b/Multiprotocol/DSM_cyrf6936.ino index 0ff3fed..1f4ad22 100644 --- a/Multiprotocol/DSM_cyrf6936.ino +++ b/Multiprotocol/DSM_cyrf6936.ino @@ -18,16 +18,22 @@ #include "iface_cyrf6936.h" //#define DSM_DEBUG_FWD_PGM - +//#define DEBUG_BIND 1 //#define DSM_GR300 #define CLONE_BIT_MASK 0x20 #define DSM_BIND_CHANNEL 0x0d //13 This can be any odd channel -//During binding we will send BIND_COUNT/2 packets +//During binding we will send BIND_COUNT packets //One packet each 10msec -#define DSM_BIND_COUNT 300 +// +// Most RXs seems to work properly with a long BIND send count (3s): Spektrum, OrangeRX. +// Lemon-RX G2s seems to have a timeout waiting for the channel to get quiet after the +// first good BIND packet.. If using 3s (300), Lemon-RX will not transmit the BIND-Response packet. + +#define DSM_BIND_COUNT 180 // About 1.8s +#define DSM_BIND_COUNT_READ 600 // About 4.2s of waiting for Response enum { DSM_BIND_WRITE=0, @@ -292,11 +298,14 @@ uint16_t DSM_callback() return 10000; #if defined DSM_TELEMETRY case DSM_BIND_CHECK: - //64 SDR Mode is configured so only the 8 first values are needed - CYRF_ConfigDataCode((const uint8_t *)"\x98\x88\x1B\xE4\x30\x79\x03\x84"); + #if DEBUG_BIND + debugln("Bind Check"); + #endif + //64 SDR Mode is configured so only the 8 first values are needed + CYRF_ConfigDataCode((const uint8_t *)"\x98\x88\x1B\xE4\x30\x79\x03\x84"); CYRF_SetTxRxMode(RX_EN); //Receive mode CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x87); //Prepare to receive - bind_counter=2*DSM_BIND_COUNT; //Timeout of 4.2s if no packet received + bind_counter=DSM_BIND_COUNT_READ; //Timeout of 4.2s if no packet received phase++; // change from BIND_CHECK to BIND_READ return 2000; case DSM_BIND_READ: @@ -312,10 +321,12 @@ uint16_t DSM_callback() CYRF_ReadDataPacketLen(packet_in+1, 10); if(DSM_Check_RX_packet()) { - debug("Bind"); - for(uint8_t i=0;i<10;i++) - debug(" %02X",packet_in[i+1]); - debugln(""); + #if DEBUG_BIND + debug("Bind"); + for(uint8_t i=0;i<10;i++) + debug(" %02X",packet_in[i+1]); + debugln(""); + #endif packet_in[0]=0x80; packet_in[6]&=0x0F; // It looks like there is a flag 0x40 being added by some receivers if(packet_in[6]>12) packet_in[6]=12; @@ -340,6 +351,9 @@ uint16_t DSM_callback() } if( --bind_counter == 0 ) { // Exit if no answer has been received for some time + #if DEBUG_BIND + debugln("Bind Read TIMEOUT"); + #endif phase++; // DSM_CHANSEL return 7000 ; } @@ -539,19 +553,23 @@ void DSM_init() if(eeprom_read_byte((EE_ADDR)DSM_CLONE_EEPROM_OFFSET+4)==0xF0) { //read cloned ID from EEPROM - debugln("Using cloned ID"); uint16_t temp = DSM_CLONE_EEPROM_OFFSET; for(uint8_t i=0;i<4;i++) cyrfmfg_id[i] = eeprom_read_byte((EE_ADDR)temp++); - debug("Clone ID=") - for(uint8_t i=0;i<4;i++) - debug("%02x ", cyrfmfg_id[i]); - debugln(""); + #if DEBUG_BIND + debugln("Using cloned ID"); + debug("Clone ID=") + for(uint8_t i=0;i<4;i++) + debug("%02x ", cyrfmfg_id[i]); + debugln(""); + #endif } else { SUB_PROTO_INVALID; - debugln("No valid cloned ID"); + #if DEBUG_BIND + debugln("No valid cloned ID"); + #endif } } else @@ -609,10 +627,13 @@ void DSM_init() { DSM_initialize_bind_phase(); phase = DSM_BIND_WRITE; - bind_counter=DSM_BIND_COUNT; + bind_counter=DSM_BIND_COUNT; + #if DEBUG_BIND + debugln("Bind Started: write count=%d",bind_counter); + #endif } else - phase = DSM_CHANSEL;// + phase = DSM_CHANSEL; } #endif