From 3a4451684f7068f00529226c06a2e4a0bfc18f1f Mon Sep 17 00:00:00 2001 From: danilo Date: Tue, 28 Mar 2017 07:29:02 +0200 Subject: [PATCH] Working TX SLE tested with gcc4.9.3 Ubuntu 16.10 (did not work before change, every second TX was lost) tested also with gcc arm embedded q4 2016 on Ubuntu 16.10 (here original code worked as well) No test with Arduino & other architectures yet --- ADF7021.cpp | 27 ++++++++++++++++++++++++++- IO.cpp | 31 ++++++++++++++++++++++++++++--- IO.h | 1 + IOArduino.cpp | 17 +++++++++++++---- IOSTM.cpp | 13 +++++++++++-- 5 files changed, 79 insertions(+), 10 deletions(-) diff --git a/ADF7021.cpp b/ADF7021.cpp index 161e643..6e440c5 100644 --- a/ADF7021.cpp +++ b/ADF7021.cpp @@ -34,6 +34,31 @@ volatile uint32_t AD7021_control_word; uint32_t ADF7021_RX_REG0; uint32_t ADF7021_TX_REG0; +volatile bool sle_request = false; + +static void Send_AD7021_control_shift() +{ + int AD7021_counter; + + for(AD7021_counter = 31; AD7021_counter >= 0; AD7021_counter--) { + if(bitRead(AD7021_control_word, AD7021_counter) == HIGH) + io.SDATA_pin(HIGH); + else + io.SDATA_pin(LOW); + + io.dlybit(); + io.SCLK_pin(HIGH); + io.dlybit(); + io.SCLK_pin(LOW); + } +} + +static void Send_AD7021_control_nosle() +{ + Send_AD7021_control_shift(); + sle_request = true; +} + void Send_AD7021_control() { int AD7021_counter; @@ -391,7 +416,7 @@ void CIO::setTX() { // Send register 0 for TX operation AD7021_control_word = ADF7021_TX_REG0; - Send_AD7021_control(); + Send_AD7021_control_nosle(); #if defined(BIDIR_DATA_PIN) Data_dir_out(true); // Data pin output mode diff --git a/IO.cpp b/IO.cpp index 7037241..9524aec 100644 --- a/IO.cpp +++ b/IO.cpp @@ -29,6 +29,9 @@ uint32_t m_frequency_rx; uint32_t m_frequency_tx; uint8_t m_power; +extern volatile bool sle_request; +static volatile bool sle_pin = 0; + CIO::CIO(): m_started(false), m_rxBuffer(RX_RINGBUFFER_SIZE), @@ -152,7 +155,25 @@ void CIO::interrupt() if (!m_started) return; - if(m_tx) { + if (sle_request == true && m_tx) + { + if(CLK_pin() == 0) + { + sle_pin = 1; + SLE_pin(HIGH); + } + else if (sle_pin == 1) + { + SLE_pin(LOW); + SDATA_pin(LOW); + sle_request = false; + sle_pin = 0; + } + } + + + // we set the TX bit at TXD low, sampling of ADF7021 happens at rising clock + if (CLK_pin() == 0 && m_tx ) { m_txBuffer.get(bit); #if defined(BIDIR_DATA_PIN) @@ -166,8 +187,9 @@ void CIO::interrupt() else TXD_pin(LOW); #endif - - } else { + } + // we sample the RX bit at rising TXD clock edge, so TXD must be 1 and we are not in tx mode + else if (CLK_pin() == 1 && !m_tx) { if(RXD_pin()) bit = 1; else @@ -176,6 +198,7 @@ void CIO::interrupt() m_rxBuffer.put(bit); } + m_watchdog++; m_modeTimerCnt++; @@ -241,6 +264,8 @@ void CIO::write(uint8_t* data, uint16_t length) if (!m_tx) { setTX(); m_tx = true; + sle_pin = 0; + while (sle_request) { asm("nop"); } } } diff --git a/IO.h b/IO.h index 1f5ceb5..c635f0d 100644 --- a/IO.h +++ b/IO.h @@ -55,6 +55,7 @@ public: void SLE_pin(bool on); void CE_pin(bool on); bool RXD_pin(void); + bool CLK_pin(void); #if defined(BIDIR_DATA_PIN) void RXD_pin_write(bool on); diff --git a/IOArduino.cpp b/IOArduino.cpp index 8497def..c891bc5 100644 --- a/IOArduino.cpp +++ b/IOArduino.cpp @@ -171,17 +171,17 @@ void CIO::startInt() // TXD pin is TxRxCLK of ADF7021, standard TX/RX data interface #if defined (__STM32F1__) - attachInterrupt(PIN_TXD, EXT_IRQHandler, RISING); + attachInterrupt(PIN_TXD, EXT_IRQHandler, CHANGE); #else - attachInterrupt(digitalPinToInterrupt(PIN_TXD), EXT_IRQHandler, RISING); + attachInterrupt(digitalPinToInterrupt(PIN_TXD), EXT_IRQHandler, CHANGE); #endif #else #if defined (__STM32F1__) - attachInterrupt(PIN_CLKOUT, EXT_IRQHandler, RISING); + attachInterrupt(PIN_CLKOUT, EXT_IRQHandler, CHANGE); #else - attachInterrupt(digitalPinToInterrupt(PIN_CLKOUT), EXT_IRQHandler, RISING); + attachInterrupt(digitalPinToInterrupt(PIN_CLKOUT), EXT_IRQHandler, CHANGE); #endif #endif @@ -228,6 +228,11 @@ bool CIO::RXD_pin() return digitalRead(PIN_RXD) == HIGH; } +bool CIO::CLK_pin() +{ + return digitalRead(PIN_TXD) == HIGH; +} + #if defined(BIDIR_DATA_PIN) void CIO::RXD_pin_write(bool on) { @@ -237,7 +242,11 @@ void CIO::RXD_pin_write(bool on) void CIO::TXD_pin(bool on) { +#if defined(BIDIR_DATA_PIN) digitalWrite(PIN_TXD, on ? HIGH : LOW); +#else + digitalWrite(PIN_CLKOUT, on ? HIGH : LOW); +#endif } void CIO::LED_pin(bool on) diff --git a/IOSTM.cpp b/IOSTM.cpp index 2cbc3fc..b66fa76 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -440,7 +440,7 @@ void CIO::Init() #endif EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; - EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); } @@ -465,7 +465,7 @@ void CIO::startInt() #endif - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 15; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 15; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); @@ -519,6 +519,15 @@ bool CIO::RXD_pin() return GPIO_ReadInputDataBit(PORT_RXD, PIN_RXD) == Bit_SET; } +bool CIO::CLK_pin() +{ +#if defined(BIDIR_DATA_PIN) + return GPIO_ReadInputDataBit(PORT_TXD, PIN_TXD) == Bit_SET; +#else + return GPIO_ReadInputDataBit(PORT_CLKOUT, PIN_CLKOUT) == Bit_SET; +#endif +} + #if defined(BIDIR_DATA_PIN) void CIO::RXD_pin_write(bool on) {