在介绍ADC学习经验之前,说一下关于基于库函数STM32开发的一点心得。本质上微处理器的开发都可分为三类函数:寄存器配置函数、主程序和中断服务函数。主程序和中断服务函数下都是用户自定义函数没什么技巧!而寄存器配置函数怎么写方便了。一个好方法就是结合ST提供的example,然后按照时钟,初始化结构体赋值,调用相关底层函数三个步骤!如何不遗漏又快速的做完这几个事情呢?时钟好说,置于初始化结构体和相关底层函数,直接去对应外设底层库头文件查看。以ADC为例可以看到:在/Exported types/ :有两个typedef struct,分别是ADC_InitTyeDef和ADC_CommonInitTyeDef。所以,先要定义两个初始化结构体:ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure;。然后参照其定义去参考手册中找该如何配置,一个个配置下去,既不会漏速度也较快!
ADC学习
这么多配置,参考手册有点看不懂。结合头文件看!
首先是
typedef struct
{
uint32_t ADC_Resolution; /*!< Configures the ADC resolution dual mode.
This parameter can be a value of @ref ADC_resolution */
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_ExternalTrigConvEdge; /*!< Select the external trigger edge and
enable the trigger of a regular group.
This parameter can be a value of
@ref ADC_external_trigger_edge_for_regular_channels_conversion */
uint32_t ADC_ExternalTrigConv; /*!< Select the external event used to trigger
the start of conversion of a regular group.
This parameter can be a value of
@ref ADC_extrenal_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_NbrOfConversion; /*!< Specifies the number of ADC conversions
that will be done using the sequencer for
regular channel group.
This parameter must range from 1 to 16. */
}ADC_InitTypeDef;
将里面的定义一个个对这参考手册看,会容易理解许多。
ADC多重模式:其实就是多个ADC模块有很多引脚是相同的,同时三个ADC模块是独立的,所以可以对同一个引脚采用多个ADC共同工作的方式。这就是ADC_Mode配置的,这些模式如交替模式,规则同时模式等,一般采用多重模式是为了提高采样速率,所以一般是选择多重模式!