前面已经看完了RTT的ADC驱动框架和瑞萨适配的RA系列的ADC驱动,剩下的就是实际使用时,我们如何添加ADC类设备了。
芯片ADC资源分配情况
RA6M5支持情况
野火板卡引出情况
即野火板卡上能用作adc的口定义如下:
配置过程
RTT配置添加
Kconfig中添加如下信息:
drv_config.h中之前已经预留ADC配置,因此不需要再添加。
配置代码
在emu中运行menuconfig,打开adc两通道配置。
运行scons --target=mdk5,把dac部分导入工程配置ADC0
打开新生成的keil工程后运行RASC,增加ADC相关配置
配置ADC1
生成代码配置
编译固件
结果验证
\ | / - RT - Thread Operating System / | \ 5.2.0 build Jun 6 2024 22:59:16 2006 - 2024 Copyright by RT-Thread team [D/drv.adc] adc0 init success [D/drv.adc] adc1 init success Hello RT-Thread! msh >dac probe dac1 probe dac1 success msh >dac enable 0 dac1 channel 0 enables success msh >dac Usage: dac probe <dac_name> - probe dac by name dac write <channel> <value> - write dac value on the channel dac disable <channel> - disable dac channel dac enable <channel> - enable dac channel msh >dac write 1 2048 dac1 channel 1 write value is 2048 msh >dac probe dac0 probe dac0 success msh >dac enable 0 dac0 channel 0 enables success msh >dac write 0 1024 dac0 channel 0 write value is 1024 msh >adc probe adc1 probe adc1 success msh >adc enable 20 adc1 channel 20 enables success msh >adc read 20 adc1 channel 20 read value is 0x00000796 msh >adc enable 20 adc1 channel 20 enables success msh >adc read 20 adc1 channel 20 read value is 0x0000040C msh >adc enable 16 adc1 channel 16 enables success msh >adc read 16 adc1 channel 16 read value is 0x00000421 msh >adc enable 16 adc1 channel 16 enables success msh >adc read 16 adc1 channel 16 read value is 0x00000421 msh >adc probe adc0 probe adc0 success msh >adc enable adc0 adc0 channel 0 enables success msh >adc read 0 adc0 channel 0 read value is 0x000007CB msh >adc enable adc0 adc0 channel 0 enables success msh >adc read 0 adc0 channel 0 read value is 0x000007CA msh >adc enable adc0 adc0 channel 0 enables success msh >adc read 0 adc0 channel 0 read value is 0x00000029 msh >adc enable adc0 adc0 channel 0 enables success msh >adc read 0 adc0 channel 0 read value is 0x00000029 msh >adc enable 1 adc0 channel 1 enables success msh >adc read 1 adc0 channel 1 read value is 0x00000745 msh >adc enable 1 adc0 channel 1 enables success msh >adc read 1 adc0 channel 1 read value is 0x000003AE msh >adc enable 2 adc0 channel 2 enables success msh >adc read 2 adc0 channel 2 read value is 0x00000432 msh >adc enable 3 adc0 channel 3 enables success msh >adc read 3 adc0 channel 3 read value is 0x00000435 msh >adc enable 6 adc0 channel 6 enables success msh >adc read 6 adc0 channel 6 read value is 0x00000445 msh >adc enable 7 adc0 channel 7 enables success msh >adc read 7 adc0 channel 7 read value is 0x0000040B msh >adc enable 8 adc0 channel 8 enables success msh >adc read 8 adc0 channel 8 read value is 0x00000407 msh >adc enable 9 adc0 channel 9 enables success msh >adc read 9 adc0 channel 9 read value is 0x00000407 msh >adc enable 10 adc0 channel 10 enables success msh >adc read 10 adc0 channel 10 read value is 0x00000405 msh >
运行过程讲解:
预先将dac1输出2048,对应电压值为1.65V左右
预先将dac0输出1024,对应电压值为0.82V左右
将杜邦线在dac1(dac0)与待测adc口之间短接,并测试读取到的数据,可以看到跳接至dac1时,读取到的数值在0x800左右,跳接至dac0时,读取到的值在0x400左右,与预期的接近
由于adc0 channel0接到了电位器上,因此直接读取电压值,之后旋转旋钮,再次读取电压值,此时可发现读取到的数值发生变化,满足预期。
另外,由于J12座子是母头座子,刚好手头上暂时无对应的公头杜邦线,因此J12上几个adc口未测试
总结
至此,启明6M5 ADC驱动部分的适配已经完毕,此方法其实不限于启明6M5,理论上所有RA系列的芯片都可以按照此方法进行驱动层的适配。