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

ant_background_scanning with S310 on nRF5144 loose RX packets

I modified the code of ant_background_scanning_s212_pca10040 to make it works with s310 on nRF5144 xxaa.

The code works fine, but loose a lot of RX packets (more than 80%).

ANT-WARE vs custom board

In the figure the packets received by AntWare and the packets received by the custom board.

I already implemented the same code on nRF5144 xxaa, but with s210 and the missed RX packets were very less.

This is my code:

#include "softdevice_handler.h"
#include "ant_stack_config.h"
#include "ant_channel_config.h"
#include "ant_search_config.h"
#include "ant_interface.h"
#include "ant_parameters.h"

#define ANT_MS_CHANNEL_NUMBER       ((uint8_t) 1)                       /**< Master channel. */
#define ANT_BS_CHANNEL_NUMBER       ((uint8_t) 0)                       /**< Background scanning channel. */
#define ANT_NETWORK_NUMBER          ((uint8_t) 0)                       /**< Default public network number. */

#define ANT_MS_CHANNEL_TYPE         CHANNEL_TYPE_MASTER                 /**< Bi-directional master. */
#define ANT_BS_CHANNEL_TYPE         CHANNEL_TYPE_SLAVE                  /**< Bi-directional slave. */

#define ANT_BS_DEVICE_NUMBER        ((uint16_t) 2)                      /**< Wild-card. */

#define ANT_DEVICE_TYPE             ((uint8_t) 2)                       /**< Device type. */
#define ANT_TRANSMISSION_TYPE       ((uint8_t) 2)                       /**< Transmission type. */
#define ANT_FREQUENCY               ((uint8_t) 66)                      /**< 2466 MHz. */

#define ANT_CHANNEL_PERIOD          ((uint16_t) 65535)                   /**< 0,5 Hz. */
#define ANT_CHANNEL_PERIOD_NONE     ((uint16_t) 0x00)                   /**< This is not taken into account. */

#define ANT_BEACON_PAGE             ((uint8_t) 1)


void ant_message_send(void);
void background_scanner_process(ant_evt_t * p_ant_evt);
void master_beacon_process(ant_evt_t * p_ant_evt);

static uint8_t m_last_rssi       = 0;
static uint16_t m_last_device_id = 0;
static uint8_t m_recieved        = 0;

/**< Derive from device serial number. */
static uint16_t ant_ms_dev_num_get(void)
{
    return ((uint16_t) (NRF_FICR->DEVICEID[0]));
}

void ant_evt_dispatch(ant_evt_t * p_ant_evt)
{
    switch (p_ant_evt->channel)
    {
        case ANT_BS_CHANNEL_NUMBER:
            background_scanner_process(p_ant_evt);
            break;

        case ANT_MS_CHANNEL_NUMBER:
            master_beacon_process(p_ant_evt);
            break;

        default:
            break;
    }
}



int main(void)
{
	DBG_init();	
	LED_init();	
	
	/////////////////////////////////////////////   ANT    ///////////////////////////////////////////////
	uint32_t err_code;
    	
	err_code = softdevice_ant_evt_handler_set(ant_evt_dispatch);
	APP_ERROR_CHECK(err_code);

	err_code = softdevice_handler_init(NRF_CLOCK_LFCLKSRC_XTAL_50_PPM, NULL, 0, NULL);
	APP_ERROR_CHECK(err_code);

	err_code = ant_stack_static_config();
	APP_ERROR_CHECK(err_code);
	
    /* Set library config to report RSSI and Device ID */
    err_code = sd_ant_lib_config_set(ANT_LIB_CONFIG_MESG_OUT_INC_RSSI
                                            | ANT_LIB_CONFIG_MESG_OUT_INC_DEVICE_ID);
    APP_ERROR_CHECK(err_code);

    const uint16_t dev_num = ant_ms_dev_num_get();

    const ant_channel_config_t ms_channel_config =
    {
        .channel_number    = ANT_MS_CHANNEL_NUMBER,
        .channel_type      = ANT_MS_CHANNEL_TYPE,
        .ext_assign        = 0x00,
        .rf_freq           = ANT_FREQUENCY,
        .transmission_type = ANT_TRANSMISSION_TYPE,
        .device_type       = ANT_DEVICE_TYPE,
        .device_number     = dev_num,
        .channel_period    = ANT_CHANNEL_PERIOD,
        .network_number    = ANT_NETWORK_NUMBER,
    };

    const ant_channel_config_t bs_channel_config =
    {
        .channel_number    = ANT_BS_CHANNEL_NUMBER,
        .channel_type      = ANT_BS_CHANNEL_TYPE,
        .ext_assign        = EXT_PARAM_ALWAYS_SEARCH,
        .rf_freq           = ANT_FREQUENCY,
        .transmission_type = ANT_TRANSMISSION_TYPE,
        .device_type       = ANT_DEVICE_TYPE,
        .device_number     = ANT_BS_DEVICE_NUMBER,
        .channel_period    = ANT_CHANNEL_PERIOD_NONE,
        .network_number    = ANT_NETWORK_NUMBER,
    };

    const ant_search_config_t bs_search_config =
    {
        .channel_number        = ANT_BS_CHANNEL_NUMBER,
        .low_priority_timeout  = ANT_LOW_PRIORITY_TIMEOUT_DISABLE,
        .high_priority_timeout = ANT_HIGH_PRIORITY_SEARCH_DISABLE,
        .search_sharing_cycles = ANT_SEARCH_SHARING_CYCLES_DISABLE,
        .search_priority       = ANT_SEARCH_PRIORITY_DEFAULT,
        .waveform              = ANT_WAVEFORM_DEFAULT,
    };

    err_code = ant_channel_init(&ms_channel_config);
    APP_ERROR_CHECK(err_code);

    err_code = ant_channel_init(&bs_channel_config);
    APP_ERROR_CHECK(err_code);

    err_code = ant_search_init(&bs_search_config);
    APP_ERROR_CHECK(err_code);

    // Fill tx buffer for the first frame
    ant_message_send();

    err_code = sd_ant_channel_open(ANT_MS_CHANNEL_NUMBER);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ant_channel_open(ANT_BS_CHANNEL_NUMBER);
    APP_ERROR_CHECK(err_code);
	
	/////////////////////////////////////////////   ANT    ///////////////////////////////////////////////

	// Main Loop
	while(1)
	{	
		sd_app_evt_wait();
	}
}

void background_scanner_process(ant_evt_t * p_ant_evt)
{
    uint32_t      err_code;
    ANT_MESSAGE * p_ant_message = (ANT_MESSAGE*)p_ant_evt->evt_buffer;

    switch(p_ant_evt->event)
    {
        case EVENT_RX:
        {
            LED_redLed_setStatus(LED_ON);
 
            if(p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTDeviceID)
            {
                m_last_device_id = uint16_decode(p_ant_message->ANT_MESSAGE_aucExtData);
            }

            if(p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTRssi)
            {
                m_last_rssi = p_ant_message->ANT_MESSAGE_aucExtData[5];
            }

            DBG_log("Message number %d\n\r", m_recieved);
            DBG_log("Device ID:     %d\n\r", m_last_device_id);
            DBG_log("RSSI:          %d\n\r\n\r", m_last_rssi);

            m_recieved++;
						
		LED_redLed_setStatus(LED_OFF);
            break;
        }
        default:
        {
            break;
        }
    }
}

void ant_message_send()
{
    uint32_t       err_code;
    uint8_t        tx_buffer[ANT_STANDARD_DATA_PAYLOAD_SIZE];
    static uint8_t counter = 0;

    tx_buffer[0] = ANT_BEACON_PAGE;
    tx_buffer[1] = m_last_rssi;
    tx_buffer[2] = (uint8_t) m_last_device_id;        // LSB
    tx_buffer[3] = (uint8_t) (m_last_device_id >> 8); // MSB
    tx_buffer[6] = counter++;
    tx_buffer[7] = m_recieved;

    err_code = sd_ant_broadcast_message_tx(ANT_MS_CHANNEL_NUMBER,
                                           ANT_STANDARD_DATA_PAYLOAD_SIZE,
                                           tx_buffer);
    APP_ERROR_CHECK(err_code);
}

void master_beacon_process(ant_evt_t * p_ant_evt)
{
    switch(p_ant_evt->event)
    {
        case EVENT_TX:
            ant_message_send();
            break;

        default:
            break;
    }

}

There are some things I didn't consider?

Has someone advices for me?

I saw that if I dont' set the background scanning I don't have lost packets. There's no way to set background scanning and don't miss packets, is there?

Thanks

Parents
  • I'm a bit confused. You have two devices. Do they have the same firmware one them? Do both have one master channel and one background scanning channel? You started off with two nRF52 with S212 and then you switched to two nRF51 with S310? Have you tried nRF52 with S332? What do you mean by "if I don't set the background scanning I don't have lost packets"? Is this on both devices? Or one of them?

Reply
  • I'm a bit confused. You have two devices. Do they have the same firmware one them? Do both have one master channel and one background scanning channel? You started off with two nRF52 with S212 and then you switched to two nRF51 with S310? Have you tried nRF52 with S332? What do you mean by "if I don't set the background scanning I don't have lost packets"? Is this on both devices? Or one of them?

Children
No Data
Related