stm32f0xx_adc.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_adc.h
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 23-March-2012
  7. * @brief This file contains all the functions prototypes for the ADC firmware
  8. * library
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F0XX_ADC_H
  30. #define __STM32F0XX_ADC_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f0xx.h"
  36. /** @addtogroup STM32F0xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup ADC
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. /**
  44. * @brief ADC Init structure definition
  45. */
  46. typedef struct
  47. {
  48. uint32_t ADC_Resolution; /*!< Selects the resolution of the conversion.
  49. This parameter can be a value of @ref ADC_Resolution */
  50. FunctionalState ADC_ContinuousConvMode; /*!< Specifies whether the conversion is performed in
  51. Continuous or Single mode.
  52. This parameter can be set to ENABLE or DISABLE. */
  53. uint32_t ADC_ExternalTrigConvEdge; /*!< Selects the external trigger Edge and enables the
  54. trigger of a regular group. This parameter can be a value
  55. of @ref ADC_external_trigger_edge_conversion */
  56. uint32_t ADC_ExternalTrigConv; /*!< Defines the external trigger used to start the analog
  57. to digital conversion of regular channels. This parameter
  58. can be a value of @ref ADC_external_trigger_sources_for_channels_conversion */
  59. uint32_t ADC_DataAlign; /*!< Specifies whether the ADC data alignment is left or right.
  60. This parameter can be a value of @ref ADC_data_align */
  61. uint32_t ADC_ScanDirection; /*!< Specifies in which direction the channels will be scanned
  62. in the sequence.
  63. This parameter can be a value of @ref ADC_Scan_Direction */
  64. }ADC_InitTypeDef;
  65. /* Exported constants --------------------------------------------------------*/
  66. /** @defgroup ADC_Exported_Constants
  67. * @{
  68. */
  69. #define IS_ADC_ALL_PERIPH(PERIPH) ((PERIPH) == ADC1)
  70. /** @defgroup ADC_JitterOff
  71. * @{
  72. */
  73. #define ADC_JitterOff_PCLKDiv2 ADC_CFGR2_JITOFFDIV2
  74. #define ADC_JitterOff_PCLKDiv4 ADC_CFGR2_JITOFFDIV4
  75. #define IS_ADC_JITTEROFF(JITTEROFF) (((JITTEROFF) & 0x3FFFFFFF) == (uint32_t)RESET)
  76. /**
  77. * @}
  78. */
  79. /** @defgroup ADC_Resolution
  80. * @{
  81. */
  82. #define ADC_Resolution_12b ((uint32_t)0x00000000)
  83. #define ADC_Resolution_10b ADC_CFGR1_RES_0
  84. #define ADC_Resolution_8b ADC_CFGR1_RES_1
  85. #define ADC_Resolution_6b ADC_CFGR1_RES
  86. #define IS_ADC_RESOLUTION(RESOLUTION) (((RESOLUTION) == ADC_Resolution_12b) || \
  87. ((RESOLUTION) == ADC_Resolution_10b) || \
  88. ((RESOLUTION) == ADC_Resolution_8b) || \
  89. ((RESOLUTION) == ADC_Resolution_6b))
  90. /**
  91. * @}
  92. */
  93. /** @defgroup ADC_external_trigger_edge_conversion
  94. * @{
  95. */
  96. #define ADC_ExternalTrigConvEdge_None ((uint32_t)0x00000000)
  97. #define ADC_ExternalTrigConvEdge_Rising ADC_CFGR1_EXTEN_0
  98. #define ADC_ExternalTrigConvEdge_Falling ADC_CFGR1_EXTEN_1
  99. #define ADC_ExternalTrigConvEdge_RisingFalling ADC_CFGR1_EXTEN
  100. #define IS_ADC_EXT_TRIG_EDGE(EDGE) (((EDGE) == ADC_ExternalTrigConvEdge_None) || \
  101. ((EDGE) == ADC_ExternalTrigConvEdge_Rising) || \
  102. ((EDGE) == ADC_ExternalTrigConvEdge_Falling) || \
  103. ((EDGE) == ADC_ExternalTrigConvEdge_RisingFalling))
  104. /**
  105. * @}
  106. */
  107. /** @defgroup ADC_external_trigger_sources_for_channels_conversion
  108. * @{
  109. */
  110. /* TIM1 */
  111. #define ADC_ExternalTrigConv_T1_TRGO ((uint32_t)0x00000000)
  112. #define ADC_ExternalTrigConv_T1_CC4 ADC_CFGR1_EXTSEL_0
  113. /* TIM2 */
  114. #define ADC_ExternalTrigConv_T2_TRGO ADC_CFGR1_EXTSEL_1
  115. /* TIM3 */
  116. #define ADC_ExternalTrigConv_T3_TRGO ((uint32_t)(ADC_CFGR1_EXTSEL_0 | ADC_CFGR1_EXTSEL_1))
  117. /* TIM15 */
  118. #define ADC_ExternalTrigConv_T15_TRGO ADC_CFGR1_EXTSEL_2
  119. #define IS_ADC_EXTERNAL_TRIG_CONV(CONV) (((CONV) == ADC_ExternalTrigConv_T1_TRGO) || \
  120. ((CONV) == ADC_ExternalTrigConv_T1_CC4) || \
  121. ((CONV) == ADC_ExternalTrigConv_T2_TRGO) || \
  122. ((CONV) == ADC_ExternalTrigConv_T3_TRGO) || \
  123. ((CONV) == ADC_ExternalTrigConv_T15_TRGO))
  124. /**
  125. * @}
  126. */
  127. /** @defgroup ADC_data_align
  128. * @{
  129. */
  130. #define ADC_DataAlign_Right ((uint32_t)0x00000000)
  131. #define ADC_DataAlign_Left ADC_CFGR1_ALIGN
  132. #define IS_ADC_DATA_ALIGN(ALIGN) (((ALIGN) == ADC_DataAlign_Right) || \
  133. ((ALIGN) == ADC_DataAlign_Left))
  134. /**
  135. * @}
  136. */
  137. /** @defgroup ADC_Scan_Direction
  138. * @{
  139. */
  140. #define ADC_ScanDirection_Upward ((uint32_t)0x00000000)
  141. #define ADC_ScanDirection_Backward ADC_CFGR1_SCANDIR
  142. #define IS_ADC_SCAN_DIRECTION(DIRECTION) (((DIRECTION) == ADC_ScanDirection_Upward) || \
  143. ((DIRECTION) == ADC_ScanDirection_Backward))
  144. /**
  145. * @}
  146. */
  147. /** @defgroup ADC_Scan_Direction
  148. * @{
  149. */
  150. #define ADC_DMAMode_OneShot ((uint32_t)0x00000000)
  151. #define ADC_DMAMode_Circular ADC_CFGR1_DMACFG
  152. #define IS_ADC_DMA_MODE(MODE) (((MODE) == ADC_DMAMode_OneShot) || \
  153. ((MODE) == ADC_DMAMode_Circular))
  154. /**
  155. * @}
  156. */
  157. /** @defgroup ADC_analog_watchdog_selection
  158. * @{
  159. */
  160. #define ADC_AnalogWatchdog_Channel_0 ((uint32_t)0x00000000)
  161. #define ADC_AnalogWatchdog_Channel_1 ((uint32_t)0x04000000)
  162. #define ADC_AnalogWatchdog_Channel_2 ((uint32_t)0x08000000)
  163. #define ADC_AnalogWatchdog_Channel_3 ((uint32_t)0x0C000000)
  164. #define ADC_AnalogWatchdog_Channel_4 ((uint32_t)0x10000000)
  165. #define ADC_AnalogWatchdog_Channel_5 ((uint32_t)0x14000000)
  166. #define ADC_AnalogWatchdog_Channel_6 ((uint32_t)0x18000000)
  167. #define ADC_AnalogWatchdog_Channel_7 ((uint32_t)0x1C000000)
  168. #define ADC_AnalogWatchdog_Channel_8 ((uint32_t)0x20000000)
  169. #define ADC_AnalogWatchdog_Channel_9 ((uint32_t)0x24000000)
  170. #define ADC_AnalogWatchdog_Channel_10 ((uint32_t)0x28000000)
  171. #define ADC_AnalogWatchdog_Channel_11 ((uint32_t)0x2C000000)
  172. #define ADC_AnalogWatchdog_Channel_12 ((uint32_t)0x30000000)
  173. #define ADC_AnalogWatchdog_Channel_13 ((uint32_t)0x34000000)
  174. #define ADC_AnalogWatchdog_Channel_14 ((uint32_t)0x38000000)
  175. #define ADC_AnalogWatchdog_Channel_15 ((uint32_t)0x3C000000)
  176. #define ADC_AnalogWatchdog_Channel_16 ((uint32_t)0x40000000)
  177. #define ADC_AnalogWatchdog_Channel_17 ((uint32_t)0x44000000)
  178. #define ADC_AnalogWatchdog_Channel_18 ((uint32_t)0x48000000)
  179. #define IS_ADC_ANALOG_WATCHDOG_CHANNEL(CHANNEL) (((CHANNEL) == ADC_AnalogWatchdog_Channel_0) || \
  180. ((CHANNEL) == ADC_AnalogWatchdog_Channel_1) || \
  181. ((CHANNEL) == ADC_AnalogWatchdog_Channel_2) || \
  182. ((CHANNEL) == ADC_AnalogWatchdog_Channel_3) || \
  183. ((CHANNEL) == ADC_AnalogWatchdog_Channel_4) || \
  184. ((CHANNEL) == ADC_AnalogWatchdog_Channel_5) || \
  185. ((CHANNEL) == ADC_AnalogWatchdog_Channel_6) || \
  186. ((CHANNEL) == ADC_AnalogWatchdog_Channel_7) || \
  187. ((CHANNEL) == ADC_AnalogWatchdog_Channel_8) || \
  188. ((CHANNEL) == ADC_AnalogWatchdog_Channel_9) || \
  189. ((CHANNEL) == ADC_AnalogWatchdog_Channel_10) || \
  190. ((CHANNEL) == ADC_AnalogWatchdog_Channel_11) || \
  191. ((CHANNEL) == ADC_AnalogWatchdog_Channel_12) || \
  192. ((CHANNEL) == ADC_AnalogWatchdog_Channel_13) || \
  193. ((CHANNEL) == ADC_AnalogWatchdog_Channel_14) || \
  194. ((CHANNEL) == ADC_AnalogWatchdog_Channel_15) || \
  195. ((CHANNEL) == ADC_AnalogWatchdog_Channel_16) || \
  196. ((CHANNEL) == ADC_AnalogWatchdog_Channel_17) || \
  197. ((CHANNEL) == ADC_AnalogWatchdog_Channel_18))
  198. /**
  199. * @}
  200. */
  201. /** @defgroup ADC_sampling_times
  202. * @{
  203. */
  204. #define ADC_SampleTime_1_5Cycles ((uint32_t)0x00000000)
  205. #define ADC_SampleTime_7_5Cycles ((uint32_t)0x00000001)
  206. #define ADC_SampleTime_13_5Cycles ((uint32_t)0x00000002)
  207. #define ADC_SampleTime_28_5Cycles ((uint32_t)0x00000003)
  208. #define ADC_SampleTime_41_5Cycles ((uint32_t)0x00000004)
  209. #define ADC_SampleTime_55_5Cycles ((uint32_t)0x00000005)
  210. #define ADC_SampleTime_71_5Cycles ((uint32_t)0x00000006)
  211. #define ADC_SampleTime_239_5Cycles ((uint32_t)0x00000007)
  212. #define IS_ADC_SAMPLE_TIME(TIME) (((TIME) == ADC_SampleTime_1_5Cycles) || \
  213. ((TIME) == ADC_SampleTime_7_5Cycles) || \
  214. ((TIME) == ADC_SampleTime_13_5Cycles) || \
  215. ((TIME) == ADC_SampleTime_28_5Cycles) || \
  216. ((TIME) == ADC_SampleTime_41_5Cycles) || \
  217. ((TIME) == ADC_SampleTime_55_5Cycles) || \
  218. ((TIME) == ADC_SampleTime_71_5Cycles) || \
  219. ((TIME) == ADC_SampleTime_239_5Cycles))
  220. /**
  221. * @}
  222. */
  223. /** @defgroup ADC_thresholds
  224. * @{
  225. */
  226. #define IS_ADC_THRESHOLD(THRESHOLD) ((THRESHOLD) <= 0xFFF)
  227. /**
  228. * @}
  229. */
  230. /** @defgroup ADC_channels
  231. * @{
  232. */
  233. #define ADC_Channel_0 ADC_CHSELR_CHSEL0
  234. #define ADC_Channel_1 ADC_CHSELR_CHSEL1
  235. #define ADC_Channel_2 ADC_CHSELR_CHSEL2
  236. #define ADC_Channel_3 ADC_CHSELR_CHSEL3
  237. #define ADC_Channel_4 ADC_CHSELR_CHSEL4
  238. #define ADC_Channel_5 ADC_CHSELR_CHSEL5
  239. #define ADC_Channel_6 ADC_CHSELR_CHSEL6
  240. #define ADC_Channel_7 ADC_CHSELR_CHSEL7
  241. #define ADC_Channel_8 ADC_CHSELR_CHSEL8
  242. #define ADC_Channel_9 ADC_CHSELR_CHSEL9
  243. #define ADC_Channel_10 ADC_CHSELR_CHSEL10
  244. #define ADC_Channel_11 ADC_CHSELR_CHSEL11
  245. #define ADC_Channel_12 ADC_CHSELR_CHSEL12
  246. #define ADC_Channel_13 ADC_CHSELR_CHSEL13
  247. #define ADC_Channel_14 ADC_CHSELR_CHSEL14
  248. #define ADC_Channel_15 ADC_CHSELR_CHSEL15
  249. #define ADC_Channel_16 ADC_CHSELR_CHSEL16
  250. #define ADC_Channel_17 ADC_CHSELR_CHSEL17
  251. #define ADC_Channel_18 ADC_CHSELR_CHSEL18
  252. #define ADC_Channel_TempSensor ((uint32_t)ADC_Channel_16)
  253. #define ADC_Channel_Vrefint ((uint32_t)ADC_Channel_17)
  254. #define ADC_Channel_Vbat ((uint32_t)ADC_Channel_18)
  255. #define IS_ADC_CHANNEL(CHANNEL) (((CHANNEL) != (uint32_t)RESET) && (((CHANNEL) & 0xFFF80000) == (uint32_t)RESET))
  256. /**
  257. * @}
  258. */
  259. /** @defgroup ADC_interrupts_definition
  260. * @{
  261. */
  262. #define ADC_IT_ADRDY ADC_IER_ADRDYIE
  263. #define ADC_IT_EOSMP ADC_IER_EOSMPIE
  264. #define ADC_IT_EOC ADC_IER_EOCIE
  265. #define ADC_IT_EOSEQ ADC_IER_EOSEQIE
  266. #define ADC_IT_OVR ADC_IER_OVRIE
  267. #define ADC_IT_AWD ADC_IER_AWDIE
  268. #define IS_ADC_CONFIG_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFFFF60) == (uint32_t)RESET))
  269. #define IS_ADC_GET_IT(IT) (((IT) == ADC_IT_ADRDY) || ((IT) == ADC_IT_EOSMP) || \
  270. ((IT) == ADC_IT_EOC) || ((IT) == ADC_IT_EOSEQ) || \
  271. ((IT) == ADC_IT_OVR) || ((IT) == ADC_IT_AWD))
  272. #define IS_ADC_CLEAR_IT(IT) (((IT) != (uint32_t)RESET) && (((IT) & 0xFFFFFF60) == (uint32_t)RESET))
  273. /**
  274. * @}
  275. */
  276. /** @defgroup ADC_flags_definition
  277. * @{
  278. */
  279. #define ADC_FLAG_ADRDY ADC_ISR_ADRDY
  280. #define ADC_FLAG_EOSMP ADC_ISR_EOSMP
  281. #define ADC_FLAG_EOC ADC_ISR_EOC
  282. #define ADC_FLAG_EOSEQ ADC_ISR_EOSEQ
  283. #define ADC_FLAG_OVR ADC_ISR_OVR
  284. #define ADC_FLAG_AWD ADC_ISR_AWD
  285. #define ADC_FLAG_ADEN ((uint32_t)0x01000001)
  286. #define ADC_FLAG_ADDIS ((uint32_t)0x01000002)
  287. #define ADC_FLAG_ADSTART ((uint32_t)0x01000004)
  288. #define ADC_FLAG_ADSTP ((uint32_t)0x01000008)
  289. #define ADC_FLAG_ADCAL ((uint32_t)0x11000000)
  290. #define IS_ADC_CLEAR_FLAG(FLAG) (((FLAG) != (uint32_t)RESET) && (((FLAG) & 0xEFFFFF60) == (uint32_t)RESET))
  291. #define IS_ADC_GET_FLAG(FLAG) (((FLAG) == ADC_FLAG_ADRDY) || ((FLAG) == ADC_FLAG_EOSMP) || \
  292. ((FLAG) == ADC_FLAG_EOC) || ((FLAG)== ADC_FLAG_EOSEQ) || \
  293. ((FLAG) == ADC_FLAG_AWD) || ((FLAG)== ADC_FLAG_OVR) || \
  294. ((FLAG) == ADC_FLAG_ADEN) || ((FLAG)== ADC_FLAG_ADDIS) || \
  295. ((FLAG) == ADC_FLAG_ADSTART) || ((FLAG)== ADC_FLAG_ADSTP) || \
  296. ((FLAG) == ADC_FLAG_ADCAL))
  297. /**
  298. * @}
  299. */
  300. /**
  301. * @}
  302. */
  303. /* Exported macro ------------------------------------------------------------*/
  304. /* Exported functions ------------------------------------------------------- */
  305. /* Function used to set the ADC configuration to the default reset state *****/
  306. void ADC_DeInit(ADC_TypeDef* ADCx);
  307. /* Initialization and Configuration functions *********************************/
  308. void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct);
  309. void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct);
  310. void ADC_JitterCmd(ADC_TypeDef* ADCx, uint32_t ADC_JitterOff, FunctionalState NewState);
  311. void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  312. /* Power saving functions *****************************************************/
  313. void ADC_AutoPowerOffCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  314. void ADC_WaitModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  315. /* Analog Watchdog configuration functions ************************************/
  316. void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  317. void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,uint16_t LowThreshold);
  318. void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog_Channel);
  319. void ADC_AnalogWatchdogSingleChannelCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  320. /* Temperature Sensor , Vrefint and Vbat management function ******************/
  321. void ADC_TempSensorCmd(FunctionalState NewState);
  322. void ADC_VrefintCmd(FunctionalState NewState);
  323. void ADC_VbatCmd(FunctionalState NewState);
  324. /* Channels Configuration functions *******************************************/
  325. void ADC_ChannelConfig(ADC_TypeDef* ADCx, uint32_t ADC_Channel, uint32_t ADC_SampleTime);
  326. void ADC_ContinuousModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  327. void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  328. void ADC_OverrunModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  329. uint32_t ADC_GetCalibrationFactor(ADC_TypeDef* ADCx);
  330. void ADC_StopOfConversion(ADC_TypeDef* ADCx);
  331. void ADC_StartOfConversion(ADC_TypeDef* ADCx);
  332. uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx);
  333. /* Regular Channels DMA Configuration functions *******************************/
  334. void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState);
  335. void ADC_DMARequestModeConfig(ADC_TypeDef* ADCx, uint32_t ADC_DMARequestMode);
  336. /* Interrupts and flags management functions **********************************/
  337. void ADC_ITConfig(ADC_TypeDef* ADCx, uint32_t ADC_IT, FunctionalState NewState);
  338. FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint32_t ADC_FLAG);
  339. void ADC_ClearFlag(ADC_TypeDef* ADCx, uint32_t ADC_FLAG);
  340. ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint32_t ADC_IT);
  341. void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint32_t ADC_IT);
  342. #ifdef __cplusplus
  343. }
  344. #endif
  345. #endif /*__STM32F0XX_ADC_H */
  346. /**
  347. * @}
  348. */
  349. /**
  350. * @}
  351. */
  352. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/