Improving ADF7021 interface, fixing small bugs

This commit is contained in:
Andy CA6JAU 2017-02-07 13:24:03 -03:00
parent 83d1916b11
commit fc0d47af0a
6 changed files with 55 additions and 43 deletions

View file

@ -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

View file

@ -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

10
IO.cpp
View file

@ -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;

2
IO.h
View file

@ -77,7 +77,7 @@ public:
// Misc functions
void dlybit(void);
void delay_rx(void);
private:
bool m_started;
CBitRB m_rxBuffer;

View file

@ -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);
}

View file

@ -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()