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

Why does changing the frequency kill ANT burst messages?

Hello all.

We have a simple ANT-page application that has the ability to send data as burst packets when requested. The code has been working well. We identified the need to change the frequency when bursting the data. Simply changing the frequency causes:
the 8 START bytes to be sent to the new frequency, calling the CONTINUE operation does not yield any errors, no more data is transmitted, and subsequent calls to the CONTINUE operation returns NRF_ANT_ERROR_TRANSFER_SEQUENCE_NUMBER_ERROR.
The code only stops working if the frequency is changed. The actual code is larger than should placed onto a forum page, but here psuedo code to give you the general idea. This function is requested from the main loop with the use of a scheduler.

static void burst_transmit(ant_event_return_t *p_event) { uint8_t tx_buffer[8]; uint32_t blocks_to_send = 0; uint32_t bytes_to_send = 0; uint32_t err_code;

switch (p_event->event)
{
case ANT_EVENT_BURST_START_REQUEST:
	memcpy(tx_buffer, <start up stuff>, 8);
	//+++ IF PROBLEM CODE REMOVED, THE REST OF THE CODE WORKS. +++
	if(g_frequency != g_req_freq)		// global current and requested freqs
	{
		err_code = sd_ant_channel_radio_freq_set(g_channel, 
							g_req_freq);
		APP_ERROR_CHECK(err_code);
		g_frequency = g_req_freq;
	}
	//+++ END OF PROBLEM CODE ++++++++++++
	err_code = sd_ant_burst_handler_request(g_channel,
					8, tx_buffer,
					BURST_SEGMENT_START);
	if(err_code == NRF_SUCCESS){ 
/* BURST_SEGMENT_START never fails, and these bytes are transmitted on the new 		frequency. */
		Queue_up_ANT_EVENT_BURST_CONTINUE_REQUEST();
		while (m_burst_wait != 0){;}    
	 	/* m_burst_wait is registered with */
		/* sd_ant_burst_handler_wait_flag_enable(). *?
	}
	else {
		Queue_up_ANT_EVENT_BURST_FAIL_REQUEST();
	}
	break;

	case ANT_EVENT_BURST_CONTINUE_REQUEST:
		bytes_to_send = p_event->bytes;
		// bytes_to_send is limited to 160 bytes per burst_handler call.
		err_code = sd_ant_burst_handler_request(g_channel,
						bytes_to_send,
						&p_event->p_data[p_event->offset],
						BURST_SEGMENT_CONTINUE);
		if(err_code == NRF_SUCCESS) {
/* BURST_SEGMENT_CONTINUE does not return an errror, the first time; */
/* however, the data is never transmitted on either frequency. */
			p_event->offset += bytes_to_send;
			p_event->bytes -= bytes_to_send;
			if(p_event->bytes < ANT_BURST_PACKET_SIZE) {
				Queue_up_ANT_EVENT_BURST_END_REQUEST();
			}else {
		Queue_up_another_ANT_EVENT_BURST_CONTINUE_REQUEST();
			}
		}else {
/* BURST_SEGMENT_CONTINUE returns */
/* NRF_ANT_ERROR_TRANSFER_SEQUENCE_NUMBER_ERROR */
/* the second time, and every other time if more attempts are made. */
			Queue_up_ANT_EVENT_BURST_FAIL_REQUEST();
		}
		while (m_burst_wait != 0){;}    
		break;

	case ANT_EVENT_BURST_END_REQUEST:
	memcpy(tx_buffer, <ending stuff>, 8);
	err_code = sd_ant_burst_handler_request(g_ant_params.channel,
        		                                	8, tx_buffer,
                                            			BURST_SEGMENT_END);
    	if(err_code == NRF_SUCCESS) {
		Queue_up_ANT_EVENT_BURST_COMPLETE_REQUEST();
		while (m_burst_wait != 0){;}    
	}else {
   		Queue_up_ANT_EVENT_BURST_FAIL_REQUEST();
	}
	break;

	default:
		break;
}

}

Any advice is appreciated!

Parents Reply Children
Related