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

Unknown shutdown request - Modified ANT BPWR example

Hey, I'm just starting to develop an ANT device on the nRF52 devkit and am trying to modify the provided example to gain an understanding of the functionality.

What I have is the ANT+ BPWR example modified so that I can open the channel with button 2, and then close it and reopen with button 3:

BSP code

void bsp_evt_handler(bsp_event_t evt){
ret_code_t            err_code;
ant_bpwr_page1_data_t page1;
uint8_t channel_status;

	NRF_LOG_INFO("BSP EVENT!");

switch (evt)
{
    case BSP_EVENT_KEY_0:
        
		/* request to calibrating the sensor
        page1    = ANT_BPWR_GENERAL_CALIB_REQUEST();
        err_code = ant_bpwr_calib_request(&m_ant_bpwr, &page1);
        APP_ERROR_CHECK(err_code);
		*/
        
		sd_ant_channel_status_get(m_ant_bpwr.channel_number,&channel_status);
		NRF_LOG_INFO("ANT channel status: %u",channel_status);

	
		break;
			
	case BSP_EVENT_KEY_1:
			
		NRF_LOG_INFO("PROFILE SETUP");

		NRF_LOG_INFO("Initialize bpwr display...");
		ret_code_t err_code = ant_bpwr_disp_init(&m_ant_bpwr,
									 BPWR_DISP_CHANNEL_CONFIG(m_ant_bpwr),
									 BPWR_DISP_PROFILE_CONFIG(m_ant_bpwr));
		APP_ERROR_CHECK(err_code);
		
		NRF_LOG_INFO("Opening bpwr display...");
		err_code = ant_bpwr_disp_open(&m_ant_bpwr);
		APP_ERROR_CHECK(err_code);

		NRF_LOG_INFO("Check state of ant...");
		err_code = ant_state_indicator_channel_opened();
	
		APP_ERROR_CHECK(err_code);

		break;
						
	case BSP_EVENT_KEY_2:
		
		sd_ant_channel_status_get(m_ant_bpwr.channel_number,&channel_status);
		NRF_LOG_INFO("ANT channel status: %u",channel_status);

		sd_ant_channel_close(m_ant_bpwr.channel_number);
	
		nrf_delay_ms(1000);
	
	
		NRF_LOG_INFO("Channel close message sent...");
		
		sd_ant_channel_status_get(m_ant_bpwr.channel_number,&channel_status);
		NRF_LOG_INFO("ANT channel status: %u",channel_status);
	
	
		nrf_delay_ms(3000);
	
		NRF_LOG_INFO("REOPENING");
		
		NRF_LOG_INFO("Opening bpwr display...");
		err_code = ant_bpwr_disp_open(&m_ant_bpwr);
		APP_ERROR_CHECK(err_code);

		NRF_LOG_INFO("Check state of ant...");
		err_code = ant_state_indicator_channel_opened();
	
		APP_ERROR_CHECK(err_code);
		
		sd_ant_channel_status_get(m_ant_bpwr.channel_number,&channel_status);
		NRF_LOG_INFO("ANT channel status: %u",channel_status);
		
		
		break;
				
	case BSP_EVENT_SLEEP:
		
		NRF_LOG_INFO("TRYING TO SLEEP")
		NRF_LOG_FLUSH();
		
		nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);

		break;

    default:

		break;
}

Problem

So everything seems to be working fine until the channel is reopened, then it receives one data page, after that a shutdown request is triggered by something I can't figure out what is.

Here is the serial monitor printout starting from when I stop the channel by pressing button 3:

<info> app: BSP EVENT!                                                          
<info> app: ANT channel status: 3                                               
<info> app: Channel close message sent...                                       
<info> app: ANT channel status: 1                                               
<info> app: REOPENING                                                           
<info> app: Opening bpwr display...                                             
<info> ant_bpwr: ANT B-PWR 0 open                                               
<info> app: Check state of ant...                                               
<info> app: ANT channel status: 2                                               
<info> ant_bpwr: B-PWR rx page: 16                                              
<info> ant_bpwr_page_16: event count:                        249                
<info> ant_bpwr_page_16: pedal power:                        --                 
<info> ant_bpwr_page_16: accumulated power:                  47171 W            
<info> ant_bpwr_page_16: instantaneous power:                283 W              
<info> ant_bpwr_common: instantaneous cadence:               90 rpm             
                                                                                
                                                                                
<info> app: ANT BPWR EVENT!                                                     
<info> app: If this works, this should be the bike power: 283                   
<info> pwr_mgmt: Shutdown request 0                                             
<info> pwr_mgmt: Shutdown started. Type 0                                       
<info> app: TRYING TO SLEEP                                                     
<info> pwr_mgmt: SysOff handler 0x00017AE9 => ready                             
<info> pwr_mgmt: SysOff handler 0x00015161 => ready                             
<info> pwr_mgmt: Shutdown complete. 

I have set up the an event handler for generic softdevice ANT events, but I'm not getting any message from the SD that the channel has been closed, however as can be seen in the serial log the channel changes states.

Handler:

void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
    ret_code_t err_code;

	NRF_LOG_WARNING("SOME ANT EVENT");
	
	switch (p_ant_evt->event)
	{
		case EVENT_CHANNEL_CLOSED:
			NRF_LOG_INFO("SOFTDEVICE SAYS CLOSED!");
			break;

		default:
			break;
	}
}

Cheers, Jonas

Related