Hi,
I want to get Battery ADC Value.
So. I simply used nrf_drv_saadc_sample_convert() function.
At first I thought it was the right value,
Later, I found that the wrong value was coming out.
If you supply 1.5v, the value should be over 400, but less than 100.
CODE:
// ADC setting void saadc_callback(nrf_drv_saadc_evt_t const * p_event) { //ret_code_t err_code; //err_code = nrf_drv_saadc_sample_convert(0, &m_battery); //APP_ERROR_CHECK(err_code); } static void bat_timeout_handler(void * p_context) { UNUSED_PARAMETER(p_context); ret_code_t err_code; // get ADV value err_code = nrf_drv_saadc_sample_convert(0, &m_battery); APP_ERROR_CHECK(err_code); // (%)percent change formula uint8_t percent = ((m_battery-MIN_ADC)/DIF_ADC)*100; if(percent >= 100) { percent = 100; } NRF_LOG_INFO("ADC : %d%",m_battery); NRF_LOG_INFO("battery : %d%",percent); // send (%)percent value err_code = ble_bas_battery_level_update(&m_bas, percent, BLE_CONN_HANDLE_ALL); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_RESOURCES) && (err_code != NRF_ERROR_BUSY) && (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)) { APP_ERROR_HANDLER(err_code); } } static void saadc_init(void) { ret_code_t err_code; #if TEST nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(ARDUINO_A0_PIN); #else // SAADC configuration struct and pin setting nrf_saadc_channel_config_t channel_config = NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(BAT_ADC_IN); #endif // SAADC struct init and register SAADC evnet handler err_code = nrf_drv_saadc_init(NULL, saadc_callback); APP_ERROR_CHECK(err_code); // SAADC channel init err_code = nrf_drv_saadc_channel_init(0, &channel_config); APP_ERROR_CHECK(err_code); }
Let me know what's wrong.
Thank you.
(softdevice Ver : 6.1.1, SDK Ver : 15.2.0, Testboard : nRF52-DK)