Skip to content

Commit 987753f

Browse files
author
Pascal Langer
committed
DSM and DSM RX: fix bind
1 parent ee08083 commit 987753f

5 files changed

Lines changed: 44 additions & 24 deletions

File tree

Multiprotocol/DSM.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const uint8_t PROGMEM DSM_init_vals[][2] = {
7777
{CYRF_28_CLK_EN, 0x02}, // Force receive clock enable
7878
{CYRF_32_AUTO_CAL_TIME, 0x3c}, // Default init value
7979
{CYRF_35_AUTOCAL_OFFSET, 0x14}, // Default init value
80+
{CYRF_26_XTAL_CFG, 0x08}, // Start delay
8081
{CYRF_06_RX_CFG, 0x4A}, // LNA enabled, RX override enabled, Fast turn mode enabled, RX is 1MHz below TX
8182
{CYRF_1B_TX_OFFSET_LSB, 0x55}, // Default init value
8283
{CYRF_1C_TX_OFFSET_MSB, 0x05}, // Default init value

Multiprotocol/DSM_Rx_cyrf6936.ino

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -199,23 +199,25 @@ static void __attribute__((unused)) DSM_abort_channel_rx(uint8_t ch)
199199
uint16_t DSM_Rx_callback()
200200
{
201201
uint8_t rx_status;
202-
static uint8_t read_retry=10;
202+
static uint8_t read_retry=0;
203203
static uint16_t pps_counter;
204204
static uint32_t pps_timer = 0;
205205

206206
switch (phase)
207207
{
208208
case DSM_RX_BIND1:
209+
if(packet_count==0)
210+
read_retry=0;
209211
//Check received data
210212
rx_status = CYRF_ReadRegister(CYRF_07_RX_IRQ_STATUS);
211213
if((rx_status & 0x03) == 0x02) // RXC=1, RXE=0 then 2nd check is required (debouncing)
212214
rx_status |= CYRF_ReadRegister(CYRF_07_RX_IRQ_STATUS);
213-
if((rx_status & 0x07) == 0x02 && read_retry)
215+
if((rx_status & 0x07) == 0x02)
214216
{ // data received with no errors
215217
CYRF_WriteRegister(CYRF_07_RX_IRQ_STATUS, 0x80); // Need to set RXOW before data read
216-
rx_status=CYRF_ReadRegister(CYRF_09_RX_COUNT);
217-
debugln("RX:%d",rx_status);
218-
if(rx_status==16)
218+
len=CYRF_ReadRegister(CYRF_09_RX_COUNT);
219+
debugln("RX:%d, CH:%d",len,hopping_frequency_no);
220+
if(len==16)
219221
{
220222
CYRF_ReadDataPacketLen(packet_in, 16);
221223
if(DSM_Rx_bind_check_validity())
@@ -263,29 +265,41 @@ uint16_t DSM_Rx_callback()
263265
debugln(", num_ch=%d, type=%02X",num_ch, DSM_rx_type);
264266
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation
265267
CYRF_SetTxRxMode(TX_EN); // Force end state TX
268+
CYRF_ConfigDataCode((const uint8_t *)"\x98\x88\x1B\xE4\x30\x79\x03\x84", 16);
266269
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x00); // Clear abort RX
267270
DSM_Rx_build_bind_packet();
268271
bind_counter=500;
269272
phase++; // DSM_RX_BIND2;
273+
return 1000;
270274
}
271275
}
272-
if(read_retry)
273-
read_retry--;
276+
DSM_abort_channel_rx(0); // Abort RX operation and receive
277+
if(read_retry==0)
278+
read_retry=4;
274279
}
275280
else
281+
if(rx_status & 0x02) // RX error
282+
DSM_abort_channel_rx(0); // Abort RX operation and receive
283+
packet_count++;
284+
if(packet_count>12)
276285
{
277-
hopping_frequency_no++; // Change channel
278-
hopping_frequency_no %= 0x50;
279-
hopping_frequency_no |= 0x01; // Odd channels only
280-
CYRF_ConfigRFChannel(hopping_frequency_no);
281-
//debugln("ch:%d",hopping_frequency_no);
282-
read_retry = 10;
283-
DSM_abort_channel_rx(0); // Abort RX operation and receive
286+
packet_count=1;
287+
if(read_retry)
288+
read_retry--;
289+
if(read_retry==0)
290+
{
291+
packet_count=0;
292+
hopping_frequency_no++; // Change channel
293+
hopping_frequency_no %= 0x50;
294+
hopping_frequency_no |= 0x01; // Odd channels only
295+
CYRF_ConfigRFChannel(hopping_frequency_no);
296+
DSM_abort_channel_rx(0); // Abort RX operation and receive
297+
}
284298
}
285-
return 12500;
299+
return 1000;
286300
case DSM_RX_BIND2:
287301
//Transmit settings back
288-
CYRF_WriteDataPacketLen(packet,10); // Does not work ?!?!?
302+
CYRF_WriteDataPacketLen(packet,10); // Send packet
289303
if(bind_counter--==0)
290304
{
291305
BIND_DONE;
@@ -296,7 +310,6 @@ uint16_t DSM_Rx_callback()
296310
hopping_frequency_no = 0;
297311
read_retry=0;
298312
rx_data_started = false;
299-
read_retry=0;
300313
pps_counter = 0;
301314
RX_LQI = 100;
302315
DSM_cyrf_configdata();
@@ -457,7 +470,10 @@ uint16_t initDSM_Rx()
457470
hopping_frequency_no = 0;
458471

459472
if (IS_BIND_IN_PROGRESS)
473+
{
474+
packet_count=0;
460475
phase = DSM_RX_BIND1;
476+
}
461477
else
462478
{
463479
uint16_t temp = DSM_RX_EEPROM_OFFSET;
@@ -471,7 +487,7 @@ uint16_t initDSM_Rx()
471487
debugln(", type=%02X", DSM_rx_type);
472488
phase = DSM_RX_DATA_PREP;
473489
}
474-
return 1000;
490+
return 15000;
475491
}
476492

477493
#endif

Multiprotocol/DSM_cyrf6936.ino

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ uint16_t ReadDsm()
230230
#if defined DSM_TELEMETRY
231231
case DSM_BIND_CHECK:
232232
//64 SDR Mode is configured so only the 8 first values are needed but we need to write 16 values...
233-
CYRF_ConfigDataCode((const uint8_t *)"\x98\x88\x1B\xE4\x30\x79\x03\x84\xC9\x2C\x06\x93\x86\xB9\x9E\xD7", 16);
233+
CYRF_ConfigDataCode((const uint8_t *)"\x98\x88\x1B\xE4\x30\x79\x03\x84", 16);
234234
CYRF_SetTxRxMode(RX_EN); //Receive mode
235235
CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x87); //Prepare to receive
236236
bind_counter=2*DSM_BIND_COUNT; //Timeout of 4.2s if no packet received
@@ -255,6 +255,10 @@ uint16_t ReadDsm()
255255
return 2000;
256256
}
257257
}
258+
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x20); // Abort RX operation
259+
CYRF_SetTxRxMode(RX_EN); // Force end state read
260+
CYRF_WriteRegister(CYRF_29_RX_ABORT, 0x00); // Clear abort RX operation
261+
CYRF_WriteRegister(CYRF_05_RX_CTRL, 0x83); // Prepare to receive
258262
}
259263
else
260264
if((rx_phase & 0x02) != 0x02)

Multiprotocol/Multiprotocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define VERSION_MAJOR 1
2020
#define VERSION_MINOR 3
2121
#define VERSION_REVISION 0
22-
#define VERSION_PATCH_LEVEL 98
22+
#define VERSION_PATCH_LEVEL 99
2323

2424
//******************
2525
// Protocols

Protocols_Details.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,9 @@ Also on er9x you will need to be sure to match the polarity of the telemetry ser
674674
The DSM receiver protocol enables master/slave trainning, separate access from 2 different radios to the same model,...
675675

676676
Notes:
677-
- Automatically support DSM 2/X 11/22 1024/2048
678-
- Currently the bind response does not work which means that the TX doesn't know what the DSM RX protocol has selected. **You must manually select the right protocol on the TX**. By default the RX will select DSMX/11ms.
679-
- Available in OpenTX 2.3.3, Trainer Mode Master/Multi
680-
- Channels 1..4 are remapped to the module default
677+
- Automatically detect DSM 2/X 11/22ms 1024/2048res
678+
- Available in OpenTX 2.3.3+, Trainer Mode Master/Multi
679+
- Channels 1..4 are remapped to the module default channel order unless on OpenTX 2.3.3+ you use the "Disable channel mapping" feature on the GUI.
681680
- Extended limits supported
682681

683682
CH1|CH2|CH3|CH4|CH5|CH6|CH7|CH8|CH9|CH10|CH11|CH12

0 commit comments

Comments
 (0)