<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37229/timer-deviation-nrf52840-sdk15-0-s140</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Aug 2018 13:25:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37229/timer-deviation-nrf52840-sdk15-0-s140" /><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143588?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 13:25:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3202068-19db-4f61-8ee9-79c021061b4d</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Can you try to use:&lt;br /&gt;#define CLOCK_CONFIG_LF_SRC 1&lt;br /&gt;or&lt;br /&gt;#define CLOCK_CONFIG_LF_SRC 2&lt;/p&gt;
&lt;p&gt;instead of&lt;br /&gt;#define CLOCK_CONFIG_LF_SRC 0&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143496?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 07:57:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:329fa6d5-4a9a-4516-989e-10867bb98517</guid><dc:creator>lmouelo</dc:creator><description>&lt;p&gt;ok now i have this in central main :&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="text"&gt;static void timer_sd_handler(void * p_context){
			  
				compteur++; // affichage chaque seconde
				compteur2++; // recupere la valeur
				compteur3++; //recuperer la valeur tout les 62.5ms
				compteur4++; // affichage pour 2 valeur
	
				if(compteur==1000){
					
					//NRF_LOG_INFO(&amp;quot;dif_Cent_Perip = %d&amp;quot;,dif_Cent_Perip);	
					compteur = 0; 
				}
				
				if(compteur3==62){
					compteurTimer=compteur2;
					compteur3=0;
				}
				if(compteur4==1000){
					NRF_LOG_INFO(&amp;quot;------------------&amp;gt;1sec&amp;lt;-------------------------------&amp;quot;);
				tmp=2;
					compteur4=0;
				}
				//NRF_LOG_INFO(&amp;quot;compteur2 = %d&amp;quot;,compteur2);
	
}

static void lfclk_request(void)
{
    ret_code_t err_code;// = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
    nrf_drv_clock_lfclk_request(NULL);
		NRF_LOG_INFO(&amp;quot;LFCLK: OFF&amp;quot;);
    if(nrf_drv_clock_lfclk_is_running()){
		NRF_LOG_INFO(&amp;quot;LFCLK: ON&amp;quot;);
	}
}

void test(){
	
	ret_code_t err_code;
	
	NRF_LOG_INFO(&amp;quot;1&amp;quot;);

	
	NRF_LOG_INFO(&amp;quot;3&amp;quot;);
	//Create timers
	
	err_code = app_timer_create(&amp;amp;sd_timer_id,APP_TIMER_MODE_REPEATED,timer_sd_handler);
	NRF_LOG_INFO(&amp;quot;4&amp;quot;);
		lfclk_request();
	APP_ERROR_CHECK(err_code);
	NRF_LOG_INFO(&amp;quot;Timer_sd_start&amp;quot;);
	err_code = app_timer_start(sd_timer_id, COMPTEUR_INTERVAL, NULL);
	NRF_LOG_INFO(&amp;quot;%d&amp;quot;,err_code);
	APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in central sdk_config.h :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//==========================================================
// &amp;lt;e&amp;gt; CLOCK_ENABLED - nrf_drv_clock - CLOCK peripheral driver - legacy layer
//==========================================================
#ifndef CLOCK_ENABLED
#define CLOCK_ENABLED 1
#endif
// &amp;lt;o&amp;gt; CLOCK_CONFIG_LF_SRC  - LF Clock Source
 
// &amp;lt;0=&amp;gt; RC 
// &amp;lt;1=&amp;gt; XTAL 
// &amp;lt;2=&amp;gt; Synth 

#ifndef CLOCK_CONFIG_LF_SRC
#define CLOCK_CONFIG_LF_SRC 0
#endif

// &amp;lt;o&amp;gt; CLOCK_CONFIG_IRQ_PRIORITY  - Interrupt priority
 

// &amp;lt;i&amp;gt; Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// &amp;lt;0=&amp;gt; 0 (highest) 
// &amp;lt;1=&amp;gt; 1 
// &amp;lt;2=&amp;gt; 2 
// &amp;lt;3=&amp;gt; 3 
// &amp;lt;4=&amp;gt; 4 
// &amp;lt;5=&amp;gt; 5 
// &amp;lt;6=&amp;gt; 6 
// &amp;lt;7=&amp;gt; 7 

#ifndef CLOCK_CONFIG_IRQ_PRIORITY
#define CLOCK_CONFIG_IRQ_PRIORITY 2
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in peripheral main :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void lfclk_request(void)
{
    ret_code_t err_code;// = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
    nrf_drv_clock_lfclk_request(NULL);
		NRF_LOG_INFO(&amp;quot;LFCLK: OFF&amp;quot;);
    if(nrf_drv_clock_lfclk_is_running()){
		NRF_LOG_INFO(&amp;quot;LFCLK: ON&amp;quot;);
	}
}

static void timer_sd_handler(void * p_context){
			
	compteur++;
	
}

void test(){
	
	

	ret_code_t err_code;
	lfclk_request();
	// Create timers
	err_code = app_timer_create(&amp;amp;sd_timer_id,APP_TIMER_MODE_REPEATED,timer_sd_handler);
	NRF_LOG_INFO(&amp;quot;&amp;quot;);
	APP_ERROR_CHECK(err_code);
	
	NRF_LOG_INFO(&amp;quot;Timer_sd_start&amp;quot;);
	err_code = app_timer_start(sd_timer_id, COMPTEUR_INTERVAL, NULL);
	NRF_LOG_INFO(&amp;quot;%d&amp;quot;,err_code);
	APP_ERROR_CHECK(err_code);
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in peripheral config_sdk.h :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//==========================================================
// &amp;lt;e&amp;gt; CLOCK_ENABLED - nrf_drv_clock - CLOCK peripheral driver - legacy layer
//==========================================================
#ifndef CLOCK_ENABLED
#define CLOCK_ENABLED 1
#endif
// &amp;lt;o&amp;gt; CLOCK_CONFIG_LF_SRC  - LF Clock Source
 
// &amp;lt;0=&amp;gt; RC 
// &amp;lt;1=&amp;gt; XTAL 
// &amp;lt;2=&amp;gt; Synth 

#ifndef CLOCK_CONFIG_LF_SRC
#define CLOCK_CONFIG_LF_SRC 0
#endif

// &amp;lt;o&amp;gt; CLOCK_CONFIG_IRQ_PRIORITY  - Interrupt priority
 

// &amp;lt;i&amp;gt; Priorities 0,2 (nRF51) and 0,1,4,5 (nRF52) are reserved for SoftDevice
// &amp;lt;0=&amp;gt; 0 (highest) 
// &amp;lt;1=&amp;gt; 1 
// &amp;lt;2=&amp;gt; 2 
// &amp;lt;3=&amp;gt; 3 
// &amp;lt;4=&amp;gt; 4 
// &amp;lt;5=&amp;gt; 5 
// &amp;lt;6=&amp;gt; 6 
// &amp;lt;7=&amp;gt; 7 

#ifndef CLOCK_CONFIG_IRQ_PRIORITY
#define CLOCK_CONFIG_IRQ_PRIORITY 2
#endif

// &amp;lt;/e&amp;gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So when a send the peripheral&amp;#39;s counter to the central card, a few minute i have a diviation between the two timers (central / peripheral ) surrounding 500 ms or more than 1 second.&lt;/p&gt;
&lt;p&gt;what part of code should I add to calibrate the &lt;span&gt;CRLF&amp;nbsp;&lt;/span&gt;or then what should I do to use an external &lt;span&gt;LFXO.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I want a maximum drift of 3 seconds after 16 hours&amp;nbsp;or 0.003125 per second&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143493?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 07:40:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bf03d38-859e-40e4-a540-f7af0027969f</guid><dc:creator>lmouelo</dc:creator><description>&lt;p&gt;how to calibrate CRLF &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143489?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 07:12:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b26ecae1-2005-4245-9924-5da47b45de9e</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;A few things to look into:&lt;/p&gt;
&lt;p&gt;- An RTC tick is (1/32768=) 30.51757 us. This means that when you configure&amp;nbsp;an app timer&amp;nbsp;with 1ms, the&amp;nbsp;timer_sd_handler() will run at every 32 RTC periods, since that is the closest: 0.9765625 ms.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;- The accuracy of the RTC tick depends on the LFCLK source, for instance if you are using the internal LFRC then the accuracy is &amp;lt;500ppm, which means a potential drift of 500us after 1second have elapsed. However the &amp;lt;500ppm only apply if you have calibrated the LFRC, else it may be much larger (1% or more). A more accurate resolution can be achieved by using external LFXO,then the accuracy is typical &amp;lt;50ppm and there is no need to calibrate.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143475?ContentTypeID=1</link><pubDate>Thu, 09 Aug 2018 06:30:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9b14ee7b-49b7-4e07-b313-dc411c6a6b23</guid><dc:creator>lmouelo</dc:creator><description>&lt;p&gt;Now&amp;nbsp; i can send mi counter but it&amp;#39;s the same, there are a big diference into conter central and conteur peripheral&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143363?ContentTypeID=1</link><pubDate>Wed, 08 Aug 2018 12:23:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7260e0f-af9d-4873-96a0-c1c4ebcf9ebf</guid><dc:creator>lmouelo</dc:creator><description>&lt;p&gt;I have changed my timer, my counter increments every ms but now I have a problem with my send I can no longer store the counter reading in the table.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void lfclk_request(void)
{
    ret_code_t err_code = nrf_drv_clock_init();
    APP_ERROR_CHECK(err_code);
    nrf_drv_clock_lfclk_request(NULL);
		NRF_LOG_INFO(&amp;quot;LFCLK: off&amp;quot;);
    if(nrf_drv_clock_lfclk_is_running()){
		NRF_LOG_INFO(&amp;quot;LFCLK: ON&amp;quot;);
	}
}

static void timer_sd_handler(void * p_context){
			
	compteur++;
//	NRF_LOG_INFO(&amp;quot;%d&amp;quot;,compteur);
	
}

void test(){
	

	ret_code_t err_code;
	// Initialize timer module.
	err_code = app_timer_init();
	APP_ERROR_CHECK(err_code);

	// Create timers
	err_code = app_timer_create(&amp;amp;sd_timer_id,APP_TIMER_MODE_REPEATED,timer_sd_handler);
	NRF_LOG_INFO(&amp;quot;&amp;quot;);
	APP_ERROR_CHECK(err_code);
	
	NRF_LOG_INFO(&amp;quot;Timer_sd_start&amp;quot;);
	err_code = app_timer_start(sd_timer_id, SD_SAVE_DATA_INTERVAL, NULL);
	APP_ERROR_CHECK(err_code);
}
static void data_send_timeout_handler(void * p_context)
{	
	
	
	bsp_board_led_on(BSP_BOARD_LED_3);
	ret_code_t err_code=20;
	uint32_t data_send=DATA_TO_SEND_IN_INTERVAL;
	static const uint8_t data_length=243;
	static uint8_t data_cid[data_length];
	static bool all_data_send=1;
	static uint32_t num_data=0;
	static int i =0;
	uint32_t tmp;
	
	
	tmp = compteur ; 
	
	if(data_send&amp;lt;DATA_TO_SEND_IN_INTERVAL){
		all_data_send=0;
	}
	
	
	if(param_conn.periph_to_central &amp;amp;&amp;amp; all_data_send &amp;amp;&amp;amp; test_1_16){
//		NRF_LOG_INFO(&amp;quot;1/16second&amp;quot;);
//		if(data_cid[30]!=29){
//			for(uint8_t i=0;i&amp;lt;data_length;i++){
//				data_cid[i]=i;
//			}
//		}
		
		if(i == 0){
			test();
			i=1;
		}
			
		

		
		
	//!!!!!!!!!!!!!!!!!!!here i have a problem !!!!!!!!!!!!!!!!!//////////////////	
		//NRF_LOG_INFO(&amp;quot;num_data=%d&amp;quot;,num_data);
		data_cid[0]=(tmp &amp;gt;&amp;gt; 0)&amp;amp; 0xFF;
		data_cid[1]=(tmp &amp;gt;&amp;gt; 8)&amp;amp; 0xFF;
		data_cid[2]=(tmp &amp;gt;&amp;gt; 16)&amp;amp; 0xFF;
		data_cid[3]=(tmp &amp;gt;&amp;gt; 24)&amp;amp; 0xFF;
		data_send=0;
		
		
		for(int x = 0; x&amp;lt;=3;x++){
		NRF_LOG_INFO(&amp;quot;data_cid %d = %d&amp;quot;,x,data_cid[x]);
		}
//!!!!!!!!!!!!!!!!!!!here i have a problem !!!!!!!!!!!!!!!!!//////////////////	
		//send start
		while(err_code!=NRF_SUCCESS){
			err_code=ble_cid_measurement_send(&amp;amp;m_cid,&amp;amp;data_cid[0],1,DATA_1_16_START_FLAG);
			if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
							(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
					 )
				{

					APP_ERROR_HANDLER(err_code);
				}
				
				if(m_cid.conn_handle==BLE_CONN_HANDLE_INVALID || !param_conn.periph_to_central){
					return;
				}
		}
		err_code=20;
		//NRF_LOG_INFO(&amp;quot;send start&amp;quot;);
		
		
		//send data
		while(data_send&amp;lt;DATA_TO_SEND_IN_INTERVAL){
			while(err_code!=NRF_SUCCESS){
				bsp_board_led_on(BSP_BOARD_LED_2);
				if(data_send+data_length&amp;lt;DATA_TO_SEND_IN_INTERVAL){

					err_code = ble_cid_measurement_send(&amp;amp;m_cid, data_cid, data_length,SIMPLE_DATA_SEND_FLAG);
				
				}else{

					err_code = ble_cid_measurement_send(&amp;amp;m_cid, data_cid, DATA_TO_SEND_IN_INTERVAL-data_send,SIMPLE_DATA_SEND_FLAG);

				}
				if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
							(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
					 )
				{

					APP_ERROR_HANDLER(err_code);


				}
				
				bsp_board_led_off(BSP_BOARD_LED_2);
				
				if(m_cid.conn_handle==BLE_CONN_HANDLE_INVALID || !param_conn.periph_to_central){
					return;

				}
			}
			err_code=20;
			data_send+=data_length;
			
			
		}
		all_data_send=1;&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143300?ContentTypeID=1</link><pubDate>Wed, 08 Aug 2018 06:33:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:110bcb7c-f82e-4e85-97ab-31de3313d9e9</guid><dc:creator>lmouelo</dc:creator><description>&lt;p&gt;ok thank&amp;#39;s you but how i&amp;nbsp;how to do&amp;nbsp; app_timer (RTC) with a 1 ms interval that increments a counter reading by 1 ms?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143258?ContentTypeID=1</link><pubDate>Tue, 07 Aug 2018 17:14:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:18cf4a97-3d26-46de-8da4-422697ffdabd</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Not sure if I quite understand the resolution of your timer ticks here, but I recommend to have them to minimum 1ms. If you have very small ticks (e.g. in the tens of us), then the interrupts will be blocked during BLE events, this will work as long as the communication is 1:1 (since both are blocked equally much), but will not work in a 1:2 (since then the central will be blocked twize as much.Can that be the case?&lt;/p&gt;
&lt;p&gt;Possible easier would be to use an app_timer (RTC) with 1ms interval that increment an 1ms counter value. You can always have finer resolution by using timer when needed.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: timer deviation nrf52840 sdk15.0 s140</title><link>https://devzone.nordicsemi.com/thread/143177?ContentTypeID=1</link><pubDate>Tue, 07 Aug 2018 09:41:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dc68abe2-6b1b-4bd2-9a20-7527d32e5827</guid><dc:creator>lmouelo</dc:creator><description>&lt;p&gt;the central code:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int x =0 ; 
uint32_t datatab[11]={0}; // table to save data
uint32_t CompteurCentral[11]={0};
uint32_t tab_dif_Cent_Perip[11]={0};
uint32_t dif2 ;
uint32_t i = 0;
uint32_t dif_Cent_Perip;
uint32_t delta_dif ;
uint32_t cpt=0;
static int tmp = 0;////timer&amp;amp;&amp;amp;compteur//////////////////////////////
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(&amp;quot;dif_Cent_Perip = %d&amp;quot;,dif_Cent_Perip);	
					compteur = 0; 
				}
				
				if(compteur3==6250){
					compteurTimer=compteur2;
					compteur3=0;
				}
				if(compteur4==100000){
				tmp=2;
					compteur4=0;
				}
					
				break;

        default:
            //Do nothing.
            break;
    }	
}static void cid_c_evt_handler(ble_cid_c_t * p_cid_c, ble_cid_c_evt_t * p_cid_c_evt)
{
    ret_code_t err_code;
		static float moyenne[NRF_SDH_BLE_CENTRAL_LINK_COUNT] = {0};
		static float timer[NRF_SDH_BLE_CENTRAL_LINK_COUNT] = {0};
		static int compteur[NRF_SDH_BLE_CENTRAL_LINK_COUNT] ={0};
		static uint64_t time_actu[NRF_SDH_BLE_CENTRAL_LINK_COUNT]={0};
		static uint64_t time_diff[NRF_SDH_BLE_CENTRAL_LINK_COUNT]={0};
		static uint8_t num_data[NRF_SDH_BLE_CENTRAL_LINK_COUNT];
		static float  time_con[NRF_SDH_BLE_CENTRAL_LINK_COUNT]= {0};
	
		//etat gpiote
		nrf_drv_gpiote_init();
		nrf_gpio_cfg_input(7,NRF_GPIO_PIN_PULLDOWN);
		uint16_t state = nrf_gpio_pin_read(7);
		state = 1;
		
		
		
    switch (p_cid_c_evt-&amp;gt;evt_type)
    {
        case BLE_CID_C_EVT_DISCOVERY_COMPLETE:
        {
            NRF_LOG_INFO(&amp;quot;Cidelec service discovered.&amp;quot;);

            err_code = ble_cid_c_handles_assign(p_cid_c,
                                                p_cid_c_evt-&amp;gt;conn_handle,
                                                &amp;amp;p_cid_c_evt-&amp;gt;params.peer_db);
            APP_ERROR_CHECK(err_code);

            // Initiate bonding.
            err_code = pm_conn_secure(p_cid_c_evt-&amp;gt;conn_handle, false);
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
						//param_conn.m_conn_handle=p_cid_c-&amp;gt;conn_handle;
						m_cid_c[p_cid_c-&amp;gt;conn_handle].conn_handle=p_cid_c-&amp;gt;conn_handle;
        } break;

        case BLE_CID_C_EVT_NOTIFICATION_SIMPLE_DATA_RECEIVE:
        {
					bsp_board_led_invert(BSP_BOARD_LED_2);
//					for(uint8_t i=0;i&amp;lt;p_cid_c_evt-&amp;gt;params.cid_data.data_length;i++){
//						if(p_cid_c_evt-&amp;gt;params.cid_data.data[i]!=i){
//							NRF_LOG_INFO(&amp;quot;erreur:mauvaise donn&amp;#233;e recu&amp;quot;);
//							i=250;
//						}
//					}
					if(param_conn[p_cid_c_evt-&amp;gt;conn_handle].test_debit.etat_test){
						
						param_conn[p_cid_c_evt-&amp;gt;conn_handle].test_debit.data_receive+=p_cid_c_evt-&amp;gt;params.cid_data.data_length;
						
					}else if(data_1_16[p_cid_c_evt-&amp;gt;conn_handle].etat_test){
						
						
						//d&amp;#233;calage pour r&amp;#233;cuper la valeur en 32 bit (8 bit -&amp;gt; 32 bit)
						cpt = p_cid_c_evt-&amp;gt;params.cid_data.data[0]+(p_cid_c_evt-&amp;gt;params.cid_data.data[1]*256)+(p_cid_c_evt-&amp;gt;params.cid_data.data[2]*65356)+(p_cid_c_evt-&amp;gt;params.cid_data.data[3]*16777216);
						
						
						x++;
						
						//NRF_LOG_INFO(&amp;quot;num_data=%d for conn %d&amp;quot;,num_data[p_cid_c_evt-&amp;gt;conn_handle],p_cid_c_evt-&amp;gt;conn_handle);
				   // NRF_LOG_INFO(&amp;quot;-----------------------------------------------------------&amp;quot; );

						//NRF_LOG_INFO(&amp;quot;Connexion %d&amp;quot;, p_cid_c_evt-&amp;gt;conn_handle);
				
						datatab[x] = cpt; // put data on the table
						
						CompteurCentral[x] = compteurTimer; // tableau compteur central 
					
						dif_Cent_Perip = CompteurCentral[x] - datatab[x];  // diff&amp;#233;rence entre central et peripheral 
			      		
						tab_dif_Cent_Perip[x] = dif_Cent_Perip ; //tableau diff&amp;#233;rence entre central et peripheral
					//	NRF_LOG_INFO(&amp;quot;data_receive=%d from conn%d time_data=%d&amp;quot;,cpt, p_cid_c_evt-&amp;gt;conn_handle, time_diff[p_cid_c_evt-&amp;gt;conn_handle]);
					//	NRF_LOG_INFO(&amp;quot;CompteurCentral = %d&amp;quot;,CompteurCentral[x]);	
						//NRF_LOG_INFO(&amp;quot;%d&amp;quot;,dif_Cent_Perip);	
						
						if(tmp==2){
							
							NRF_LOG_INFO(&amp;quot;ce= %d, p1= %d, ce= %d, p2 = %d&amp;quot;,CompteurCentral[x-1],datatab[x-1],CompteurCentral[x],datatab[x] );
							tmp = 0;
						}
						
						if(datatab[x-1]&amp;gt;datatab[x]){
							
							dif2 = datatab[x-1]-datatab[x];	//compare of two values Con0 Con1
						}		
						
						else{
							
							dif2 = datatab[x]-datatab[x-1]; //compare of two values
							
						}
						if(tab_dif_Cent_Perip[x-1]&amp;gt;tab_dif_Cent_Perip[x]){
							
							delta_dif = tab_dif_Cent_Perip[x-1] - tab_dif_Cent_Perip[x];
							//NRF_LOG_INFO(&amp;quot;delta_dif = %d&amp;quot;,delta_dif);
						}
						else{
							
							delta_dif = tab_dif_Cent_Perip[x] - tab_dif_Cent_Perip[x-1];
							//NRF_LOG_INFO(&amp;quot;delta_dif = %d&amp;quot;,delta_dif);
						}
		
						//NRF_LOG_INFO(&amp;quot;dif_Cent_Perip = %d &amp;quot;, dif_Cent_Perip);
						//NRF_LOG_INFO(&amp;quot;delta_dif =  %d&amp;quot; ,delta_dif);
						//NRF_LOG_INFO(&amp;quot;datatab X =  %d&amp;quot; ,datatab[x]);
						//NRF_LOG_INFO(&amp;quot;datatab X-1 =  %d&amp;quot; ,datatab[x-1]);
					//	NRF_LOG_INFO(&amp;quot;-----------------------------------------------------------&amp;quot; );
						
						if(x==10){
							uint32_t f = datatab[x];
							uint32_t f2 = tab_dif_Cent_Perip[x];
							uint32_t f3 = CompteurCentral[x];
							for(i = 0; i&amp;lt;=x;i++){
									datatab[i]=0;	
								tab_dif_Cent_Perip[i]=0;
								CompteurCentral[i]=0;
							}
							datatab[0]=f;
							tab_dif_Cent_Perip[0] =f2;
							CompteurCentral[0]=f3;
							x=0;
					//	 NRF_LOG_INFO(&amp;quot;d&amp;#233;calage valeur tab[0]= %d&amp;quot;,datatab[0] );

					}
						
						
						data_1_16[p_cid_c_evt-&amp;gt;conn_handle].data_receive+=p_cid_c_evt-&amp;gt;params.cid_data.data_length;
						
						state =1;
						
						//NRF_LOG_INFO(&amp;quot;EtatData = %d&amp;quot;,state);						
						//NRF_LOG_INFO(&amp;quot;data_receive=%d from conn%d time_data=%d&amp;quot;,data_1_16[p_cid_c_evt-&amp;gt;conn_handle].data_receive, p_cid_c_evt-&amp;gt;conn_handle, time_diff[p_cid_c_evt-&amp;gt;conn_handle]);
						

					}else{
						
						//NRF_LOG_INFO(&amp;quot;data_receive:%d octets from conn %d&amp;quot;,p_cid_c_evt-&amp;gt;params.cid_data.data_length,p_cid_c_evt-&amp;gt;conn_handle);
						
					//	NRF_LOG_INFO(&amp;quot;EtatData = %d&amp;quot;,state);
					}
        } break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The peripheral code :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;////timer&amp;amp;&amp;amp;compteur//////////////////////////////
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(&amp;quot;test&amp;quot;);
    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(&amp;amp;TIMER_LED, &amp;amp;timer_cfg, timer_led_event_handler);
	NRF_LOG_INFO(&amp;quot;err_code %d&amp;quot;,err_code);
    APP_ERROR_CHECK(err_code);
    time_ticks = nrf_drv_timer_us_to_ticks(&amp;amp;TIMER_LED, time_us);
    nrf_drv_timer_extended_compare(
         &amp;amp;TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
    nrf_drv_timer_enable(&amp;amp;TIMER_LED);
}
tatic void data_send_timeout_handler(void * p_context)
{	
	
	
	bsp_board_led_on(BSP_BOARD_LED_3);
	ret_code_t err_code=20;
	uint32_t data_send=DATA_TO_SEND_IN_INTERVAL;
	static const uint8_t data_length=243;
	static uint8_t data_cid[data_length];
	static bool all_data_send=1;
	static uint32_t num_data=0;
	static int i =0;
	uint32_t tmp;
	
	
	tmp = compteur ; 
	
	if(data_send&amp;lt;DATA_TO_SEND_IN_INTERVAL){
		all_data_send=0;
	}
	
	
	if(param_conn.periph_to_central &amp;amp;&amp;amp; all_data_send &amp;amp;&amp;amp; test_1_16){
		
		if(i == 0){
			test();
			i=1;
		}
			
		

		
		
		
	//	NRF_LOG_INFO(&amp;quot;num_data=%d&amp;quot;,num_data);
		data_cid[0]=(tmp &amp;gt;&amp;gt; 0)&amp;amp; 0xFF;
		data_cid[1]=(tmp &amp;gt;&amp;gt; 8)&amp;amp; 0xFF;
		data_cid[2]=(tmp &amp;gt;&amp;gt; 16)&amp;amp; 0xFF;
		data_cid[3]=(tmp &amp;gt;&amp;gt; 24)&amp;amp; 0xFF;
		data_send=0;
		
		/*for(int x = 0; x&amp;lt;=3;x++){
		NRF_LOG_INFO(&amp;quot;data_cid %d = %d&amp;quot;,x,data_cid[x]);
		}*/
		
		//send start
		while(err_code!=NRF_SUCCESS){
			err_code=ble_cid_measurement_send(&amp;amp;m_cid,&amp;amp;data_cid[0],1,DATA_1_16_START_FLAG);
			if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
							(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
					 )
				{

					APP_ERROR_HANDLER(err_code);
				}
				
				if(m_cid.conn_handle==BLE_CONN_HANDLE_INVALID || !param_conn.periph_to_central){
					return;
				}
		}
		err_code=20;
		//NRF_LOG_INFO(&amp;quot;send start&amp;quot;);
		
		
		//send data
		while(data_send&amp;lt;DATA_TO_SEND_IN_INTERVAL){
			while(err_code!=NRF_SUCCESS){
				bsp_board_led_on(BSP_BOARD_LED_2);
				if(data_send+data_length&amp;lt;DATA_TO_SEND_IN_INTERVAL){

					err_code = ble_cid_measurement_send(&amp;amp;m_cid, data_cid, data_length,SIMPLE_DATA_SEND_FLAG);
				
				}else{

					err_code = ble_cid_measurement_send(&amp;amp;m_cid, data_cid, DATA_TO_SEND_IN_INTERVAL-data_send,SIMPLE_DATA_SEND_FLAG);

				}
				if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_INVALID_STATE) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_RESOURCES) &amp;amp;&amp;amp;
							(err_code != NRF_ERROR_BUSY) &amp;amp;&amp;amp;
							(err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
					 )
				{

					APP_ERROR_HANDLER(err_code);


				}
				
				bsp_board_led_off(BSP_BOARD_LED_2);
				
				if(m_cid.conn_handle==BLE_CONN_HANDLE_INVALID || !param_conn.periph_to_central){
					return;

				}
			}
			err_code=20;
			data_send+=data_length;
			
			
		}
		all_data_send=1;
		s&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>