Hi,
I am using the nrf52840dk trying to connect my bike power meter over ANT+, to then forward data to cloud (will be using the nrf9160dk and then the thingy91 once I get the following worked out).
I have converted ANT code from the examples/ant/ant_plus/ant_bpwr/bpwr_rx with pca10040 to use the pca10056 and s340 softdevice. I had this working but somehow after a build-clean and build it has stopped receiving ANT messages.
I have now taken what I think is the bare minimum from this project to simply receive an ant message and print it on the screen (via printf and NRF_LOG_INFO) - everything compiles, but I just cant seem to get the ant_evt_handler() to fire.
* I know my bike is transmitting, as I can see it on other devices
I have:
* copied the s340 softdevice (V6.1.1) to the board and all looks good (I can see it in nrfConnect)
* copied the header files to the components/softdevice/s340/headers directory
* updated the nrf_sdm.h file with: #define ANT_LICENSE_KEY "3831-521d-7df9-24d8-eff3-467b-225f-a00e"
* Set the ANT_PLUS_NETWORK_KEY : #define ANT_PLUS_NETWORK_KEY {0xB9, 0xA5, 0x21, 0xFB, 0xBD, 0x72, 0xC3, 0x45}
* Set the ANT_FS_NETWORK_KEY: #define ANT_FS_NETWORK_KEY {0xA8, 0xA4, 0x23, 0xB9, 0xF5, 0x5E, 0x63, 0xC1}
* I am using SES 5.50a for compilation and flashing
I am not sure how to proceed with debug or trying to find out why its not receiving the messages, or if the message is being received
why its not being forwarded through the different layers to the ant_evt_handler(). I know the board is fine and that it starts to work
because the initial debug statements all get printed.
I can attach the project if that helps, but for now I have the following in main.c
#include <stdint.h>
#include "nrf.h"
#include "app_error.h"
#include "app_timer.h"
#include "bsp.h"
#include "boards.h"
#include "hardfault.h"
#include "nrf_sdh.h"
#include "nrf_sdh_ant.h"
#include "nrf_pwr_mgmt.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "ant_channel_config.h"
#include "ant_parameters.h"
#include "ant_key_manager.h"
#include "ant_state_indicator.h"
#include "ant_interface.h"
#include "nrf_delay.h"
#include "sdk_config.h"
#include "string.h"
void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context);
NRF_SDH_ANT_OBSERVER(m_ant_observer, APP_ANT_OBSERVER_PRIO, ant_evt_handler, NULL);
void ant_evt_handler(ant_evt_t * p_ant_evt, void * p_context)
{
NRF_LOG_INFO("ant_evt_handler");
ret_code_t err_code;
if (p_ant_evt->channel == ANT_CHANNEL_NUM)
{
switch (p_ant_evt->event)
{
case EVENT_RX:
// Really strange, need this (;) or error: see:
// stackoverflow.com/.../why-do-i-get-a-label-can-only-be-part-of-a-statement-and-a-declaration-is-not-a
;
unsigned char * charPtr=(unsigned char *) p_ant_evt;
char ant_evt_c[256];
NRF_LOG_INFO ("RX");
// Clear the array, otherwise it will still have data in it ?
memset( ant_evt_c, '\0', sizeof( ant_evt_c ) );
for ( int i = 1; i<= sizeof(ant_evt_t); i++ )
{
char str[2];
sprintf(str, "%02x", charPtr[i]);
strcat( ant_evt_c, str );
strcat ( ant_evt_c, " ");
}
NRF_LOG_INFO( "ant_evt_c: %s", ant_evt_c);
if (p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BROADCAST_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_ACKNOWLEDGED_DATA_ID
|| p_ant_evt->message.ANT_MESSAGE_ucMesgID == MESG_BURST_DATA_ID)
{
// LED 2 is inverted for 100 msec
err_code = bsp_indication_set(BSP_INDICATE_RCV_OK);
APP_ERROR_CHECK(err_code);
}
break;
default:
NRF_LOG_INFO ("default: (%c)", p_ant_evt->event);
break;
}
}
}
static void ant_channel_rx_broadcast_setup(void)
{
NRF_LOG_INFO("ant_channel_rx_broadcast_setup.");
ant_channel_config_t broadcast_channel_config =
{
.channel_number = BROADCAST_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 = CHAN_ID_DEV_NUM,
.channel_period = CHAN_PERIOD,
.network_number = ANTPLUS_NETWORK_NUM
};
ret_code_t err_code = ant_channel_init(&broadcast_channel_config);
APP_ERROR_CHECK(err_code);
// Open channel.
err_code = sd_ant_channel_open(BROADCAST_CHANNEL_NUMBER);
APP_ERROR_CHECK(err_code);
}
/**@brief Function for the Timer and BSP initialization.
*/
static void utils_setup(void)
{
ret_code_t err_code = app_timer_init();
APP_ERROR_CHECK(err_code);
err_code = nrf_pwr_mgmt_init();
APP_ERROR_CHECK(err_code);
}
/**@brief Function for ANT stack initialization.
*/
static void softdevice_setup(void)
{
ret_code_t err_code = nrf_sdh_enable_request();
APP_ERROR_CHECK(err_code);
ASSERT(nrf_sdh_is_enabled());
err_code = nrf_sdh_ant_enable();
APP_ERROR_CHECK(err_code);
//err_code = ant_plus_key_set(ANTPLUS_NETWORK_NUM);
//APP_ERROR_CHECK(err_code);
}
/**
*@brief Function for initializing logging.
*/
static void log_init(void)
{
ret_code_t err_code = NRF_LOG_INIT(NULL);
APP_ERROR_CHECK(err_code);
NRF_LOG_DEFAULT_BACKENDS_INIT();
}
/**@brief Function for application main entry. Does not return.
*/
int main(void)
{
log_init();
utils_setup();
softdevice_setup();
ant_channel_rx_broadcast_setup();
NRF_LOG_INFO("ANT Simple example started.");
// Enter main loop.
for (;;)
{
NRF_LOG_FLUSH();
nrf_pwr_mgmt_run();
}
}
thanks