ANT example ant_continuous_scanning_controller(SDK 17.0.2) problem

Dear Members,

The project I'm working on now requires searching for nearby ANT+ devices and then using a table to choose which device to pair with.

These ANT+ devices include: BPWR,BSC,HRM devices. 

So,I first practice with example ant_continuous_scanning_controller(SDK 17.0.2, SoftDevice S212 ). Test with SimulANT+ (Version 2.3.0.0). Open 2 BPWR devices at the same time, But it can't find any device normally.

bpwr  device:

I press button ,It always shows up p_ant_evt->event: 0x00000007(EVENT_CHANNEL_CLOSED).

I try to change the setting of sdk_config.h, But it still doesn't work.

 

//==========================================================
// <o> ANT_NETWORK_NUM - Network number. 
#ifndef ANT_NETWORK_NUM
#define ANT_NETWORK_NUM 0
#endif

// <o> ANT_RESPONSE_CHANNEL_NUMBER - ANT response channel number. 
#ifndef ANT_RESPONSE_CHANNEL_NUMBER
#define ANT_RESPONSE_CHANNEL_NUMBER 1
#endif

// <o> ANT_SCAN_CHANNEL_NUMBER - ANT scan channel number. 
#ifndef ANT_SCAN_CHANNEL_NUMBER
#define ANT_SCAN_CHANNEL_NUMBER 0
#endif

// <o> CHAN_ID_DEV_TYPE - Channel ID: Device Type. 
#ifndef CHAN_ID_DEV_TYPE
#define CHAN_ID_DEV_TYPE 11	// 1
#endif

// <o> CHAN_ID_TRANS_TYPE - Channel ID: Transmission type. 
#ifndef CHAN_ID_TRANS_TYPE
#define CHAN_ID_TRANS_TYPE 5	// 5	// 21
#endif

// <o> HOME_ID - Unique ID for the entire network. 
#ifndef HOME_ID
#define HOME_ID 4660
#endif

// <o> RF_FREQ - RF Frequency. 
#ifndef RF_FREQ
#define RF_FREQ 57	//0x39u	// 25
#endif

Also add ant_search_init(); to code,then change "search_priority" to highest , But it still doesn't work.

/**@brief initialize ant search // joe
 */
static void AntSearchInit(void)	// joe
{
	uint32_t err_code;
	ant_search_config_t init;
	init.channel_number = ANT_SCAN_CHANNEL_NUMBER;
	init.high_priority_timeout = ANT_DEFAULT_HIGH_PRIORITY_TIMEOUT;
	init.low_priority_timeout = ANT_DEFAULT_LOW_PRIORITY_TIMEOUT;
	init.search_priority = ANT_SEARCH_PRIORITY_HIGHEST;
	init.search_sharing_cycles = ANT_SEARCH_SHARING_CYCLES_DISABLE;
	init.waveform = ANT_WAVEFORM_FAST;
	
	err_code = ant_search_init(&init);
	APP_ERROR_CHECK(err_code);
}
/**@brief initialize application
 */
static void continuous_scan_init()
{
    uint32_t err_code;
	
	AntSearchInit();

    // 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);

    // Configure channel 0 for scanning mode, but do not open it.
    // The scanning channel will be opened in scan mode for a short amount of time on a button press.
    ant_channel_config_t channel_config =
    {
        .channel_number    = ANT_SCAN_CHANNEL_NUMBER,
        .channel_type      = CHANNEL_TYPE_SLAVE,
        .ext_assign        = 0x00,
        .rf_freq           = RF_FREQ,
        .transmission_type = CHAN_ID_TRANS_TYPE,
        .device_type       = CHAN_ID_DEV_TYPE,
        .device_number     = 0x00,          // Wildcard
        .channel_period    = 0x00,          // Not used, since this is going to be scanning
        .network_number    = ANT_NETWORK_NUM,
    };

    err_code = ant_channel_init(&channel_config);
    APP_ERROR_CHECK(err_code);
		
    // Assign a second channel for sending messages on the reverse direction
    // There is no need to configure any other parameters, this channel is never opened;
    // its resources are used by ANT to send messages in the reverse direction while in
    // continuous scanning mode.
    err_code = sd_ant_channel_assign(ANT_RESPONSE_CHANNEL_NUMBER,
                                     CHANNEL_TYPE_SLAVE,
                                     ANT_NETWORK_NUM,
                                     0x00);
    APP_ERROR_CHECK(err_code);
		
		
		
}

Please,how can I solve this problem?

Best regards,

Thanks!

Joe

Parents
  • Hi Joe,

    Due to vacation and current Easter holidays in Norway we have some longer answer time than normal. We expect to be fully staffed again by Tuesday the coming week, and you may expect a reply to your issue during that week.

    I hope the additional waiting time does not cause any issues for you.

    Kind regards,
    Andreas

  • Hi Andreas,

    Do you have any suggestions for the problem I'm having?

    Thanks,

    Best regards,

    Joe

  • Are you an ANT+ adopter and have you provided the ANT+ network key when configuring the channel(s) to search for ANT+ devices?

    Kenneth

  • Hi Kenneth:

    In the original example, ANT_PLUS_NETWORK_KEY is not added, so it must be added with ANT_PLUS_NETWORK_KEY? If it is to be added, how to add ANT_PLUS_NETWORK_KEY?

    THANKS!

    Joe

  • If you look at some of the project in the \examples\ant\ant_plus\ you can find it include an ant_key_manager.c where you should place the ANT_PLUS_NETWORK_KEY, also you need to call the ant_plus_key_set() after calling nrf_sdh_ant_enable() in main.c

    Best regards,
    Kenneth

  • Thanks for  your  reply! I  add ANT_PLUS_NETWORK_KEY to  code  as you  said.

    void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
    {
        uint32_t err_code;
        uint8_t  message_rssi;
        uint16_t message_device_number;
    
        ANT_MESSAGE * p_ant_message = (ANT_MESSAGE *) &p_ant_evt->message;
    		NRF_LOG_INFO("p_ant_evt->event:0x%08X", p_ant_evt->event);
    
        switch (p_ant_evt->event)
        {
            case EVENT_RX:
                if (p_ant_message->ANT_MESSAGE_aucPayload[0] == DEVICE_STATUS_PAGE)
                {
                    bsp_board_led_invert(BSP_BOARD_LED_1);
                    if (p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTDeviceID &&
                        p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTRssi)
                    {
                        message_device_number =
                            (uint16_t)(p_ant_message->ANT_MESSAGE_aucExtData[0] |
                                       ((uint16_t)p_ant_message->ANT_MESSAGE_aucExtData[1] << 8));
                        message_rssi = p_ant_message->ANT_MESSAGE_aucExtData[5];
                        node_to_list_add(message_device_number, message_rssi);
                    }
                }
                break;
    
            case EVENT_TRANSFER_TX_COMPLETED:
                bsp_board_led_off(BSP_BOARD_LED_0);
                bsp_board_led_off(BSP_BOARD_LED_1);
                err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
                APP_ERROR_CHECK(err_code);
                break;
    
            case EVENT_TRANSFER_TX_FAILED:
                if (m_retries > 0)
                {
                    command_send();
                    m_retries--;
                }
                else
                {
                    bsp_board_led_off(BSP_BOARD_LED_0);
                    bsp_board_led_off(BSP_BOARD_LED_1);
                    err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
                    APP_ERROR_CHECK(err_code);
                }
                break;
    
            default:
                break; // No implementation needed
        }
    }

    Now it can receive EVENT_RX(p_ant_evt->event = 0x00000080),but it can't find  

    "p_ant_message->ANT_MESSAGE_aucPayload[0] == DEVICE_STATUS_PAGE ", Check the log of SimulANT+,It doesn't seem  transmit DEVICE_STATUS_PAGE, How can  I solve  this problem?

    Thanks!

    Best regards,

    Joe

Reply
  • Thanks for  your  reply! I  add ANT_PLUS_NETWORK_KEY to  code  as you  said.

    void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
    {
        uint32_t err_code;
        uint8_t  message_rssi;
        uint16_t message_device_number;
    
        ANT_MESSAGE * p_ant_message = (ANT_MESSAGE *) &p_ant_evt->message;
    		NRF_LOG_INFO("p_ant_evt->event:0x%08X", p_ant_evt->event);
    
        switch (p_ant_evt->event)
        {
            case EVENT_RX:
                if (p_ant_message->ANT_MESSAGE_aucPayload[0] == DEVICE_STATUS_PAGE)
                {
                    bsp_board_led_invert(BSP_BOARD_LED_1);
                    if (p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTDeviceID &&
                        p_ant_message->ANT_MESSAGE_stExtMesgBF.bANTRssi)
                    {
                        message_device_number =
                            (uint16_t)(p_ant_message->ANT_MESSAGE_aucExtData[0] |
                                       ((uint16_t)p_ant_message->ANT_MESSAGE_aucExtData[1] << 8));
                        message_rssi = p_ant_message->ANT_MESSAGE_aucExtData[5];
                        node_to_list_add(message_device_number, message_rssi);
                    }
                }
                break;
    
            case EVENT_TRANSFER_TX_COMPLETED:
                bsp_board_led_off(BSP_BOARD_LED_0);
                bsp_board_led_off(BSP_BOARD_LED_1);
                err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
                APP_ERROR_CHECK(err_code);
                break;
    
            case EVENT_TRANSFER_TX_FAILED:
                if (m_retries > 0)
                {
                    command_send();
                    m_retries--;
                }
                else
                {
                    bsp_board_led_off(BSP_BOARD_LED_0);
                    bsp_board_led_off(BSP_BOARD_LED_1);
                    err_code = sd_ant_channel_close(ANT_SCAN_CHANNEL_NUMBER);
                    APP_ERROR_CHECK(err_code);
                }
                break;
    
            default:
                break; // No implementation needed
        }
    }

    Now it can receive EVENT_RX(p_ant_evt->event = 0x00000080),but it can't find  

    "p_ant_message->ANT_MESSAGE_aucPayload[0] == DEVICE_STATUS_PAGE ", Check the log of SimulANT+,It doesn't seem  transmit DEVICE_STATUS_PAGE, How can  I solve  this problem?

    Thanks!

    Best regards,

    Joe

Children
No Data
Related