Hi,Everyone! Now i have the board nrf52832 and i'm trying to get the battery value and send by using saadc. i have read the example of ble_app_proximity and saadc,and i configure it by my thought, here is my configuration:
void Battery_Update(void)
{
nrf_saadc_value_t adc_result;
nrf_saadc_enable();
nrf_saadc_resolution_set(NRF_SAADC_RESOLUTION_10BIT);
nrf_saadc_oversample_set(NRF_SAADC_OVERSAMPLE_DISABLED);
nrf_saadc_channel_config_t config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN2);
ret_code_t err_code = nrf_drv_saadc_channel_init(0, &config);
APP_ERROR_CHECK(err_code);
nrf_saadc_buffer_init(&adc_result, 1);
nrf_delay_us(100);
nrf_saadc_task_trigger(NRF_SAADC_TASK_START);
nrf_saadc_task_trigger(NRF_SAADC_TASK_SAMPLE);
while(nrf_saadc_busy_check());
nrf_saadc_disable();
if(BLE_GetBattery_Level_notify()){
BLE_Battery_Update(&adc_result, 2, NULL);
}
printf("adc_result: %d\r\n", adc_result);
}
this function will be operated per 1s, and the result is:
-
not contected, adc_result: 27248(always this value)
-
contected,but not enable characteristic notify, adc_result: 0(always this value)
-
contected,and enable notify, adc_result is correct.
i'm confused what happen and how to solve it. i need your help! thanks!