nRF52832芯片使用ADC的代码示例
#define ADC_REF_VOLTAGE_IN_MILLIVOLTS 600 /**< Reference voltage (in millivolts) used by ADC while doing conversion. */
#define ADC_PRE_SCALING_COMPENSATION 6 /**< The ADC is configured to use VDD with a 1/6 gain -> 6x. */
static void adc_init(void)
{
uint32_t err_code;
nrf_drv_adc_config_t config = NRF_DRV_ADC_DEFAULT_CONFIG;
config.reference = NRF_ADC_CONFIG_REF_VBG; // 使用内部1.2V参考电压
config.resolution = NRF_ADC_CONFIG_RES_10BIT; // 分辨率10位
err_code = nrf_drv_adc_init(&config, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_adc_channel_enable(&m_channel_cfg[0]); // 启用ADC通道0
}
static uint16_t get_adc_value(void)
{
uint32_