STM32F401的内置温度的ADC转换流程LL库
时间: 2024-05-07 10:16:18 浏览: 202
以下是STM32F401的内置温度的ADC转换流程LL库:
1. 初始化ADC模块
```
//初始化ADC模块
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_5, LL_GPIO_MODE_ANALOG);
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_ADC1);
LL_ADC_SetClockPrescaler(ADC1, LL_ADC_CLOCK_SYNC_PCLK_DIV2);
LL_ADC_SetResolution(ADC1, LL_ADC_RESOLUTION_12B);
LL_ADC_SetDataAlignment(ADC1, LL_ADC_DATA_ALIGN_RIGHT);
LL_ADC_SetSamplingTimeCommonChannels(ADC1, LL_ADC_SAMPLINGTIME_COMMON_1,
LL_ADC_SAMPLINGTIME_239CYCLES_5);
LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_TEMPSENSOR,
LL_ADC_SAMPLINGTIME_239CYCLES_5);
LL_ADC_EnableInternalRegulator(ADC1);
LL_ADC_StartCalibration(ADC1);
while(LL_ADC_IsCalibrationOnGoing(ADC1));
LL_ADC_Enable(ADC1);
while(!LL_ADC_IsActiveFlag_ADRDY(ADC1));
```
2. 配置ADC通道
```
//配置ADC通道
LL_ADC_REG_SetTriggerSource(ADC1, LL_ADC_REG_TRIG_SOFTWARE);
LL_ADC_REG_SetContinuousMode(ADC1, LL_ADC_REG_CONV_SINGLE);
LL_ADC_REG_SetSequencerLength(ADC1, LL_ADC_REG_SEQ_SCAN_DISABLE);
LL_ADC_REG_SetOverrun(ADC1, LL_ADC_REG_OVR_DATA_OVERWRITTEN);
LL_ADC_REG_SetDMATransfer(ADC1, LL_ADC_REG_DMA_TRANSFER_NONE);
LL_ADC_EnableIT_EOC(ADC1);
```
3. 启动ADC转换
```
//启动ADC转换
LL_ADC_REG_StartConversion(ADC1);
while(!LL_ADC_IsActiveFlag_EOC(ADC1));
```
4. 读取ADC转换结果
```
//读取ADC转换结果
uint16_t adc_value = LL_ADC_REG_ReadConversionData12(ADC1);
```
5. 计算温度值
```
//计算温度值
float temperature = ((float)adc_value * 3300.0f / 4095.0f - 760.0f) / 2.5f + 25.0f;
```
阅读全文