管理员
最后登录1970-1-1
在线时间 小时
注册时间2013-3-25
|
STM32F1 系列的ADC 库函数如下,也不是很多,一个上午就可以看完。- void ADC_DeInit(ADC_TypeDef* ADCx);
- void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
- void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
- void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState);
- void ADC_ResetCalibration(ADC_TypeDef* ADCx);
- FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx);
- void ADC_StartCalibration(ADC_TypeDef* ADCx);
- FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx);
- void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx);
- void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number);
- void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
- void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);
- uint32_t ADC_GetDualModeConversionValue(void);
- void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv);
- void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx);
- void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
- void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length);
- void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset);
- uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel);
- void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog);
- void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
- void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel);
- void ADC_TempSensorVrefintCmd(FunctionalState NewState);
- FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
- void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
- ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT);
- void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT);
复制代码
每一个库函数我都看了下,也对着手册的寄存器看过库的底层,总体上都可以理解,没有什么大问题,
但是有个:设置注入通道转换偏移值这个函数不知道用来干嘛,对应的寄存器是:ADC注入通道数据偏移寄存器x (ADC_JOFRx)(x=1..4)
函数原型如下:
- /**
- * @brief Set the injected channels conversion value offset
- * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
- * @param ADC_InjectedChannel: the ADC injected channel to set its offset.
- * This parameter can be one of the following values:
- * @arg ADC_InjectedChannel_1: Injected Channel1 selected
- * @arg ADC_InjectedChannel_2: Injected Channel2 selected
- * @arg ADC_InjectedChannel_3: Injected Channel3 selected
- * @arg ADC_InjectedChannel_4: Injected Channel4 selected
- * @param Offset: the offset value for the selected ADC injected channel
- * This parameter must be a 12bit value.
- * @retval None
- */
- void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset)
- {
- __IO uint32_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
- assert_param(IS_ADC_OFFSET(Offset));
-
- tmp = (uint32_t)ADCx;
- tmp += ADC_InjectedChannel;
-
- /* Set the selected injected channel data offset */
- *(__IO uint32_t *) tmp = (uint32_t)Offset;
- }
复制代码 在手册中:JOFR这个寄存器的描述是:当转换注入通道时,这些位定义了用于从原始转换数据中减去的数值。转换的结果可以在
ADC_JDRx寄存器中读出。我们可以知道,注入通道的转换结果是直接从JDR寄存器读取的,JOFR里面的值并没有影响到转换结果,
那么JOFR寄存器设置的偏移值到底用在什么场合? 暂时做个笔记备注下。
至于注入通道的转换值有没有被JOFR寄存器里面设置的值影响到,我们可以从下面这个库函数里面了解:- uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel)
- {
- __IO uint32_t tmp = 0;
-
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
- tmp = (uint32_t)ADCx;
- tmp += ADC_InjectedChannel + JDR_Offset;
-
- /* Returns the selected injected channel conversion data value */
- return (uint16_t) (*(__IO uint32_t*) tmp);
- }
复制代码 ADC注入通道数据偏移寄存器JOFR的偏移是:0X14~0X20,对应着四个注入通道,分别是:
- #define ADC_InjectedChannel_1 ((uint8_t)0x14)
- #define ADC_InjectedChannel_2 ((uint8_t)0x18)
- #define ADC_InjectedChannel_3 ((uint8_t)0x1C)
- #define ADC_InjectedChannel_4 ((uint8_t)0x20)
复制代码 ADC 注入数据寄存器JDR的地址偏移是:0X3C~0X48,注入通道转换的值就存在这个寄存器当中。
在:返回注入通道转换值的库函数:uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel)中
有如下代码:
- tmp = (uint32_t)ADCx;
- tmp += ADC_InjectedChannel + JDR_Offset;
-
- /* Returns the selected injected channel conversion data value */
- return (uint16_t) (*(__IO uint32_t*) tmp);
复制代码 其他JDR_Offset是一个宏,定义为:0x28,0X28其实就是JDR和JOFR这两个寄存器地址偏移的差值,
JDR的地址偏移为:0X3C~0X48,JOFR的地址偏移为:0X14~0X20,(0X3C~0X48)-(0X14~0X20)= 0X28。
最后返回的也就是JDR寄存器里面的值,即:(ADCx+0X3C~0X48),也就是注入通道转换的值。所以,JOFR,你到底是干什么的?
|
|