Close ANT HRM channel and save to SDcard ?

Dear Members,

How can I stop ANT HRM channel temporarily, and save the heart rate value on to SDcard ?

My code at static void page0_data_log(ant_hrm_page0_data_t const * p_page_data),

err_code = sd_ant_channel_close(HRM_CHANNEL_NUM);
APP_ERROR_CHECK(err_code);
        
        log_hrm(p_page_data->computed_heart_rate); //log HRM value 8Dec21 Rixtronix LAB
        //open the channel
        err_code=sd_ant_channel_open(HRM_CHANNEL_NUM);
        APP_ERROR_CHECK(err_code);

Please revise me ?

Thanks

Parents
  • After issuing the sd_ant_channel_close() you need to wait for the event that indicate the channel is closed (this may take some time, since it depends for instance on the channel period).

    Kenneth

  • the event that indicate the channel is closed ,which event ? thanks...

    code :

     
    		err_code = sd_ant_channel_close(HRM_CHANNEL_NUM);
         APP_ERROR_CHECK(err_code);
    		
    		 if (err_code==NRF_SUCCESS )
    			 {
    				 
    		      err_code = sd_ant_channel_unassign(HRM_CHANNEL_NUM); 
    				 NRF_LOG_INFO("WRITE HRM TO SDcard Page 0...\r\n");
    		
    				 
    			 }

    Please correct me the sequence and where should I put that sequence of closing the channel, write to SDcard and reopen again ?

    Thanks

  • Ok, I will try build and use DEBUG, anyway,

    I never got these breakpoints  :

    When it's connected on ANT HRM, it keeps running never stop on that breakpoint ?

    Any ideas ?

    Thanks

  • Hi Kenneth,

    When I put DEBUG,

    I got this :



                                                                                 

    nfo> app: Err_code libuarte_init libuarte1 0
                                     

    rror> app: SOFTDEVICE: ASSERTION FAILED

    What's the cause of "SOFTDEVICE: ASSERTION FAILED" ?

    How can we trace it ?

    Thanks
              

  • there are two ant_evt_handler I can see,
    one in main.c and the other one is in ant_state_indicator

    in main :
    static void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
    {
    switch (p_ant_evt->event)
    {
    case EVENT_RX_FAIL_GO_TO_SEARCH:
    /* Reset speed and cadence values */
    memset(&m_speed_calc_data, 0, sizeof(m_speed_calc_data));
    memset(&m_cadence_calc_data, 0, sizeof(m_cadence_calc_data));
    break;

    default:
    // No implementation needed
    break;
    }
    }


    in ant_state_indicator.c
    static void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
    {
    ret_code_t err_code = NRF_SUCCESS;

    if (m_channel != p_ant_evt->channel)
    {
    return;
    }

    switch (m_channel_type)
    {
    case CHANNEL_TYPE_SLAVE:
    /* fall through */
    case CHANNEL_TYPE_SLAVE_RX_ONLY:
    switch (p_ant_evt->event)
    {
    case EVENT_RX:
    NRF_LOG_INFO("EVENT_RX...\r\n");
    err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);

    nrf_pwr_mgmt_feed(); //Function for indicating activity.
    break;

    case EVENT_RX_FAIL:
    NRF_LOG_INFO("EVENT_RX_FAIL...\r\n");
    NRF_LOG_INFO("RIXTRONIX EVENT_RX_FAIL...\r\n");
    err_code = bsp_indication_set(BSP_INDICATE_RCV_ERROR);

    break;

    case EVENT_RX_FAIL_GO_TO_SEARCH:
    NRF_LOG_INFO("EVENT_RX_FAIL_GO_TO_SEARCH...\r\n");
    NRF_LOG_INFO("RIXTRONIX EVENT_RX_FAIL_GO_TO_SEARCH...\r\n");
    err_code = bsp_indication_set(BSP_INDICATE_SCANNING);
    break;

    case EVENT_CHANNEL_CLOSED:
    NRF_LOG_INFO("EVENT_CHANNEL_CLOSED...\r\n");
    nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF); //default
    //nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_CONTINUE);
    nrf_pwr_mgmt_feed(); //Function for indicating activity.


    break;

    case EVENT_RX_SEARCH_TIMEOUT:
    //Rixtronix LAB
    //8 Sept 2021,
    //on search timeout, and idle, make device on if there is a signal from sensor ?
    NRF_LOG_INFO("EVENT_RX_SEARCH_TIMEOUT...\r\n");
    err_code = bsp_indication_set(BSP_INDICATE_IDLE);//default
    //err_code = bsp_indication_set(BSP_INDICATE_SCANNING);
    nrf_pwr_mgmt_feed(); //Function for indicating activity. default

    break;
    }
    break;
    }
    APP_ERROR_CHECK(err_code);
    }


    in softdevice_setup function at main/**@brief BLE + ANT stack initialization.
    *
    * @details Initializes the SoftDevice and the stack event interrupt.
    */
    static void softdevice_setup(void)
    {
    ret_code_t err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("softdevice_setup\r\n");
    ASSERT(nrf_sdh_is_enabled());

    #ifdef BLE_STACK_SUPPORT_REQD
    ble_stack_init();
    #endif

    err_code = nrf_sdh_ant_enable();
    APP_ERROR_CHECK(err_code);

    // Register a handler for ANT events.
    NRF_SDH_ANT_OBSERVER(m_ant_observer, APP_ANT_OBSERVER_PRIO, ant_evt_handler, NULL);


    }

    ant_evt_handler the one in main.c is being used,

    does this naming ant_evt_handler cause the crash ?

    Thanks

  • I got this error

    <error> app: ERROR 0 [NRF_SUCCESS] at ..\..\..\..\..\..\..\..\components\librari

    \libuarte\nrf_libuarte_async.c:230
                                               

     at: 0x000462F7

    on main loop

    at GPS_process function

  • Can it be a conflict between libuarte1 interrupt with ANT interrupt ?
    Libuarte1 config : 
    NRF_LIBUARTE_ASYNC_DEFINE(libuarte1, 1, 3, 2, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3); //timer0 id =3, rtc1 id =2 //originally Rixtronix LAB 14 Dec 21
    
    at main()
    nrf_libuarte_async_config_t nrf_libuarte_async_config1 = {
                .tx_pin     = SER_APP_TX_PIN,
                .rx_pin     = SER_APP_RX_PIN,
                .baudrate   = NRF_UARTE_BAUDRATE_9600, //originally 28 Sept 2021
    					  //.baudrate   = NRF_UARTE_BAUDRATE_38400,
                .parity     = NRF_UARTE_PARITY_EXCLUDED,
                .hwfc       = NRF_UARTE_HWFC_DISABLED,
                .timeout_us = 1000,
                .int_prio   = APP_IRQ_PRIORITY_LOW
    			      
        };
    		err_code=nrf_libuarte_async_init(&libuarte1, &nrf_libuarte_async_config1, uart_event_handler1, (void *)&libuarte1);
    			APP_ERROR_CHECK(err_code);
    		NRF_LOG_INFO("Err_code libuarte_init libuarte1 %u",err_code);
    		
    		nrf_libuarte_async_enable(&libuarte1); //disable for debugging 13 Oct 2021
    
        GPS_Init();		
    
    Can it be a conflict between libuarte1 interrupt with ANT interrupt ?

Reply
  • Can it be a conflict between libuarte1 interrupt with ANT interrupt ?
    Libuarte1 config : 
    NRF_LIBUARTE_ASYNC_DEFINE(libuarte1, 1, 3, 2, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3); //timer0 id =3, rtc1 id =2 //originally Rixtronix LAB 14 Dec 21
    
    at main()
    nrf_libuarte_async_config_t nrf_libuarte_async_config1 = {
                .tx_pin     = SER_APP_TX_PIN,
                .rx_pin     = SER_APP_RX_PIN,
                .baudrate   = NRF_UARTE_BAUDRATE_9600, //originally 28 Sept 2021
    					  //.baudrate   = NRF_UARTE_BAUDRATE_38400,
                .parity     = NRF_UARTE_PARITY_EXCLUDED,
                .hwfc       = NRF_UARTE_HWFC_DISABLED,
                .timeout_us = 1000,
                .int_prio   = APP_IRQ_PRIORITY_LOW
    			      
        };
    		err_code=nrf_libuarte_async_init(&libuarte1, &nrf_libuarte_async_config1, uart_event_handler1, (void *)&libuarte1);
    			APP_ERROR_CHECK(err_code);
    		NRF_LOG_INFO("Err_code libuarte_init libuarte1 %u",err_code);
    		
    		nrf_libuarte_async_enable(&libuarte1); //disable for debugging 13 Oct 2021
    
        GPS_Init();		
    
    Can it be a conflict between libuarte1 interrupt with ANT interrupt ?

Children
  • RixtronixLAB said:
    Can it be a conflict between libuarte1 interrupt with ANT interrupt ?

    Maybe, you can check the softdevice specification, the system on chip resource requirements to see which hardware perihpheral the softdevice is using and compare with the ones you are trying to use from the application:
    https://www.thisisant.com/developer/components/nrf52832/#tab_tech_resources_tab 

  • I see this :

    ANT interrupt latency.pdf

    It crashed between ANT radio interrupt and GPS UART interrupt,

    do you have an idea on how to debug it ? So I can give a good interrupt timing between these two devices ? thanks

  • Hi Kenneth,

    I'm not using ANT HRM at all, only GPS,

    I got this :

    <error> app: ERROR 0 [NRF_SUCCESS] at ..\..\..\..\..\..\..\..\components\librari

    \libuarte\nrf_libuarte_async.c:230
                                               

     at: 0x00049733

    How do you reckon rectifying it ?

    is my process too long ? It's 600 lines GPS processing, and it's called on the main();

    my callback on event :

    case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
    				
    				   GPS_CallBack(); //originally on 1 Dec 21 Rixtronix LAB
    				
    				   //Rixtronix LAB 7 December 2021 
    				
                break;
                
                call back function : 
    GPS.LastTime=nrf_systick_val_get(); //originally
    	 
    	//DEBUG
    	
    	if(GPS.rxIndex < sizeof(GPS.rxBuffer)-2)
    	{
    		GPS.rxBuffer[GPS.rxIndex] = GPS.rxTmp; //originally
    		 
    		GPS.rxIndex++;
    		memcpy((uint8_t *)line_buffer_GPS,(uint8_t *)GPS.rxBuffer, GPS.rxIndex); //experiment with uint8_t *
    			
    	}
       nrf_libuarte_async_rx_free(&libuarte1, (uint8_t *)&GPS.rxTmp, 1); //originally        

    uint8_t        rxBuffer[255]; ----> should I increase or decrease ?

    GPS baudrate = 38400, I made to 115200, straight away error...

    Any clues ?

    Thanks

Related