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

  • 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

Reply Children
No Data
Related