通过 ADC 设备采样电压值并转换为数值
更多...
通过 ADC 设备采样电压值并转换为数值
源码
#include <rtthread.h>
#include <rtdevice.h>
#define ADC_DEV_NAME "adc1"
#define ADC_DEV_CHANNEL 5
static int adc_vol_sample(int argc, char *argv[])
{
rt_adc_device_t adc_dev;
{
rt_kprintf(
"adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
}
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
vol = value * 330 / 4096;
rt_kprintf(
"the voltage is :%d.%02d \n", vol / 100, vol % 100);
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
return ret;
}