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

  • You should receive an EVENT_CHANNEL_CLOSED event in your event handler. The easiest way to find the name of the event handler may be to search the project for NRF_SDH_ANT_OBSERVER(). It may look something like this (example taken from ant_hrm_tx):

    You may also add your own NRF_SDH_ANT_OBSERVER() if you like.

    Kenneth

  • Hi Kenneth,

    I've found that function at ant_state_indicator.c

    on this case :

      case EVENT_CHANNEL_CLOSED:
                        NRF_LOG_INFO("EVENT_CHANNEL_CLOSED...\r\n");
                        nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF); //default

    I never that get "case",

    and I have put at E:\nRF5_SDK_17.0.2_d674dde\components\ant\ant_profiles\ant_hrm\pages\ant_hrm_page_0.c

    function :

    static void page0_data_log(ant_hrm_page0_data_t const * p_page_data)

    err_code = sd_ant_channel_close(HRM_CHANNEL_NUM);

    The interrupt from HRM keeps coming and system reset

    How can I close it and reopen ?

    Thanks

  • You write system reset, the only way the chip will reset is if power is removed, pin reset is pressed or NVIC_SystemReset() is called. I believe the case here is that NVIC_SystemReset() is called, and likely from the app_error_fault_handler(), you should build with DEBUG to find the exact cause.

    Kenneth

Reply Children
  • 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 ?

Related