From fc0d47af0a4ca499b4cc22728a058197409deaf0 Mon Sep 17 00:00:00 2001 From: Andy CA6JAU Date: Tue, 7 Feb 2017 13:24:03 -0300 Subject: [PATCH] Improving ADF7021 interface, fixing small bugs --- ADF7021.cpp | 51 ++++++++++++++++++++++----------------------------- ADF7021.h | 2 -- IO.cpp | 10 +++++----- IO.h | 2 +- IOArduino.cpp | 7 +++++-- IOSTM.cpp | 26 ++++++++++++++++++++++---- 6 files changed, 55 insertions(+), 43 deletions(-) diff --git a/ADF7021.cpp b/ADF7021.cpp index 67ad1ac..7ef2c8d 100644 --- a/ADF7021.cpp +++ b/ADF7021.cpp @@ -32,6 +32,9 @@ volatile uint32_t AD7021_control_byte; volatile int AD7021_counter; +uint32_t ADF7021_RX_REG0; +uint32_t ADF7021_TX_REG0; + void Send_AD7021_control() { for(AD7021_counter = 31; AD7021_counter >= 0; AD7021_counter--) { @@ -52,12 +55,16 @@ void Send_AD7021_control() io.SDATA_pin(LOW); } -void Send_REG0_RX() +void CIO::ifConf() { - uint32_t ADF7021_RX_REG0; - float divider; - uint8_t N_divider; + float divider; + uint8_t N_divider; uint16_t F_divider; + + uint32_t ADF7021_REG2 = 0; + uint32_t ADF7021_REG3 = 0; + uint32_t ADF7021_REG4 = 0; + uint32_t ADF7021_REG13 = 0; divider = (m_frequency_rx - 100000) / (ADF7021_PFD / 2.0); @@ -70,17 +77,6 @@ void Send_REG0_RX() ADF7021_RX_REG0 |= (uint32_t) N_divider << 19; // frequency; ADF7021_RX_REG0 |= (uint32_t) F_divider << 4; // frequency; - AD7021_control_byte = ADF7021_RX_REG0; - Send_AD7021_control(); -} - -void Send_REG0_TX() -{ - uint32_t ADF7021_TX_REG0; - float divider; - uint8_t N_divider; - uint16_t F_divider; - divider = m_frequency_tx / (ADF7021_PFD / 2.0); N_divider = floor(divider); @@ -92,17 +88,6 @@ void Send_REG0_TX() ADF7021_TX_REG0 |= (uint32_t) N_divider << 19; // frequency; ADF7021_TX_REG0 |= (uint32_t) F_divider << 4; // frequency; - AD7021_control_byte = ADF7021_TX_REG0; - Send_AD7021_control(); -} - -void CIO::ifConf() -{ - uint32_t ADF7021_REG2 = 0; - uint32_t ADF7021_REG3 = 0; - uint32_t ADF7021_REG4 = 0; - uint32_t ADF7021_REG13 = 0; - if (m_dstarEnable) { // Dev: 1200 Hz, symb rate = 4800 @@ -207,6 +192,9 @@ void CIO::ifConf() // IF FILTER (5) AD7021_control_byte = ADF7021_REG5; Send_AD7021_control(); + + // Frequency RX (0) + setRX(); // MODULATION (2) ADF7021_REG2 |= (uint32_t) 0b0010; // register 2 @@ -247,18 +235,23 @@ void CIO::ifConf() //====================================================================================================================== void CIO::setTX() { + AD7021_control_byte = ADF7021_TX_REG0; + Send_AD7021_control(); + PTT_pin(HIGH); LED_pin(LOW); - Send_REG0_TX(); } //====================================================================================================================== void CIO::setRX() { + delay_rx(); + + AD7021_control_byte = ADF7021_RX_REG0; + Send_AD7021_control(); + PTT_pin(LOW); LED_pin(HIGH); - delay_rx(); - Send_REG0_RX(); } #endif diff --git a/ADF7021.h b/ADF7021.h index a67c4d6..16227f6 100644 --- a/ADF7021.h +++ b/ADF7021.h @@ -189,8 +189,6 @@ www.analog.com/media/en/technical-documentation/data-sheets/ADF7021.pdf #define bitRead(value, bit) (((value) >> (bit)) & 0x01) void Send_AD7021_control(void); -void Send_REG0_RX(void); -void Send_REG0_TX(void); #endif diff --git a/IO.cpp b/IO.cpp index 9032e73..d4676dc 100644 --- a/IO.cpp +++ b/IO.cpp @@ -57,8 +57,10 @@ void CIO::process() // Switch off the transmitter if needed if (m_txBuffer.getData() == 0U && m_tx) { - m_tx = false; + DEB_pin(LOW); setRX(); + m_tx = false; + DEB_pin(LOW); } if (m_rxBuffer.getData() >= 1U) { @@ -83,6 +85,8 @@ void CIO::interrupt() return; if(m_tx) { + DEB_pin(HIGH); + m_txBuffer.get(bit); if(bit) @@ -98,7 +102,6 @@ void CIO::interrupt() m_rxBuffer.put(bit); } - } void CIO::start() @@ -108,9 +111,6 @@ void CIO::start() if (m_started) return; - delay_rx(); - setRX(); - startInt(); m_started = true; diff --git a/IO.h b/IO.h index c8fdd8c..04c63a0 100644 --- a/IO.h +++ b/IO.h @@ -77,7 +77,7 @@ public: // Misc functions void dlybit(void); void delay_rx(void); - + private: bool m_started; CBitRB m_rxBuffer; diff --git a/IOArduino.cpp b/IOArduino.cpp index 381a467..eacc6ae 100644 --- a/IOArduino.cpp +++ b/IOArduino.cpp @@ -70,12 +70,15 @@ extern "C" { } void CIO::delay_rx() { - delayMicroseconds(1); +#if defined (__STM32F1__) + delayMicroseconds(290); +#else + delayMicroseconds(150); +#endif } void CIO::dlybit(void) { - volatile unsigned int delay; delayMicroseconds(1); } diff --git a/IOSTM.cpp b/IOSTM.cpp index e6e95c5..11c43f6 100644 --- a/IOSTM.cpp +++ b/IOSTM.cpp @@ -80,15 +80,33 @@ extern "C" { } } +/** + * Function delay_us() from stm32duino project + * + * @brief Delay the given number of microseconds. + * + * @param us Number of microseconds to delay. + */ +static inline void delay_us(uint32_t us) { + us *= 12; + + /* fudge for function call overhead */ + us--; + asm volatile(" mov r0, %[us] \n\t" + "1: subs r0, #1 \n\t" + " bhi 1b \n\t" + : + : [us] "r" (us) + : "r0"); +} + void CIO::delay_rx() { - volatile unsigned int delay; - for(delay = 0;delay<512;delay++); + delay_us(340); } void CIO::dlybit(void) { - volatile unsigned int delay; - for(delay = 0;delay<5;delay++); + delay_us(1); } void CIO::Init()