Hi, I'm testing my custom PCB that uses nRF52832-QFAA and a single cell Li-Ion battery (3 ~ 4.2V).
Additionally, I use
-
SDK 12.1
-
SoftDevice S132 v3
-
HRS example and SAADC example
void saadc_init(void) {
ret_code_t err_code;
nrf_saadc_channel_config_t channel_config =
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(nrf_drv_saadc_gpio_to_ain(4)); // for AIN2
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(2, &channel_config);
APP_ERROR_CHECK(err_code);
// ...
I think the SAADC example
uses an interrupt that is triggered when the buffer is filled with samples.
Whereas I want to sample the values using the timer.
My objective is to the send battery level after reading the ADC value via BAS (Battery Service) using the timer.
err_code = app_timer_create(&m_battery_timer_id,
APP_TIMER_MODE_REPEATED,
battery_level_meas_timeout_handler); // ...
static void battery_level_meas_timeout_handler(void * p_context){
UNUSED_PARAMETER(p_context);
battery_level_update(); // I want to read the ADC value here!
-
Have I correctly configured
AIN2
?NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(nrf_drv_saadc_gpio_to_ain(4)); err_code = nrf_drv_saadc_channel_init(2, &channel_config); // Are they the correct number?
// Added 2017.06.01
As you said about if you only use one SAADC channel, you can use channel 0
,
yes. I use only one, so I will change it. Thanks for checking it out.
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(nrf_drv_saadc_gpio_to_ain(4)); // for AIN2
I used that code, not NRF_SAADC_INPUT_AIN2
.
If I use NRF_SAADC_INPUT_AIN2
, different values (42, 30, 35, ...) are read.
After typing 4, the values of the battery divided voltages are read.
- Is there a function that reads the buffer of the ADC?
If that exists, can I use it inside the timeout handler? Or should I call it outside the handler?
-Best Regards, MANGO