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

Passing ADC through to NUS Service Wrong Results

I can't figure out why I can't send ADC values to the NUS service via BLE correctly. I should be getting hex values that convert to something like 0 or -1, since the ADC pin is grounded. Instead I am getting back like 0x040020E9 using the Nordic app. Am I just not passing them as the correct casted types?

    NRF_UART0->TASKS_STARTRX = 1;
    NRF_UART0->TASKS_STARTTX = 1;
    NRF_UART0->ENABLE = 1;
    uint16_t length = SAADC_SAMPLES_IN_BUFFER;
    uint8_t transfer_buffer[SAADC_SAMPLES_IN_BUFFER];

    for (i = 0; i < SAADC_SAMPLES_IN_BUFFER; i++) {
      transfer_buffer[i] = p_event->data.done.p_buffer[i];
    }

    err_code = ble_nus_data_send(&m_nus, transfer_buffer[0], sizeof(transfer_buffer[0]), m_conn_handle);
    if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) &&
        (err_code != NRF_ERROR_NOT_FOUND)) {
      APP_ERROR_CHECK(err_code);
    }

Parents Reply
  • Thanks, I think I found a way around it - unless one can straight pass to `ble_nus_data_send` 16 bit values this is what I am doing:

        static uint16_t adc_value;
        static uint16_t adc_len;
    
        uint8_t i = SAADC_SAMPLES_IN_BUFFER - 1;
        adc_value = p_event->data.done.p_buffer[i];
        adc_len = sizeof(adc_value);
        err_code = ble_nus_data_send(&m_nus, (uint8_t *)&adc_value, &adc_len, m_conn_handle);

Children
Related