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

How to send two packets of data

Hi! I have asked a question in this topic (devzone.nordicsemi.com/.../) and now I can send one packet of 20bytes. What I cannot do is sending two packets at the same time, because what I see is that my beacon sends two packets separately. My application uses the ADC every 2ms, I put the result of the conversion in an array and when I reach 20bytes I send it, so this takes 20ms(I use the 10bit conversion). When I add the second packet I expect to see the two packets at the same time every 40ms, instead I see one packet every 20ms. This is part of my code:

void ADC_IRQHandler(void)
{
	/* Clear dataready event */
  NRF_ADC->EVENTS_END = 0;	

  /* Write ADC result to port 2 */
 	//nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT2, NRF_ADC->RESULT);
	
	//Invio a pacchetti di 20 bytes (ogni dato in uscita dall'adc è 1byte)
	static uint8_t i=0;                 //usiamo static per evitare che modifichi il valore della variabile
	static uint8_t j=0;
	static uint16_t adc_results[10];     //adc a 10bit, salviamo il risultato su 16bit per non sprecare spazio nel pacchetto
	static uint16_t adc_results_2[10];

	if (i<10)	
{		
			adc_results[i]=1;//NRF_ADC->RESULT;
			i++;
}
	if ((i >= 10) & (i<20))
	{
			adc_results_2[j]=2;//NRF_ADC->RESULT;
			i++;
			j++;
	}
	if (i==20)
	{
				our_termperature_characteristic_update(&m_our_service, adc_results, adc_results_2);  //una volta riempito il pacchetto lo invia
				
		for(i=0;i<10;i++)
				{
					adc_results[i]=0; //azzera il pacchetto
					adc_results_2[i]=0;
				}
				i=0; //azzera l'indice
				j=0;
	}
	//Use the STOP task to save current. Workaround for PAN_028 rev1.5 anomaly 1.
  NRF_ADC->TASKS_STOP = 1;
	
	//Release the external crystal
	sd_clock_hfclk_release();
}	

void our_termperature_characteristic_update(ble_os_t *p_our_service, uint16_t temperature_value[], uint16_t temperature_value_2[])
{
    // OUR_JOB: Step 3.E, Update characteristic value
			if (p_our_service->conn_handle != BLE_CONN_HANDLE_INVALID)
{
			uint16_t               len = 20; //modificato per ricevere tutti i dati del pacchetto
			ble_gatts_hvx_params_t hvx_params;
			memset(&hvx_params, 0, sizeof(hvx_params));

			hvx_params.handle = p_our_service->char_handles.value_handle;
			hvx_params.type   = BLE_GATT_HVX_NOTIFICATION;
			hvx_params.offset = 0;
			hvx_params.p_len  = &len;
			hvx_params.p_data = (uint8_t*)temperature_value;  
	
			sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params);
	hvx_params.p_data = (uint8_t*)temperature_value_2;
			sd_ble_gatts_hvx(p_our_service->conn_handle, &hvx_params);
}
Related