RT_Thread学习笔记(4) ADC使用
1.引脚
板子上的引脚为PC1,查阅手册:

123随便选,所以我选择ADC2_IN11。
2.Cubemx配置
随便点点,然后生成就完事了

Copy目录下生成的代码

3.Rt_thread设置
还是去setting那把ADC开启

RTT也提供了操作步骤,在board.h里有
/** if you want to use adc you can use the following instructions.
*
* STEP 1, open adc driver framework support in the RT-Thread Settings file
*
* STEP 2, define macro related to the adc
* such as #define BSP_USING_ADC1
*
* STEP 3, copy your adc init function from stm32xxxx_hal_msp.c generated by stm32cubemx to the end of board.c file
* such as void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
*
* STEP 4, modify your stm32xxxx_hal_config.h file to support adc peripherals. define macro related to the peripherals
* such as #define HAL_ADC_MODULE_ENABLED
*
*/
照着操作一下:

把Cubemx生成的代码复制到board,c里面
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)
{
GPIO_InitTypeDef GPIO_InitStruct = {
0};
if(hadc->Instance==ADC2)

本文档详细介绍了如何在RT-Thread操作系统中配置和使用STM32的ADC模块进行电压测量。通过Cubemx生成配置代码,并将其整合到RT-Thread中,实现了电压值的读取和转换。
最低0.47元/天 解锁文章
1170

被折叠的 条评论
为什么被折叠?



