stm32F103C8T6将PB10设置为ADC2的初始化以及详细配置函数
时间: 2023-11-28 21:04:38 浏览: 26
以下是将PB10设置为ADC2的初始化和详细配置函数:
```c
void ADC2_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
// 使能GPIOB时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
// 配置GPIOB.10为模拟输入口
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// 使能ADC2时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE);
// ADC2配置
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; // 独立模式
ADC_InitStructure.ADC_ScanConvMode = DISABLE; // 单通道模式
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // 单次转换模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; // 转换由软件触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; // 数据右对齐
ADC_InitStructure.ADC_NbrOfChannel = 1; // 转换通道数1
ADC_Init(ADC2, &ADC_InitStructure);
// 配置ADC2通道10为采样时间为239.5周期
ADC_RegularChannelConfig(ADC2, ADC_Channel_10, 1, ADC_SampleTime_239Cycles5);
// 使能ADC2
ADC_Cmd(ADC2, ENABLE);
// 开启ADC2校准
ADC_ResetCalibration(ADC2);
while(ADC_GetResetCalibrationStatus(ADC2));
ADC_StartCalibration(ADC2);
while(ADC_GetCalibrationStatus(ADC2));
}
```
以上就是将PB10设置为ADC2的初始化和详细配置函数的代码。你可以根据自己的需要进行修改。