这里最不可思议的是不要管理规则通道和注入通道问题
## 2. 打开menuconfig选中ADC外设



```c
/*
示例代码参考电压为3.3V,转换位数为12位。
*/
#include
#include
#define ADC_DEV_NAME “adc1” /* ADC 设备名称 /
#define ADC_DEV_CHANNEL0 0 / ADC 通道 /
#define ADC_DEV_CHANNEL1 1 / ADC 通道 /
#define ADC_DEV_CHANNEL5 5 / ADC 通道 /
#define REFER_VOLTAGE 330 / 参考电压 3.3V,数据精度乘以100保留2位小数*/
#define CONVERT_BITS (1 << 12) /* 转换位数为12位 */
static int adc_vol_sample(int argc, char *argv[])
{
rt_adc_device_t adc_dev;
rt_uint32_t value, vol0,vol1,vol5;
rt_err_t ret = RT_EOK;
/* 查找设备 */
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
if (adc_dev == RT_NULL)
{
rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
return RT_ERROR;
}
/* 使能设备 */
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL0);
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL1);
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL5);
while(1)
{
/* 读取采样值 */
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL0);
/* 转换为对应电压值 */
vol0 = value * REFER_VOLTAGE / CONVERT_BITS;
//rt_kprintf("the voltage is :%d.%02d \n", vol0 / 100, vol0 % 100);
/* 读取采样值 */
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL1);
/* 转换为对应电压值 */
vol1 = value * REFER_VOLTAGE / CONVERT_BITS;
//rt_kprintf("the voltage is :%d.%02d \n", vol1 / 100, vol1 % 100);
rt_thread_delay(500);
/* 读取采样值 */
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL5);
/* 转换为对应电压值 */
vol5 = value * REFER_VOLTAGE / CONVERT_BITS;
rt_kprintf("the voltage is :%d.%02d %d.%02d %d.%02d \n", vol0 / 100, vol0 % 100,vol1 / 100, vol1 % 100,vol5 / 100, vol5 % 100);
rt_thread_delay(500);
}
/* 关闭通道 */
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL0);
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL1);
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(adc_vol_sample, adc voltage convert sample);
