From 82f111d249f86b8394582a19d4ad8095eabae294 Mon Sep 17 00:00:00 2001 From: bsongis Date: Sun, 3 Nov 2013 14:17:54 +0000 Subject: [PATCH] [Taranis] DSM2 now ok on the logic analyser. I cannot test with a module, as I don't have a module ready for... --- src/protocols/dsm2_arm.cpp | 29 +++++++++++++++------------ src/protocols/pulses_avr.cpp | 2 +- src/targets/taranis/pulses_driver.cpp | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/protocols/dsm2_arm.cpp b/src/protocols/dsm2_arm.cpp index e8e24a3a1..bcea759ef 100644 --- a/src/protocols/dsm2_arm.cpp +++ b/src/protocols/dsm2_arm.cpp @@ -59,20 +59,18 @@ uint8_t dsm2SerialBitCount; uint8_t dsm2Index = 0; void _send_1(uint8_t v) { - dsm2Value += v; + if (dsm2Index == 0) + v -= 2; + else + v += 2; - if (dsm2Index == 0) { - *(dsm2StreamPtr+1) = dsm2Value; - dsm2Index = 1; - } - else { - *dsm2StreamPtr = dsm2Value; - dsm2Index = 0; - dsm2StreamPtr += 2; - } + dsm2Value += v; + *dsm2StreamPtr++ = dsm2Value; + + dsm2Index = (dsm2Index+1) % 2; } -void sendByteDsm2(uint8_t b) //max 10changes 0 10 10 10 10 1 +void sendByteDsm2(uint8_t b) //max 10 changes 0 10 10 10 10 1 { bool lev = 0; uint8_t len = BITLEN_DSM2; //max val: 9*16 < 256 @@ -92,7 +90,7 @@ void sendByteDsm2(uint8_t b) //max 10changes 0 10 10 10 10 1 } void putDsm2Flush() { - // dsm2StreamPtr--; //remove last stopbits and + dsm2StreamPtr--; //remove last stopbits and *dsm2StreamPtr++ = 44010; // Past the 44000 of the ARR } #else @@ -139,11 +137,16 @@ void setupPulsesDSM2(unsigned int port) dsm2SerialBitCount = 0 ; #else dsm2Value = 0; - dsm2Index = 0; + dsm2Index = 1; #endif dsm2StreamPtr = dsm2Stream; +#if defined(PCBTARANIS) + dsm2Value = 100; + *dsm2StreamPtr++ = dsm2Value; +#endif + switch(s_current_protocol[port]) { case PROTO_DSM2_LP45: dsmDat[0] = 0x00; diff --git a/src/protocols/pulses_avr.cpp b/src/protocols/pulses_avr.cpp index 771cddd5b..1ed8d05fb 100644 --- a/src/protocols/pulses_avr.cpp +++ b/src/protocols/pulses_avr.cpp @@ -52,7 +52,7 @@ uint8_t s_pulses_paused = 0; uint16_t B3_comp_value; -#ifdef DSM2_SERIAL +#if defined(DSM2_SERIAL) inline void DSM2_EnableTXD(void) { UCSR0B |= (1 << TXEN0); // enable TX diff --git a/src/targets/taranis/pulses_driver.cpp b/src/targets/taranis/pulses_driver.cpp index c079a494a..50f5c2fcb 100644 --- a/src/targets/taranis/pulses_driver.cpp +++ b/src/targets/taranis/pulses_driver.cpp @@ -471,7 +471,7 @@ static void init_pa7_dsm2() #if defined(REV3) TIM8->CCER = TIM_CCER_CC1E | TIM_CCER_CC1P ; #else - TIM8->CCER = TIM_CCER_CC1NE ; + TIM8->CCER = TIM_CCER_CC1NE | TIM_CCER_CC1NP ; #endif TIM8->CR2 = TIM_CR2_OIS1 ; // O/P idle high TIM8->BDTR = TIM_BDTR_MOE ; // Enable outputs