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

nRF52832 SAADC

Hello,

I'm using nRF SDK 15.0. I'm trying to use SAADC peripheral in my code. My primary code is based on "ble_app_template". I have added several services which are working fine. 

I have copied the SAADC code from the saadc example in the peripheral folder of SDK. The code is as it is. I can compile the SAADC example individually but when try to use this code in the BLE project, it gives errors (as below). 

Kindly let me know what needs to be changed/adjusted. I need at least two analog inputs.


Compiling ‘main.c’
implicit declaration of function 'saadc_init'; did you mean 'gatt_init'? [-Wimplicit-function-declaration]
'Output/xxx_s132_nrf52832 Debug/Obj/SEGGER_RTT.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/SEGGER_RTT_Syscalls_SES.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/SEGGER_RTT_printf.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/ble_advdata.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/ble_advertising.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/ble_conn_params.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/ble_conn_state.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/ble_srv_common.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/gatt_cache_manager.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/gatts_cache_manager.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/id_manager.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/nrf_ble_gatt.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/nrf_ble_qwr.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/peer_data_storage.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/peer_database.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/peer_id.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/peer_manager.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/pm_buffer.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/pm_mutex.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/security_dispatcher.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/security_manager.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/ble_bas.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/nrf_sdh.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/nrf_sdh_ble.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/nrf_sdh_soc.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/cue_service.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/rgb_service.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/bat_service.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/cmd_service.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/cue_driver.o' is up to date
'Output/xxx_s132_nrf52832 Debug/Obj/rgb_driver.o' is up to date
Output/xxx_s132_nrf52832 Debug/Obj/adc_driver.o does not exist.
Compiling ‘adc_driver.c’
nrfx.h
nrfx_saadc.h
nrf_drv_saadc.h
adc_driver.c
'NRFX_TIMER0_INST_IDX' undeclared here (not in a function); did you mean 'NRFX_TIMER3_INST_IDX'?
in definition of macro 'NRFX_CONCAT_3_'
in expansion of macro 'NRFX_CONCAT_3'
in expansion of macro 'NRFX_TIMER_INSTANCE'
in expansion of macro 'NRF_DRV_TIMER_INSTANCE'
Build failed

  • Ok, the issue is on line #19 of the code snippet. It should be:

    NRF_LOG_INFO("V2=%d\r\n", p_event->data.done.p_buffer[1]);

    instead of:

    NRF_LOG_INFO("V2=%d\r\n", p_event->data.done.p_buffer[2]);

    After this change, the code works as expected.

  • Hi,

    I'm using above code to read SAADC. However, I'm experiencing a strange issue. The SAADC works fine when device is not connected to BLE central device. As soon as it's connected, the saadc_callback function stops executing despite the fact that nrf_drv_saadc_sample(); returns NRF_SUCCESSFUL. 

    I have tried changing the priority of SAADC IRQ in the sdk_config.h from 7 to 3, still no success.

    The code otherwise works fine and at device startup, when it's not connected, SAADC reads values correctly.

  • Hi,

    There should not be any link between the BLE connection and the SAADC. Do you do something else when the connection is established? Could it for instance be that you start doing a lot of work in a higher priority interrupt that blocks the SAADC handling? Or some other logic flaw in the app that prevents SAADC sampling? Can you verify (for instance by breakpoints in the SAADC driver) weather the sampling is actually started and weather an interrupt is triggered?

Related