Hello, i have a central card nrf52840 and several peripheral cards nrf52840.
I have a program that allows me to launch the timer on the central and peripherals at the same time. The peripherals send their timers to the central station and the central station compares its timer with the one received.
I have a connection interval of 62.5 ms and a connection time of 7.8ms.
When I have a central connection and 1 peripheral: I have a drift only 3 second on 16h00.
But when I have a central 2 peripheral connection: I have a drift of 1 second after a few minutes. and i don't why if if anyone can help me.
Here is the central code:
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);
uint32_t compteurTimer;
uint32_t compteur;
uint32_t compteur2;
uint32_t compteur3;
uint32_t compteur4;
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context){
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
compteur2++;
compteur3++;
compteur++;
compteur4++;
if(compteur==1000){
//NRF_LOG_INFO("dif_Cent_Perip = %d",dif_Cent_Perip);
compteur = 0;
}
if(compteur3==6250){
compteurTimer=compteur2;
compteur3=0;
}
if(compteur4==100000){
tmp=2;
compteur4=0;
}
break;
default:
//Do nothing.
break;
}
}
void test(){
NRF_LOG_INFO("test");
uint32_t time_us = 10; //Time(in microsecond) between consecutive compare events.
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;
//Configure all leds on board.
bsp_board_init(BSP_INIT_LEDS);
//Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
NRF_LOG_INFO("err_code %d",err_code);
APP_ERROR_CHECK(err_code);
time_ticks = nrf_drv_timer_us_to_ticks(&TIMER_LED, time_us);
nrf_drv_timer_extended_compare(
&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_LED);
}
Here is the peripheral code:
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);
uint32_t compteur;
uint32_t compteur2;
uint32_t compteur3;
uint32_t tab[20] ={0};
int d = 0;
int f;
int x ;
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context){
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
d++;
compteur++;
break;
default:
//Do nothing.
break;
}
}
void test(){
NRF_LOG_INFO("test");
uint32_t time_us =10; //Time(in miliseconds) between consecutive compare events.
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;
//Configure all leds on board.
bsp_board_init(BSP_INIT_LEDS);
//Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
NRF_LOG_INFO("err_code %d",err_code);
APP_ERROR_CHECK(err_code);
time_ticks = nrf_drv_timer_us_to_ticks(&TIMER_LED, time_us);
nrf_drv_timer_extended_compare(
&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_LED);
}
thank's