大家好,
我使用的是 STM32G474RE,STM32CubeMX 版本是 6.5.0。
当ADC5使能温度传感器、Vref和Vbat通道时,STM32CubeMX会在MX_ADC5_Init函数(LL库)中生成代码:
- /** Configure Regular Channel
- */
- LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_VREFINT);
- LL_ADC_SetChannelSamplingtime(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
- LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SINGLE_ENDED);
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_VREFINT);
- /** Configure Regular Channel
- */
- LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_TEMPSENSOR_ADC5);
- LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SAMPLINGTIME_2CYCLES_5);
- LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SINGLE_ENDED);
- /** Configure Regular Channel
- */
- LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_VBAT);
- LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
- LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SINGLE_ENDED);
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_VBAT);
的
我认为第 12 行之后缺少一行代码:
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_TEMPSENSOR);
另外,调用LL_ADC_SetCommonPathInternalCh()函数会清除之前的状态,所以我觉得应该修改为这段代码:
- /** Configure Regular Channel
- */
- LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_VREFINT);
- LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
- LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VREFINT, LL_ADC_SINGLE_ENDED);
- /** Configure Regular Channel
- */
- LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_TEMPSENSOR_ADC5);
- LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SAMPLINGTIME_2CYCLES_5);
- LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_TEMPSENSOR_ADC5, LL_ADC_SINGLE_ENDED);
- /** Configure Regular Channel
- */
- LL_ADC_REG_SetSequencerRanks(ADC5, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_VBAT);
- LL_ADC_SetChannelSamplingTime(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SAMPLINGTIME_2CYCLES_5);
- LL_ADC_SetChannelSingleDiff(ADC5, LL_ADC_CHANNEL_VBAT, LL_ADC_SINGLE_ENDED);
- LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(ADC5), LL_ADC_PATH_INTERNAL_VBAT|LL_ADC_PATH_INTERNAL_VREFINT|LL_ADC_PATH_ INTERNAL_TEMPSENSOR);
0
|
|
|
|