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

Sending SAADC over BLE?

I am trying to combine both the SAADC and BLE libraries to be able to read a value from my sensor on the analog pin and then send it over Bluetooth LE to a central dongle.

I have experimented with the /examples/peripheral/saadc example as well as the /examples/ble_peripheral/ble_app_uart. It seems that both of these examples do what I need but separately. However, when I try to combine them I experience a lot of issues.

Firstly, copying the saadc code verbatim over to the ble_app_uart code results in the LED flashing very rapidly and the output over serial to be garbage. I have narrowed down this problem being due to the fact that the APP_TIMER and Timer0 are going at the same time.

Next, I looked at the example code in this very helpful thread: devzone.nordicsemi.com/.../

And for testing purposes added the following code to the on_ble_evt handler for the condition BLE_GAP_EVT_CONNECTED:

printf("\n\rSAADC HAL simple example.\r\n");
nrf_saadc_task_trigger(NRF_SAADC_TASK_START  );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE );
nrf_saadc_task_trigger(NRF_SAADC_TASK_STOP  );

This code resulted in UART showing me the values being captured from SAADC, but all of these values are 0.

I am at a loss here after trying to figure this out for several days now. Could anybody steer me into the right direction for accomplishing this task that seems should be very simple?

TL;DR I am trying to connect a peripheral to a central device with BLE. The peripheral will be using SAADC to read the analog input 0 and will send these values to the central device so that the central device can print it out over UART. I cannot seem to figure out how to combine the two examples given.

Parents
  • Hi Filip

    Below is an example which is a ble_app_uart example combined with the SAADC example. It is based on nRF5 SDK 11.0.0 and I have tested it with softdevice S132 2.0.0 and the PCA10040 development board.

    ble_app_uart__saadc_timer_driven.zip

    The example samples on pin AIN0/P0.02 and outputs the result both on hardware UART and transfers it over BLE via the NUS service. You can adjust the samling rate by adjusting the SAADC_SAMPLE_RATE_DIVIDER constant and you can adjust the size of the SAADC RAM buffer by adjusting the SAADC_SAMPLES_IN_BUFFER constant.

  • Ok I got my new board in and it is working perfectly over UART so thank you for that! However, when I run "/examples/ble_central/ble_app_uart_c/pca10028" (also tried the pca10031) on my nRF51 Dongle, it spits out garbage for each value. I have identified it is on this code, but am not sure why it is wrong.

    for (uint32_t i = 0; i < p_ble_nus_evt->data_len; i++)
           {
                 while(app_uart_put( p_ble_nus_evt->p_data[i]) != NRF_SUCCESS);
           }
    

    Thanks so much! This is the last piece and I will be there! :)

Reply
  • Ok I got my new board in and it is working perfectly over UART so thank you for that! However, when I run "/examples/ble_central/ble_app_uart_c/pca10028" (also tried the pca10031) on my nRF51 Dongle, it spits out garbage for each value. I have identified it is on this code, but am not sure why it is wrong.

    for (uint32_t i = 0; i < p_ble_nus_evt->data_len; i++)
           {
                 while(app_uart_put( p_ble_nus_evt->p_data[i]) != NRF_SUCCESS);
           }
    

    Thanks so much! This is the last piece and I will be there! :)

Children
No Data
Related