笔记-IMX6ULL ADC采集

1、打开设备树arch/arm/boot/dts/imx6ull-xxx.dts,xxx对应自己的板子,找到对应的代码片,若没有,自行添加:
regulator设置参考

   reg_vref_3v3: regulator@2 {
			compatible = "regulator-fixed";
			regulator-name = "vref-3v3";
			regulator-min-microvolt = <3300000>;
			regulator-max-microvolt = <3300000>;
		};	
&adc1 {
	pinctrl-names = "default";
	pinctrl-0 = <&pinctrl_adc1>;
	vref-supply = <®_vref_3v3>;
	num-channels = <2>; //此参数为ADC的通道,扫描2个通道,0-1
	status = "okay";
};

2、因为是将tsc引脚作为ADC功能,所以tsc引脚则不能作为tsc功能,需将此功能屏蔽:

&tsc{
......
        status = "disabled";
};

原本status = “okay”,需将其改为disabled
3、参考其他功能的管脚定义,添加tsc的ADC管脚定义:

pinctrl_adc1: adc1grp {
	fsl,pins = <                                          
		MX6UL_PAD_GPIO1_IO01__GPIO1_IO01              0xb0      
	>;
	/其它ADC引脚...
      };

4、对应的imx6ull.dtsi文件如下定义

adc1: adc@02198000 {
compatible = "fsl,imx6ul-adc", "fsl,vf610-adc";
reg = <0x02198000 0x4000>;
interrupts = ;
clocks = <&clks IMX6UL_CLK_ADC1>;
num-channels = <2>;
clock-names = "adc";
status = "disabled";
};

5、添加成功之后重新烧写设备树tq-imx6ull.dtb,tsc引脚即为ADC功能,可测试是否可读取ADC的值

adc设备驱动目录:

cat /sys/devices/platform/soc/2100000.aips-bus/2198000.adc/iio:device0/in_voltage1_raw

附:
自定义设置通道数

对于使用,仅ADC1输入3、4、6和7可以尝试下一个更改:
在imx6ull.dtsi中更改num-channels = 4:

adc1:adc @ 02198000 {
  ...
  num-channels = <4>;

修改 drivers/iio/adc/imx7d_adc.c

static const struct iio_chan_spec vf610_adc_iio_channels[] = {
    VF610_ADC_CHAN(3, IIO_VOLTAGE),
    VF610_ADC_CHAN(4, IIO_VOLTAGE),
    VF610_ADC_CHAN(6, IIO_VOLTAGE),
    VF610_ADC_CHAN(7, IIO_VOLTAGE),
          ...

你可能感兴趣的:(嵌入式软件)