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

Reading Analog Signals While Using the ble_peripheral_uart example in SDK15.0.0 and sending strings to an iPhone

Reading analog signals while using the ble_peripheral_uart in SDK15.0.0 and sending strings to an iPhone

I am trying to read values from an analog peripheral device. To perform an analog read, I am using this example from the NordicSnippets simple examples:

github.com/.../main.c

I want to transmit the reading from the analog device to an iphone over BLE using the ble_peripheral_uart example in the SDK. The problem is that the connection between the iphone (central) and the BL652 (peripheral) keeps crashing every time I try to read from the analog signal and send. It happens in a very peculiar way: The two devices connect, then a small time later I get

"Error Code: The connection has timed out unexpectedly" in red font from the log in nRF Toolbox iPhone app.

The funny thing is: the peripheral disconnects successfully, as shown by its LED on its board and by its advertisement in another device. But the iphone app that originally connected still wants to disconnect, but cannot.

When I remove the clock tasks from lines 8 to 11, the program runs, but the values from the analog read are not reasonable or responsive to changes in the sensor.

We wish to generalize the pin assignment of the port by changing the index of the NRF_SAADC->CH[0] to NRF_SAADC->CH[pin]. What does the value of this argument actually correspond to?

I am currently working on a Laird DK, which follows the layout of pca10040.h (with the exception of a clock parameter, which has already been fixed).

Using Nordic's SDK 15.0.0

SoftDevice 132 v6.0.0

Thanks in advance for any help. I really appreciate it.

Parents
  • Hi Benjamin

    With lines 8-11 in place it will probably assert because you are trying to access the NRF_CLOCK module directly while using the SoftDevice. 

    When using the SoftDevice you should request the external HF clock by calling sd_clock_hfclk_request()

    To verify whether or not the HF clock is running you can use the sd_clock_hfclk_is_running(uint32_t * p_is_running) function. 

    Also, what pin are you trying to sample?
    The original example you are referring to will simply try to measure the VDD voltage (common use case if you want to calculate battery life time). 

    If you want to sample an external input you have to replace SAADC_CH_PSELP_PSELP_VDD with SAADC_CH_PSELP_PSELP_AnalogInputX (where X has to be between 0 and 7)
    The mapping between analog input 0-7 and the GPIO pins can be found in the pin assignment chapter of the product spec. 

    The channel index has no special significance other than allowing you to configure 8 independent ADC channels each with a unique ADC configuration. Each channel can be set to a separate input, each with it's own gain setting, limit settings and so forth. Then you can easily samples through multiple channels in turn, without having to reconfigure the ADC each time you want to change the settings. 

    Best regards
    Torbjørn

     

Reply
  • Hi Benjamin

    With lines 8-11 in place it will probably assert because you are trying to access the NRF_CLOCK module directly while using the SoftDevice. 

    When using the SoftDevice you should request the external HF clock by calling sd_clock_hfclk_request()

    To verify whether or not the HF clock is running you can use the sd_clock_hfclk_is_running(uint32_t * p_is_running) function. 

    Also, what pin are you trying to sample?
    The original example you are referring to will simply try to measure the VDD voltage (common use case if you want to calculate battery life time). 

    If you want to sample an external input you have to replace SAADC_CH_PSELP_PSELP_VDD with SAADC_CH_PSELP_PSELP_AnalogInputX (where X has to be between 0 and 7)
    The mapping between analog input 0-7 and the GPIO pins can be found in the pin assignment chapter of the product spec. 

    The channel index has no special significance other than allowing you to configure 8 independent ADC channels each with a unique ADC configuration. Each channel can be set to a separate input, each with it's own gain setting, limit settings and so forth. Then you can easily samples through multiple channels in turn, without having to reconfigure the ADC each time you want to change the settings. 

    Best regards
    Torbjørn

     

Children
No Data
Related