1、ADC的初始化,因为需要采集两个电路的电压,包括电池电压和DC5V的电压,因此需要初始化两个ADC句柄
void HwADCInit(void)
{
ADC_init();
ADC_Params_init(&ADCparams);
ADC5VHandle = ADC_open(CC2650_LAUNCHXL_ADC3, &ADCparams);
ADCBbatteryHandle = ADC_open(CC2650_LAUNCHXL_ADC1, &ADCparams);
if(ADC5VHandle!=NULL)
{
ADC_close(ADCBbatteryHandle);
}
}
2、ADC电压的读取,
int16_t HwADCRead(ADC_Handle ADCHandle)
{
int16_t res;
uint16_t adcValue;
res = ADC_convert(ADCBbatteryHandle, &adcValue); //获取 ADC 值
if (res == ADC_STATUS_SUCCESS)
{
return adcValue;
}
else
return -1;
}