STM32-快速上手ADC

本文介绍了STM32单片机中ADC模块的使用方法,包括ADC端口映射、配置步骤和函数,以及如何启动转换和读取结果。内容涵盖时钟配置、IO设置、ADC参数初始化、校准和数据对齐等关键操作。
摘要由CSDN通过智能技术生成

STM32的ADC模块的架构分析在这里,这里只记怎么用。

目录

1. ADC端口映射

2. 配置

2.1 配置步骤

2.2 配置函数

3.使用

4.源码


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
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值