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

Nordic UART Service send a 10 bit value over BLE?

Hi,

I programmed the NRF51-dk to take ADC samples and transmit those values at 8 bit resolution. Now I want to send a 10 bit resolution value over BLE UART, but I believe the limit for the ble_nus_string_send function only sends up to 8 bits. Right now I store the 10 bit ADC value as an uint16_t. I thought about dividing the 16 bit into two 8 bit unsigned integers and then sending them separately, but I wanted to know if it was possible to send up to 16 or at least 10 bits. My code:

void ADC_IRQHandler(void)
{
//	uint16_t adc_result_calibrated;
	uint16_t adc_result;
	
	/* Clear dataready event */
  NRF_ADC->EVENTS_END = 0;	
	
	adc_result = NRF_ADC->RESULT;	
	uint8_t adc_low = adc_result & 0xff;
	uint8_t adc_high = (adc_result >> 8);
	app_trace_log("Value: %X%X\r\n",adc_high,adc_low);   //log ADC reult on UART
	ble_nus_string_send(&m_nus, &adc_result , 1);
	
	//Release the external crystal
	sd_clock_hfclk_release();
}	
Parents
  • What you want to achieve can be handled by ble_nus_string_send. Not sure why you think the function only sends 8 bits, it can send up to 20 bytes in one call and you can call it very rapidly.

    So with uint16_t that is two bytes.

    First set up your uint8_t data_to_send_array[20] = { 0 } I put 20, but you can put any number as long as it is bigger than the value you want to send and does not exceed the maximum size allowed.

    Next get your adc_result and do this:

    data_to_send_array[0] = (adc_result & 0xFF00) >> 8;
    data_to_send_array[1] = (adc_result & 0x00FF);
    

    The call ble_nus_string_send(&m_nus, data_to_send_array , 2) and you will be good.

Reply
  • What you want to achieve can be handled by ble_nus_string_send. Not sure why you think the function only sends 8 bits, it can send up to 20 bytes in one call and you can call it very rapidly.

    So with uint16_t that is two bytes.

    First set up your uint8_t data_to_send_array[20] = { 0 } I put 20, but you can put any number as long as it is bigger than the value you want to send and does not exceed the maximum size allowed.

    Next get your adc_result and do this:

    data_to_send_array[0] = (adc_result & 0xFF00) >> 8;
    data_to_send_array[1] = (adc_result & 0x00FF);
    

    The call ble_nus_string_send(&m_nus, data_to_send_array , 2) and you will be good.

Children
Related