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

How to convert output of SAADC hexadecimal values to decimal values ?

I am getting SAADC output on BLE device, but issue is I am getting hexadecimal output but i want decimal values.

I am not getting what to make changes. please suggest i have attached part of my code along with output.

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event->type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;
        uint16_t adc_value;
        uint8_t value[SAADC_SAMPLES_IN_BUFFER*2];
        uint16_t bytes_to_send;
				
        // set buffers
        err_code = nrf_drv_saadc_buffer_convert(p_event->data.done.p_buffer, SAADC_SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);
						
        // print samples on hardware UART and parse data for BLE transmission
        printf("ADC event number: %d\r\n",(int)m_adc_evt_counter);
        for (int i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++)
        {
            printf("%d\r\n", p_event->data.done.p_buffer[i]);

            adc_value = p_event->data.done.p_buffer[i];
            value[i*2] = adc_value;
            value[(i*2)+1] = adc_value >> 8;
        }
				
        // Send data over BLE via NUS service. Makes sure not to send more than 20 bytes.
        if((SAADC_SAMPLES_IN_BUFFER*2) <= 20) 
        {
            bytes_to_send = (SAADC_SAMPLES_IN_BUFFER*2);
					 
        }
        else 
        {
            bytes_to_send = 20;
        }
        err_code = ble_nus_data_send(&m_nus, value, &bytes_to_send, m_conn_handle);
        if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_NOT_FOUND)) 
        {
            APP_ERROR_CHECK(err_code);
        }
						
        m_adc_evt_counter++;
    }
}

please help ...... what changes to be made.

Parents Reply Children
No Data
Related