This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ANT HRS demo using UART RX

Hi,

I add UART support using IRQ on the "ant_hrm_tx" example code.

and I'm sending packet of 4 bytes that contains: Delimiter,HeartRate,Battery,Delimiter

the frame is very basic and send every 1000ms from another MCU.

the problem is that I can see the "printf messages" (on the demo) but Ican't received any message (breakpoint inside the IRQ handler)

here's our IRQ handler, based on uart example code:

the basic concept is to extract the HeartRate from the frame and to send it using the hr.

/**@brief UART0 IRQ handler */

void UART0_IRQHandler(void)

{
if (NRF_UART0->EVENTS_RXDRDY == 1) {
data_array[index++] = (uint8_t)NRF_UART0->RXD;

 NRF_UART0->EVENTS_RXDRDY = 0;    

 if (data_array[0] != 0xFE)    //find sync     

   index = 0;        

 if (index == 4)      
{         
    index = 0;          

    if (data_array[3] == 0xFE)          
   {                
       heart_rate = (uint16_t)data_array[1];                

       data_array[0]=0;

       data_array[3]=0; 
   }      
}    

} }

/**@brief UART configure */

void uart_config(uint8_t txd_pin_number,uint8_t rxd_pin_number) { nrf_gpio_cfg_output(txd_pin_number);

nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_NOPULL); NRF_UART0->PSELTXD = txd_pin_number;

NRF_UART0->PSELRXD = rxd_pin_number;

NRF_UART0->BAUDRATE = (UART_BAUDRATE_BAUDRATE_Baud9600 << UART_BAUDRATE_BAUDRATE_Pos); NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos); NRF_UART0->TASKS_STARTTX = 0; NRF_UART0->TASKS_STARTRX = 1; //RX only NRF_UART0->EVENTS_RXDRDY = 0; }

/**@brief UART init: pinout, speed and IRQ */

static void uart_init(void) {
uart_config(TX_PIN_NUMBER, RX_PIN_NUMBER);
NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;

NVIC_SetPriority(UART0_IRQn, APP_IRQ_PRIORITY_HIGH); NVIC_EnableIRQ(UART0_IRQn);

}

I really need you help here, did I missed something with the registers? IRQ mask? how can we integrate UART RX using ANT stack, also when nRF51422 is sleeping?

many thanks,

  • If you are using the ant_hrm_tx with no modification (UART0_IRQHandler() is already used in app_uart.c, where received data is filled to the m_rx_fifo buffer), then you can simply receive and for instance loopback bytes on the UART by adding the following 4 lines of code in hrm_tx.c:

    #include "app_uart.h"

    uint8_t uart_byte;

    if(app_uart_get(&uart_byte) != NRF_ERROR_NOT_FOUND)

    app_uart_put(uart_byte);

Related