STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_adc.h
Go to the documentation of this file.
00001 
00023 /* Define to prevent recursive inclusion -------------------------------------*/
00024 #ifndef __STM32F10x_ADC_H
00025 #define __STM32F10x_ADC_H
00026 
00027 #ifdef __cplusplus
00028  extern "C" {
00029 #endif
00030 
00031 /* Includes ------------------------------------------------------------------*/
00032 #include "stm32f10x.h"
00033 
00050 typedef struct
00051 {
00052   uint32_t ADC_Mode;                      
00056   FunctionalState ADC_ScanConvMode;       
00060   FunctionalState ADC_ContinuousConvMode; 
00064   uint32_t ADC_ExternalTrigConv;          
00068   uint32_t ADC_DataAlign;                 
00071   uint8_t ADC_NbrOfChannel;               
00074 }ADC_InitTypeDef;
00083 #define IS_ADC_ALL_PERIPH(PERIPH) (((PERIPH) == ADC1) || \
00084                                    ((PERIPH) == ADC2) || \
00085                                    ((PERIPH) == ADC3))
00086 
00087 #define IS_ADC_DMA_PERIPH(PERIPH) (((PERIPH) == ADC1) || \
00088                                    ((PERIPH) == ADC3))
00089 
00094 #define ADC_Mode_Independent                       ((uint32_t)0x00000000)
00095 #define ADC_Mode_RegInjecSimult                    ((uint32_t)0x00010000)
00096 #define ADC_Mode_RegSimult_AlterTrig               ((uint32_t)0x00020000)
00097 #define ADC_Mode_InjecSimult_FastInterl            ((uint32_t)0x00030000)
00098 #define ADC_Mode_InjecSimult_SlowInterl            ((uint32_t)0x00040000)
00099 #define ADC_Mode_InjecSimult                       ((uint32_t)0x00050000)
00100 #define ADC_Mode_RegSimult                         ((uint32_t)0x00060000)
00101 #define ADC_Mode_FastInterl                        ((uint32_t)0x00070000)
00102 #define ADC_Mode_SlowInterl                        ((uint32_t)0x00080000)
00103 #define ADC_Mode_AlterTrig                         ((uint32_t)0x00090000)
00104 
00105 #define IS_ADC_MODE(MODE) (((MODE) == ADC_Mode_Independent) || \
00106                            ((MODE) == ADC_Mode_RegInjecSimult) || \
00107                            ((MODE) == ADC_Mode_RegSimult_AlterTrig) || \
00108                            ((MODE) == ADC_Mode_InjecSimult_FastInterl) || \
00109                            ((MODE) == ADC_Mode_InjecSimult_SlowInterl) || \
00110                            ((MODE) == ADC_Mode_InjecSimult) || \
00111                            ((MODE) == ADC_Mode_RegSimult) || \
00112                            ((MODE) == ADC_Mode_FastInterl) || \
00113                            ((MODE) == ADC_Mode_SlowInterl) || \
00114                            ((MODE) == ADC_Mode_AlterTrig))
00115 
00123 #define ADC_ExternalTrigConv_T1_CC1                ((uint32_t)0x00000000) 
00124 #define ADC_ExternalTrigConv_T1_CC2                ((uint32_t)0x00020000) 
00125 #define ADC_ExternalTrigConv_T2_CC2                ((uint32_t)0x00060000) 
00126 #define ADC_ExternalTrigConv_T3_TRGO               ((uint32_t)0x00080000) 
00127 #define ADC_ExternalTrigConv_T4_CC4                ((uint32_t)0x000A0000) 
00128 #define ADC_ExternalTrigConv_Ext_IT11_TIM8_TRGO    ((uint32_t)0x000C0000) 
00130 #define ADC_ExternalTrigConv_T1_CC3                ((uint32_t)0x00040000) 
00131 #define ADC_ExternalTrigConv_None                  ((uint32_t)0x000E0000) 
00133 #define ADC_ExternalTrigConv_T3_CC1                ((uint32_t)0x00000000) 
00134 #define ADC_ExternalTrigConv_T2_CC3                ((uint32_t)0x00020000) 
00135 #define ADC_ExternalTrigConv_T8_CC1                ((uint32_t)0x00060000) 
00136 #define ADC_ExternalTrigConv_T8_TRGO               ((uint32_t)0x00080000) 
00137 #define ADC_ExternalTrigConv_T5_CC1                ((uint32_t)0x000A0000) 
00138 #define ADC_ExternalTrigConv_T5_CC3                ((uint32_t)0x000C0000) 
00140 #define IS_ADC_EXT_TRIG(REGTRIG) (((REGTRIG) == ADC_ExternalTrigConv_T1_CC1) || \
00141                                   ((REGTRIG) == ADC_ExternalTrigConv_T1_CC2) || \
00142                                   ((REGTRIG) == ADC_ExternalTrigConv_T1_CC3) || \
00143                                   ((REGTRIG) == ADC_ExternalTrigConv_T2_CC2) || \
00144                                   ((REGTRIG) == ADC_ExternalTrigConv_T3_TRGO) || \
00145                                   ((REGTRIG) == ADC_ExternalTrigConv_T4_CC4) || \
00146                                   ((REGTRIG) == ADC_ExternalTrigConv_Ext_IT11_TIM8_TRGO) || \
00147                                   ((REGTRIG) == ADC_ExternalTrigConv_None) || \
00148                                   ((REGTRIG) == ADC_ExternalTrigConv_T3_CC1) || \
00149                                   ((REGTRIG) == ADC_ExternalTrigConv_T2_CC3) || \
00150                                   ((REGTRIG) == ADC_ExternalTrigConv_T8_CC1) || \
00151                                   ((REGTRIG) == ADC_ExternalTrigConv_T8_TRGO) || \
00152                                   ((REGTRIG) == ADC_ExternalTrigConv_T5_CC1) || \
00153                                   ((REGTRIG) == ADC_ExternalTrigConv_T5_CC3))
00154 
00162 #define ADC_DataAlign_Right                        ((uint32_t)0x00000000)
00163 #define ADC_DataAlign_Left                         ((uint32_t)0x00000800)
00164 #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \
00165                                   ((ALIGN) == ADC_DataAlign_Left))
00166 
00174 #define ADC_Channel_0                               ((uint8_t)0x00)
00175 #define ADC_Channel_1                               ((uint8_t)0x01)
00176 #define ADC_Channel_2                               ((uint8_t)0x02)
00177 #define ADC_Channel_3                               ((uint8_t)0x03)
00178 #define ADC_Channel_4                               ((uint8_t)0x04)
00179 #define ADC_Channel_5                               ((uint8_t)0x05)
00180 #define ADC_Channel_6                               ((uint8_t)0x06)
00181 #define ADC_Channel_7                               ((uint8_t)0x07)
00182 #define ADC_Channel_8                               ((uint8_t)0x08)
00183 #define ADC_Channel_9                               ((uint8_t)0x09)
00184 #define ADC_Channel_10                              ((uint8_t)0x0A)
00185 #define ADC_Channel_11                              ((uint8_t)0x0B)
00186 #define ADC_Channel_12                              ((uint8_t)0x0C)
00187 #define ADC_Channel_13                              ((uint8_t)0x0D)
00188 #define ADC_Channel_14                              ((uint8_t)0x0E)
00189 #define ADC_Channel_15                              ((uint8_t)0x0F)
00190 #define ADC_Channel_16                              ((uint8_t)0x10)
00191 #define ADC_Channel_17                              ((uint8_t)0x11)
00192 
00193 #define ADC_Channel_TempSensor                      ((uint8_t)ADC_Channel_16)
00194 #define ADC_Channel_Vrefint                         ((uint8_t)ADC_Channel_17)
00195 
00196 #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) == ADC_Channel_0) || ((CHANNEL) == ADC_Channel_1) || \
00197                                  ((CHANNEL) == ADC_Channel_2) || ((CHANNEL) == ADC_Channel_3) || \
00198                                  ((CHANNEL) == ADC_Channel_4) || ((CHANNEL) == ADC_Channel_5) || \
00199                                  ((CHANNEL) == ADC_Channel_6) || ((CHANNEL) == ADC_Channel_7) || \
00200                                  ((CHANNEL) == ADC_Channel_8) || ((CHANNEL) == ADC_Channel_9) || \
00201                                  ((CHANNEL) == ADC_Channel_10) || ((CHANNEL) == ADC_Channel_11) || \
00202                                  ((CHANNEL) == ADC_Channel_12) || ((CHANNEL) == ADC_Channel_13) || \
00203                                  ((CHANNEL) == ADC_Channel_14) || ((CHANNEL) == ADC_Channel_15) || \
00204                                  ((CHANNEL) == ADC_Channel_16) || ((CHANNEL) == ADC_Channel_17))
00205 
00213 #define ADC_SampleTime_1Cycles5                    ((uint8_t)0x00)
00214 #define ADC_SampleTime_7Cycles5                    ((uint8_t)0x01)
00215 #define ADC_SampleTime_13Cycles5                   ((uint8_t)0x02)
00216 #define ADC_SampleTime_28Cycles5                   ((uint8_t)0x03)
00217 #define ADC_SampleTime_41Cycles5                   ((uint8_t)0x04)
00218 #define ADC_SampleTime_55Cycles5                   ((uint8_t)0x05)
00219 #define ADC_SampleTime_71Cycles5                   ((uint8_t)0x06)
00220 #define ADC_SampleTime_239Cycles5                  ((uint8_t)0x07)
00221 #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SampleTime_1Cycles5) || \
00222                                   ((TIME) == ADC_SampleTime_7Cycles5) || \
00223                                   ((TIME) == ADC_SampleTime_13Cycles5) || \
00224                                   ((TIME) == ADC_SampleTime_28Cycles5) || \
00225                                   ((TIME) == ADC_SampleTime_41Cycles5) || \
00226                                   ((TIME) == ADC_SampleTime_55Cycles5) || \
00227                                   ((TIME) == ADC_SampleTime_71Cycles5) || \
00228                                   ((TIME) == ADC_SampleTime_239Cycles5))
00229 
00237 #define ADC_ExternalTrigInjecConv_T2_TRGO           ((uint32_t)0x00002000) 
00238 #define ADC_ExternalTrigInjecConv_T2_CC1            ((uint32_t)0x00003000) 
00239 #define ADC_ExternalTrigInjecConv_T3_CC4            ((uint32_t)0x00004000) 
00240 #define ADC_ExternalTrigInjecConv_T4_TRGO           ((uint32_t)0x00005000) 
00241 #define ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4 ((uint32_t)0x00006000) 
00243 #define ADC_ExternalTrigInjecConv_T1_TRGO           ((uint32_t)0x00000000) 
00244 #define ADC_ExternalTrigInjecConv_T1_CC4            ((uint32_t)0x00001000) 
00245 #define ADC_ExternalTrigInjecConv_None              ((uint32_t)0x00007000) 
00247 #define ADC_ExternalTrigInjecConv_T4_CC3            ((uint32_t)0x00002000) 
00248 #define ADC_ExternalTrigInjecConv_T8_CC2            ((uint32_t)0x00003000) 
00249 #define ADC_ExternalTrigInjecConv_T8_CC4            ((uint32_t)0x00004000) 
00250 #define ADC_ExternalTrigInjecConv_T5_TRGO           ((uint32_t)0x00005000) 
00251 #define ADC_ExternalTrigInjecConv_T5_CC4            ((uint32_t)0x00006000) 
00253 #define IS_ADC_EXT_INJEC_TRIG(INJTRIG) (((INJTRIG) == ADC_ExternalTrigInjecConv_T1_TRGO) || \
00254                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T1_CC4) || \
00255                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_TRGO) || \
00256                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T2_CC1) || \
00257                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T3_CC4) || \
00258                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_TRGO) || \
00259                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4) || \
00260                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_None) || \
00261                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T4_CC3) || \
00262                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T8_CC2) || \
00263                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T8_CC4) || \
00264                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T5_TRGO) || \
00265                                         ((INJTRIG) == ADC_ExternalTrigInjecConv_T5_CC4))
00266 
00274 #define ADC_InjectedChannel_1                       ((uint8_t)0x14)
00275 #define ADC_InjectedChannel_2                       ((uint8_t)0x18)
00276 #define ADC_InjectedChannel_3                       ((uint8_t)0x1C)
00277 #define ADC_InjectedChannel_4                       ((uint8_t)0x20)
00278 #define IS_ADC_INJECTED_CHANNEL(CHANNEL) (((CHANNEL) == ADC_InjectedChannel_1) || \
00279                                           ((CHANNEL) == ADC_InjectedChannel_2) || \
00280                                           ((CHANNEL) == ADC_InjectedChannel_3) || \
00281                                           ((CHANNEL) == ADC_InjectedChannel_4))
00282 
00290 #define ADC_AnalogWatchdog_SingleRegEnable         ((uint32_t)0x00800200)
00291 #define ADC_AnalogWatchdog_SingleInjecEnable       ((uint32_t)0x00400200)
00292 #define ADC_AnalogWatchdog_SingleRegOrInjecEnable  ((uint32_t)0x00C00200)
00293 #define ADC_AnalogWatchdog_AllRegEnable            ((uint32_t)0x00800000)
00294 #define ADC_AnalogWatchdog_AllInjecEnable          ((uint32_t)0x00400000)
00295 #define ADC_AnalogWatchdog_AllRegAllInjecEnable    ((uint32_t)0x00C00000)
00296 #define ADC_AnalogWatchdog_None                    ((uint32_t)0x00000000)
00297 
00298 #define IS_ADC_ANALOG_WATCHDOG(WATCHDOG) (((WATCHDOG) == ADC_AnalogWatchdog_SingleRegEnable) || \
00299                                           ((WATCHDOG) == ADC_AnalogWatchdog_SingleInjecEnable) || \
00300                                           ((WATCHDOG) == ADC_AnalogWatchdog_SingleRegOrInjecEnable) || \
00301                                           ((WATCHDOG) == ADC_AnalogWatchdog_AllRegEnable) || \
00302                                           ((WATCHDOG) == ADC_AnalogWatchdog_AllInjecEnable) || \
00303                                           ((WATCHDOG) == ADC_AnalogWatchdog_AllRegAllInjecEnable) || \
00304                                           ((WATCHDOG) == ADC_AnalogWatchdog_None))
00305 
00313 #define ADC_IT_EOC                                 ((uint16_t)0x0220)
00314 #define ADC_IT_AWD                                 ((uint16_t)0x0140)
00315 #define ADC_IT_JEOC                                ((uint16_t)0x0480)
00316 
00317 #define IS_ADC_IT(IT) ((((IT) & (uint16_t)0xF81F) == 0x00) && ((IT) != 0x00))
00318 
00319 #define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_AWD) || \
00320                            ((IT) == ADC_IT_JEOC))
00321 
00329 #define ADC_FLAG_AWD                               ((uint8_t)0x01)
00330 #define ADC_FLAG_EOC                               ((uint8_t)0x02)
00331 #define ADC_FLAG_JEOC                              ((uint8_t)0x04)
00332 #define ADC_FLAG_JSTRT                             ((uint8_t)0x08)
00333 #define ADC_FLAG_STRT                              ((uint8_t)0x10)
00334 #define IS_ADC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint8_t)0xE0) == 0x00) && ((FLAG) != 0x00))
00335 #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_AWD) || ((FLAG) == ADC_FLAG_EOC) || \
00336                                ((FLAG) == ADC_FLAG_JEOC) || ((FLAG)== ADC_FLAG_JSTRT) || \
00337                                ((FLAG) == ADC_FLAG_STRT))
00338 
00346 #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF)
00347 
00356 #define IS_ADC_OFFSET(OFFSET) ((OFFSET) <= 0xFFF)
00357 
00366 #define IS_ADC_INJECTED_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x4))
00367 
00376 #define IS_ADC_INJECTED_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x4))
00377 
00387 #define IS_ADC_REGULAR_LENGTH(LENGTH) (((LENGTH) >= 0x1) && ((LENGTH) <= 0x10))
00388 
00396 #define IS_ADC_REGULAR_RANK(RANK) (((RANK) >= 0x1) && ((RANK) <= 0x10))
00397 
00406 #define IS_ADC_REGULAR_DISC_NUMBER(NUMBER) (((NUMBER) >= 0x1) && ((NUMBER) <= 0x8))
00407 
00428 void ADC_DeInit(ADC_TypeDef* ADCx);
00429 void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
00430 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
00431 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00432 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00433 void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState);
00434 void ADC_ResetCalibration(ADC_TypeDef* ADCx);
00435 FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx);
00436 void ADC_StartCalibration(ADC_TypeDef* ADCx);
00437 FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx);
00438 void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00439 FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx);
00440 void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number);
00441 void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00442 void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
00443 void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00444 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);
00445 uint32_t ADC_GetDualModeConversionValue(void);
00446 void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00447 void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00448 void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv);
00449 void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00450 void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
00451 FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx);
00452 void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime);
00453 void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length);
00454 void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset);
00455 uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel);
00456 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog);
00457 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold);
00458 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel);
00459 void ADC_TempSensorVrefintCmd(FunctionalState NewState);
00460 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
00461 void ADC_ClearFlag(ADC_TypeDef* ADCx, uint8_t ADC_FLAG);
00462 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT);
00463 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT);
00464 
00465 #ifdef __cplusplus
00466 }
00467 #endif
00468 
00469 #endif /*__STM32F10x_ADC_H */
00470 
00483 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/