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

NUS handler for ADC

I'm trying to use the NUS to send data over from NRF52 dev kit to the NRF Connect app. Using Putty for UART works fine. Now I adapted to read out ADC values from 2 ADC ports, but data is unreadable on phone application.

Found lots of other code on the internet and adapted the best, but now stuck at this problem.

 See below part code:


        ret_code_t err_code;
        uint16_t adc_value;
        uint8_t value[SAADC_SAMPLES_IN_BUFFER*2];
        uint8_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  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_string_send(&m_nus, value, bytes_to_send);
        if (err_code != NRF_ERROR_INVALID_STATE) 
        {
            APP_ERROR_CHECK(err_code);
        }
						
        m_adc_evt_counter++;
    }

Parents Reply Children
Related