STM32的ADC模块的架构分析在这里,这里只记怎么用。
目录
1. ADC端口映射
ADC肯定要外部输入信号的,通过IO口进行采集,IO与ADC通道的对应关系如下:
2. 配置
2.1 配置步骤
- 开启需要用到的ADCx时钟和对应的IO时钟
- ADC模块和GPIO模块都在APB2时钟下
- void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState);
- 配置ADCx预分频器分频系数
- void RCC_ADCCLKConfig(uint32_t RCC_PCLK2);
- 配置需要用到的对应IO设置为模拟输入
- void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
- 复位ADCx寄存器
- void ADC_DeInit(ADC_TypeDef* ADCx);
- 配置ADCx参数
- void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
typedef struct { uint32_t ADC_Mode; /*!< Configures the ADC to operate in independent or dual mode. This parameter can be a value of @ref ADC_mode */ FunctionalState ADC_ScanConvMode; /*!< Specifies whether the conversion is performed in Scan (multichannels) or Single (one channel) mode. This parameter can be set to ENABLE or DISABLE */ FunctionalState ADC_ContinuousConvMode; /*!< Specifies whether the conversion is performed in Continuous or Single mode. This parameter can be set to ENABLE or DISABLE. */ uint32_t ADC_ExternalTrigConv; /*!< Defines the external trigger used to start the analog to digital conversion of regular channels. This parameter can be a value of @ref ADC_external_trigger_sources_for_regular_channels_conversion */ uint32_t ADC_DataAlign; /*!< Specifies whether the ADC data alignment is left or right. This parameter can be a value of @ref ADC_data_align */ uint8_t ADC_NbrOfChannel; /*!< Specifies the number of ADC channels that will be converted us