原因是通道号对应到实际hal库中的通道名不正确
STM32L431芯片中内部VREFIN通道是0,如果直接使用0号通道去读取将获取错误的adc值,需要修改drv_adc.c中的stm32_adc_get_channel函数,将返回的通道号改为ADC_CHANNEL_VREFINT
17通道对应ADC_CHANNEL_TEMPSENSOR
18通道对应ADC_CHANNEL_VBAT
static rt_uint32_t stm32_adc_get_channel(rt_uint32_t channel) { rt_uint32_t stm32_channel = 0; switch (channel) { case 0: stm32_channel = ADC_CHANNEL_VREFINT; break; case 1: stm32_channel = ADC_CHANNEL_1; break; case 2: stm32_channel = ADC_CHANNEL_2; break; case 3: stm32_channel = ADC_CHANNEL_3; break; case 4: stm32_channel = ADC_CHANNEL_4; break; case 5: stm32_channel = ADC_CHANNEL_5; break; case 6: stm32_channel = ADC_CHANNEL_6; break; case 7: stm32_channel = ADC_CHANNEL_7; break; case 8: stm32_channel = ADC_CHANNEL_8; break; case 9: stm32_channel = ADC_CHANNEL_9; break; case 10: stm32_channel = ADC_CHANNEL_10; break; case 11: stm32_channel = ADC_CHANNEL_11; break; case 12: stm32_channel = ADC_CHANNEL_12; break; case 13: stm32_channel = ADC_CHANNEL_13; break; case 14: stm32_channel = ADC_CHANNEL_14; break; case 15: stm32_channel = ADC_CHANNEL_15; break; #ifdef ADC_CHANNEL_16 case 16: stm32_channel = ADC_CHANNEL_16; break; #endif case 17: stm32_channel = ADC_CHANNEL_TEMPSENSOR; break; #ifdef ADC_CHANNEL_18 case 18: stm32_channel = ADC_CHANNEL_VBAT; break; #endif #ifdef ADC_CHANNEL_19 case 19: stm32_channel = ADC_CHANNEL_19; break; #endif } return stm32_channel; }
标签:RT,case,thread,channel,stm32,VBAT,ADC,break,CHANNEL From: https://www.cnblogs.com/arthurly/p/17011686.html