2 ******************************************************************************
3 * @file stm32f30x_adc.c
4 * @author MCD Application Team
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the Analog to Digital Convertor (ADC) peripheral:
9 * + Initialization and Configuration
10 * + Analog Watchdog configuration
11 * + Temperature Sensor, Vbat & Vrefint (Internal Reference Voltage) management
12 * + Regular Channels Configuration
13 * + Regular Channels DMA Configuration
14 * + Injected channels Configuration
15 * + Interrupts and flags management
16 * + Dual mode configuration
19 ==============================================================================
20 ##### How to use this driver #####
21 ==============================================================================
23 (#) select the ADC clock using the function RCC_ADCCLKConfig()
24 (#) Enable the ADC interface clock using RCC_AHBPeriphClockCmd();
25 (#) ADC pins configuration
26 (++) Enable the clock for the ADC GPIOs using the following function:
27 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOx, ENABLE);
28 (++) Configure these ADC pins in analog mode using GPIO_Init();
29 (#) Configure the ADC conversion resolution, data alignment, external
30 trigger and edge, sequencer lenght and Enable/Disable the continuous mode
31 using the ADC_Init() function.
32 (#) Activate the ADC peripheral using ADC_Cmd() function.
34 *** ADC channels group configuration ***
35 ========================================
37 (+) To configure the ADC channels features, use ADC_Init(), ADC_InjectedInit()
38 and/or ADC_RegularChannelConfig() functions.
39 (+) To activate the continuous mode, use the ADC_ContinuousModeCmd()
41 (+) To activate the Discontinuous mode, use the ADC_DiscModeCmd() functions.
42 (+) To activate the overrun mode, use the ADC_OverrunModeCmd() functions.
43 (+) To activate the calibration mode, use the ADC_StartCalibration() functions.
44 (+) To read the ADC converted values, use the ADC_GetConversionValue()
47 *** DMA for ADC channels features configuration ***
48 ===================================================
50 (+) To enable the DMA mode for ADC channels group, use the ADC_DMACmd() function.
51 (+) To configure the DMA transfer request, use ADC_DMAConfig() function.
55 ******************************************************************************
58 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
60 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
61 * You may not use this file except in compliance with the License.
62 * You may obtain a copy of the License at:
64 * http://www.st.com/software_license_agreement_liberty_v2
66 * Unless required by applicable law or agreed to in writing, software
67 * distributed under the License is distributed on an "AS IS" BASIS,
68 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
69 * See the License for the specific language governing permissions and
70 * limitations under the License.
72 ******************************************************************************
75 /* Includes ------------------------------------------------------------------*/
76 #include "stm32f30x_adc.h"
77 #include "stm32f30x_rcc.h"
79 /** @addtogroup STM32F30x_StdPeriph_Driver
84 * @brief ADC driver modules
88 /* Private typedef -----------------------------------------------------------*/
89 /* Private define ------------------------------------------------------------*/
91 /* CFGR register Mask */
92 #define CFGR_CLEAR_Mask ((uint32_t)0xFDFFC007)
94 /* JSQR register Mask */
95 #define JSQR_CLEAR_Mask ((uint32_t)0x00000000)
98 #define CCR_CLEAR_MASK ((uint32_t)0xFFFC10E0)
100 /* ADC JDRx registers offset */
101 #define JDR_Offset ((uint8_t)0x80)
103 /* Private macro -------------------------------------------------------------*/
104 /* Private variables ---------------------------------------------------------*/
105 /* Private function prototypes -----------------------------------------------*/
106 /* Private functions ---------------------------------------------------------*/
108 /** @defgroup ADC_Private_Functions
112 /** @defgroup ADC_Group1 Initialization and Configuration functions
113 * @brief Initialization and Configuration functions
116 ===============================================================================
117 ##### Initialization and Configuration functions #####
118 ===============================================================================
120 This section provides functions allowing to:
121 (#) Initialize and configure the ADC injected and/or regular channels and dual mode.
122 (#) Management of the calibration process
123 (#) ADC Power-on Power-off
124 (#) Single ended or differential mode
125 (#) Enabling the queue of context and the auto delay mode
126 (#) The number of ADC conversions that will be done using the sequencer for regular
128 (#) Enable or disable the ADC peripheral
135 * @brief Deinitializes the ADCx peripheral registers to their default reset values.
136 * @param ADCx: where x can be 1, 2,3 or 4 to select the ADC peripheral.
139 void ADC_DeInit(ADC_TypeDef
* ADCx
)
141 /* Check the parameters */
142 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
145 if((ADCx
== ADC1
) || (ADCx
== ADC2
))
147 /* Enable ADC1/ADC2 reset state */
148 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC12
, ENABLE
);
149 /* Release ADC1/ADC2 from reset state */
150 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC12
, DISABLE
);
152 else if((ADCx
== ADC3
) || (ADCx
== ADC4
))
154 /* Enable ADC3/ADC4 reset state */
155 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC34
, ENABLE
);
156 /* Release ADC3/ADC4 from reset state */
157 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC34
, DISABLE
);
161 * @brief Initializes the ADCx peripheral according to the specified parameters
162 * in the ADC_InitStruct.
163 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
164 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
165 * the configuration information for the specified ADC peripheral.
168 void ADC_Init(ADC_TypeDef
* ADCx
, ADC_InitTypeDef
* ADC_InitStruct
)
170 uint32_t tmpreg1
= 0;
171 /* Check the parameters */
172 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
173 assert_param(IS_ADC_CONVMODE(ADC_InitStruct
->ADC_ContinuousConvMode
));
174 assert_param(IS_ADC_RESOLUTION(ADC_InitStruct
->ADC_Resolution
));
175 assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct
->ADC_ExternalTrigConvEvent
));
176 assert_param(IS_EXTERNALTRIG_EDGE(ADC_InitStruct
->ADC_ExternalTrigEventEdge
));
177 assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct
->ADC_DataAlign
));
178 assert_param(IS_ADC_OVRUNMODE(ADC_InitStruct
->ADC_OverrunMode
));
179 assert_param(IS_ADC_AUTOINJECMODE(ADC_InitStruct
->ADC_AutoInjMode
));
180 assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct
->ADC_NbrOfRegChannel
));
182 /*---------------------------- ADCx CFGR Configuration -----------------*/
183 /* Get the ADCx CFGR value */
184 tmpreg1
= ADCx
->CFGR
;
186 tmpreg1
&= CFGR_CLEAR_Mask
;
187 /* Configure ADCx: scan conversion mode */
188 /* Set SCAN bit according to ADC_ScanConvMode value */
189 tmpreg1
|= (uint32_t)ADC_InitStruct
->ADC_ContinuousConvMode
|
190 ADC_InitStruct
->ADC_Resolution
|
191 ADC_InitStruct
->ADC_ExternalTrigConvEvent
|
192 ADC_InitStruct
->ADC_ExternalTrigEventEdge
|
193 ADC_InitStruct
->ADC_DataAlign
|
194 ADC_InitStruct
->ADC_OverrunMode
|
195 ADC_InitStruct
->ADC_AutoInjMode
;
197 /* Write to ADCx CFGR */
198 ADCx
->CFGR
= tmpreg1
;
200 /*---------------------------- ADCx SQR1 Configuration -----------------*/
201 /* Get the ADCx SQR1 value */
202 tmpreg1
= ADCx
->SQR1
;
204 tmpreg1
&= ~(uint32_t)(ADC_SQR1_L
);
205 /* Configure ADCx: regular channel sequence length */
206 /* Set L bits according to ADC_NbrOfRegChannel value */
207 tmpreg1
|= (uint32_t) (ADC_InitStruct
->ADC_NbrOfRegChannel
- 1);
208 /* Write to ADCx SQR1 */
209 ADCx
->SQR1
= tmpreg1
;
214 * @brief Fills each ADC_InitStruct member with its default value.
215 * @param ADC_InitStruct : pointer to an ADC_InitTypeDef structure which will be initialized.
218 void ADC_StructInit(ADC_InitTypeDef
* ADC_InitStruct
)
220 /* Reset ADC init structure parameters values */
221 ADC_InitStruct
->ADC_ContinuousConvMode
= DISABLE
;
222 ADC_InitStruct
->ADC_Resolution
= ADC_Resolution_12b
;
223 ADC_InitStruct
->ADC_ExternalTrigConvEvent
= ADC_ExternalTrigConvEvent_0
;
224 ADC_InitStruct
->ADC_ExternalTrigEventEdge
= ADC_ExternalTrigEventEdge_None
;
225 ADC_InitStruct
->ADC_DataAlign
= ADC_DataAlign_Right
;
226 ADC_InitStruct
->ADC_OverrunMode
= DISABLE
;
227 ADC_InitStruct
->ADC_AutoInjMode
= DISABLE
;
228 ADC_InitStruct
->ADC_NbrOfRegChannel
= 1;
232 * @brief Initializes the ADCx peripheral according to the specified parameters
233 * in the ADC_InitStruct.
234 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
235 * @param ADC_InjectInitStruct: pointer to an ADC_InjecInitTypeDef structure that contains
236 * the configuration information for the specified ADC injected channel.
239 void ADC_InjectedInit(ADC_TypeDef
* ADCx
, ADC_InjectedInitTypeDef
* ADC_InjectedInitStruct
)
241 uint32_t tmpreg1
= 0;
242 /* Check the parameters */
243 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
244 assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_InjectedInitStruct
->ADC_ExternalTrigInjecConvEvent
));
245 assert_param(IS_EXTERNALTRIGINJ_EDGE(ADC_InjectedInitStruct
->ADC_ExternalTrigInjecEventEdge
));
246 assert_param(IS_ADC_INJECTED_LENGTH(ADC_InjectedInitStruct
->ADC_NbrOfInjecChannel
));
247 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct
->ADC_InjecSequence1
));
248 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct
->ADC_InjecSequence2
));
249 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct
->ADC_InjecSequence3
));
250 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct
->ADC_InjecSequence4
));
252 /*---------------------------- ADCx JSQR Configuration -----------------*/
253 /* Get the ADCx JSQR value */
254 tmpreg1
= ADCx
->JSQR
;
256 tmpreg1
&= JSQR_CLEAR_Mask
;
257 /* Configure ADCx: Injected channel sequence length, external trigger,
258 external trigger edge and sequences
260 tmpreg1
= (uint32_t) ((ADC_InjectedInitStruct
->ADC_NbrOfInjecChannel
- (uint8_t)1) |
261 ADC_InjectedInitStruct
->ADC_ExternalTrigInjecConvEvent
|
262 ADC_InjectedInitStruct
->ADC_ExternalTrigInjecEventEdge
|
263 (uint32_t)((ADC_InjectedInitStruct
->ADC_InjecSequence1
) << 8) |
264 (uint32_t)((ADC_InjectedInitStruct
->ADC_InjecSequence2
) << 14) |
265 (uint32_t)((ADC_InjectedInitStruct
->ADC_InjecSequence3
) << 20) |
266 (uint32_t)((ADC_InjectedInitStruct
->ADC_InjecSequence4
) << 26));
267 /* Write to ADCx SQR1 */
268 ADCx
->JSQR
= tmpreg1
;
272 * @brief Fills each ADC_InjectedInitStruct member with its default value.
273 * @param ADC_InjectedInitStruct : pointer to an ADC_InjectedInitTypeDef structure which will be initialized.
276 void ADC_InjectedStructInit(ADC_InjectedInitTypeDef
* ADC_InjectedInitStruct
)
278 ADC_InjectedInitStruct
->ADC_ExternalTrigInjecConvEvent
= ADC_ExternalTrigInjecConvEvent_0
;
279 ADC_InjectedInitStruct
->ADC_ExternalTrigInjecEventEdge
= ADC_ExternalTrigInjecEventEdge_None
;
280 ADC_InjectedInitStruct
->ADC_NbrOfInjecChannel
= 1;
281 ADC_InjectedInitStruct
->ADC_InjecSequence1
= ADC_InjectedChannel_1
;
282 ADC_InjectedInitStruct
->ADC_InjecSequence2
= ADC_InjectedChannel_1
;
283 ADC_InjectedInitStruct
->ADC_InjecSequence3
= ADC_InjectedChannel_1
;
284 ADC_InjectedInitStruct
->ADC_InjecSequence4
= ADC_InjectedChannel_1
;
288 * @brief Initializes the ADCs peripherals according to the specified parameters
289 * in the ADC_CommonInitStruct.
290 * @param ADCx: where x can be 1 or 4 to select the ADC peripheral.
291 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
292 * that contains the configuration information for All ADCs peripherals.
295 void ADC_CommonInit(ADC_TypeDef
* ADCx
, ADC_CommonInitTypeDef
* ADC_CommonInitStruct
)
297 uint32_t tmpreg1
= 0;
298 /* Check the parameters */
299 assert_param(IS_ADC_MODE(ADC_CommonInitStruct
->ADC_Mode
));
300 assert_param(IS_ADC_CLOCKMODE(ADC_CommonInitStruct
->ADC_Clock
));
301 assert_param(IS_ADC_DMA_MODE(ADC_CommonInitStruct
->ADC_DMAMode
));
302 assert_param(IS_ADC_DMA_ACCESS_MODE(ADC_CommonInitStruct
->ADC_DMAAccessMode
));
303 assert_param(IS_ADC_TWOSAMPLING_DELAY(ADC_CommonInitStruct
->ADC_TwoSamplingDelay
));
305 if((ADCx
== ADC1
) || (ADCx
== ADC2
))
307 /* Get the ADC CCR value */
308 tmpreg1
= ADC1_2
->CCR
;
310 /* Clear MULTI, DELAY, DMA and ADCPRE bits */
311 tmpreg1
&= CCR_CLEAR_MASK
;
315 /* Get the ADC CCR value */
316 tmpreg1
= ADC3_4
->CCR
;
318 /* Clear MULTI, DELAY, DMA and ADCPRE bits */
319 tmpreg1
&= CCR_CLEAR_MASK
;
321 /*---------------------------- ADC CCR Configuration -----------------*/
322 /* Configure ADCx: Multi mode, Delay between two sampling time, ADC clock, DMA mode
323 and DMA access mode for dual mode */
324 /* Set MULTI bits according to ADC_Mode value */
325 /* Set CKMODE bits according to ADC_Clock value */
326 /* Set MDMA bits according to ADC_DMAAccessMode value */
327 /* Set DMACFG bits according to ADC_DMAMode value */
328 /* Set DELAY bits according to ADC_TwoSamplingDelay value */
329 tmpreg1
|= (uint32_t)(ADC_CommonInitStruct
->ADC_Mode
|
330 ADC_CommonInitStruct
->ADC_Clock
|
331 ADC_CommonInitStruct
->ADC_DMAAccessMode
|
332 (uint32_t)(ADC_CommonInitStruct
->ADC_DMAMode
<< 12) |
333 (uint32_t)((uint32_t)ADC_CommonInitStruct
->ADC_TwoSamplingDelay
<< 8));
335 if((ADCx
== ADC1
) || (ADCx
== ADC2
))
337 /* Write to ADC CCR */
338 ADC1_2
->CCR
= tmpreg1
;
342 /* Write to ADC CCR */
343 ADC3_4
->CCR
= tmpreg1
;
348 * @brief Fills each ADC_CommonInitStruct member with its default value.
349 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
350 * which will be initialized.
353 void ADC_CommonStructInit(ADC_CommonInitTypeDef
* ADC_CommonInitStruct
)
355 /* Initialize the ADC_Mode member */
356 ADC_CommonInitStruct
->ADC_Mode
= ADC_Mode_Independent
;
358 /* initialize the ADC_Clock member */
359 ADC_CommonInitStruct
->ADC_Clock
= ADC_Clock_AsynClkMode
;
361 /* Initialize the ADC_DMAAccessMode member */
362 ADC_CommonInitStruct
->ADC_DMAAccessMode
= ADC_DMAAccessMode_Disabled
;
364 /* Initialize the ADC_DMAMode member */
365 ADC_CommonInitStruct
->ADC_DMAMode
= ADC_DMAMode_OneShot
;
367 /* Initialize the ADC_TwoSamplingDelay member */
368 ADC_CommonInitStruct
->ADC_TwoSamplingDelay
= 0;
373 * @brief Enables or disables the specified ADC peripheral.
374 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
375 * @param NewState: new state of the ADCx peripheral.
376 * This parameter can be: ENABLE or DISABLE.
379 void ADC_Cmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
381 /* Check the parameters */
382 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
383 assert_param(IS_FUNCTIONAL_STATE(NewState
));
385 if (NewState
!= DISABLE
)
387 /* Set the ADEN bit */
388 ADCx
->CR
|= ADC_CR_ADEN
;
392 /* Disable the selected ADC peripheral: Set the ADDIS bit */
393 ADCx
->CR
|= ADC_CR_ADDIS
;
398 * @brief Starts the selected ADC calibration process.
399 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
402 void ADC_StartCalibration(ADC_TypeDef
* ADCx
)
404 /* Check the parameters */
405 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
407 /* Set the ADCAL bit */
408 ADCx
->CR
|= ADC_CR_ADCAL
;
412 * @brief Returns the ADCx calibration value.
413 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
416 uint32_t ADC_GetCalibrationValue(ADC_TypeDef
* ADCx
)
418 /* Check the parameters */
419 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
421 /* Return the selected ADC calibration value */
422 return (uint32_t)ADCx
->CALFACT
;
426 * @brief Sets the ADCx calibration register.
427 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
430 void ADC_SetCalibrationValue(ADC_TypeDef
* ADCx
, uint32_t ADC_Calibration
)
432 /* Check the parameters */
433 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
435 /* Set the ADC calibration register value */
436 ADCx
->CALFACT
= ADC_Calibration
;
440 * @brief Select the ADC calibration mode.
441 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
442 * @param ADC_CalibrationMode: the ADC calibration mode.
443 * This parameter can be one of the following values:
444 * @arg ADC_CalibrationMode_Single: to select the calibration for single channel
445 * @arg ADC_CalibrationMode_Differential: to select the calibration for differential channel
448 void ADC_SelectCalibrationMode(ADC_TypeDef
* ADCx
, uint32_t ADC_CalibrationMode
)
450 /* Check the parameters */
451 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
452 assert_param(IS_ADC_CALIBRATION_MODE(ADC_CalibrationMode
));
453 /* Set or Reset the ADCALDIF bit */
454 ADCx
->CR
&= (~ADC_CR_ADCALDIF
);
455 ADCx
->CR
|= ADC_CalibrationMode
;
460 * @brief Gets the selected ADC calibration status.
461 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
462 * @retval The new state of ADC calibration (SET or RESET).
464 FlagStatus
ADC_GetCalibrationStatus(ADC_TypeDef
* ADCx
)
466 FlagStatus bitstatus
= RESET
;
467 /* Check the parameters */
468 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
469 /* Check the status of CAL bit */
470 if ((ADCx
->CR
& ADC_CR_ADCAL
) != (uint32_t)RESET
)
472 /* CAL bit is set: calibration on going */
477 /* CAL bit is reset: end of calibration */
480 /* Return the CAL bit status */
485 * @brief ADC Disable Command.
486 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
489 void ADC_DisableCmd(ADC_TypeDef
* ADCx
)
491 /* Check the parameters */
492 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
494 /* Set the ADDIS bit */
495 ADCx
->CR
|= ADC_CR_ADDIS
;
500 * @brief Gets the selected ADC disable command Status.
501 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
502 * @retval The new state of ADC ADC disable command (SET or RESET).
504 FlagStatus
ADC_GetDisableCmdStatus(ADC_TypeDef
* ADCx
)
506 FlagStatus bitstatus
= RESET
;
507 /* Check the parameters */
508 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
510 /* Check the status of ADDIS bit */
511 if ((ADCx
->CR
& ADC_CR_ADDIS
) != (uint32_t)RESET
)
513 /* ADDIS bit is set */
518 /* ADDIS bit is reset */
521 /* Return the ADDIS bit status */
526 * @brief Enables or disables the specified ADC Voltage Regulator.
527 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
528 * @param NewState: new state of the ADCx Voltage Regulator.
529 * This parameter can be: ENABLE or DISABLE.
532 void ADC_VoltageRegulatorCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
534 /* Check the parameters */
535 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
536 assert_param(IS_FUNCTIONAL_STATE(NewState
));
538 /* set the intermediate state before moving the ADC voltage regulator
539 from enable state to disable state or from disable state to enable state */
540 ADCx
->CR
&= ~(ADC_CR_ADVREGEN
);
542 if (NewState
!= DISABLE
)
544 /* Set the ADVREGEN bit 0 */
545 ADCx
->CR
|= ADC_CR_ADVREGEN_0
;
549 /* Set the ADVREGEN bit 1 */
550 ADCx
->CR
|=ADC_CR_ADVREGEN_1
;
555 * @brief Selectes the differential mode for a specific channel
556 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
557 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
558 * This parameter can be one of the following values:
559 * @arg ADC_Channel_1: ADC Channel1 selected
560 * @arg ADC_Channel_2: ADC Channel2 selected
561 * @arg ADC_Channel_3: ADC Channel3 selected
562 * @arg ADC_Channel_4: ADC Channel4 selected
563 * @arg ADC_Channel_5: ADC Channel5 selected
564 * @arg ADC_Channel_6: ADC Channel6 selected
565 * @arg ADC_Channel_7: ADC Channel7 selected
566 * @arg ADC_Channel_8: ADC Channel8 selected
567 * @arg ADC_Channel_9: ADC Channel9 selected
568 * @arg ADC_Channel_10: ADC Channel10 selected
569 * @arg ADC_Channel_11: ADC Channel11 selected
570 * @arg ADC_Channel_12: ADC Channel12 selected
571 * @arg ADC_Channel_13: ADC Channel13 selected
572 * @arg ADC_Channel_14: ADC Channel14 selected
573 * @note : Channel 15, 16 and 17 are fixed to single-ended inputs mode.
576 void ADC_SelectDifferentialMode(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, FunctionalState NewState
)
578 /* Check the parameters */
579 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
580 assert_param(IS_ADC_DIFFCHANNEL(ADC_Channel
));
581 assert_param(IS_FUNCTIONAL_STATE(NewState
));
583 if (NewState
!= DISABLE
)
585 /* Set the DIFSEL bit */
586 ADCx
->DIFSEL
|= (uint32_t)(1 << ADC_Channel
);
590 /* Reset the DIFSEL bit */
591 ADCx
->DIFSEL
&= ~(uint32_t)(1 << ADC_Channel
);
596 * @brief Selects the Queue Of Context Mode for injected channels.
597 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
598 * @param NewState: new state of the Queue Of Context Mode.
599 * This parameter can be: ENABLE or DISABLE.
602 void ADC_SelectQueueOfContextMode(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
604 /* Check the parameters */
605 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
606 assert_param(IS_FUNCTIONAL_STATE(NewState
));
608 if (NewState
!= DISABLE
)
610 /* Set the JQM bit */
611 ADCx
->CFGR
|= (uint32_t)(ADC_CFGR_JQM
);
615 /* Reset the JQM bit */
616 ADCx
->CFGR
&= ~(uint32_t)(ADC_CFGR_JQM
);
621 * @brief Selects the ADC Delayed Conversion Mode.
622 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
623 * @param NewState: new state of the ADC Delayed Conversion Mode.
624 * This parameter can be: ENABLE or DISABLE.
627 void ADC_AutoDelayCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
629 /* Check the parameters */
630 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
631 assert_param(IS_FUNCTIONAL_STATE(NewState
));
633 if (NewState
!= DISABLE
)
635 /* Set the AUTDLY bit */
636 ADCx
->CFGR
|= (uint32_t)(ADC_CFGR_AUTDLY
);
640 /* Reset the AUTDLY bit */
641 ADCx
->CFGR
&= ~(uint32_t)(ADC_CFGR_AUTDLY
);
649 /** @defgroup ADC_Group2 Analog Watchdog configuration functions
650 * @brief Analog Watchdog configuration functions
653 ===============================================================================
654 ##### Analog Watchdog configuration functions #####
655 ===============================================================================
657 [..] This section provides functions allowing to configure the 3 Analog Watchdogs
658 (AWDG1, AWDG2 and AWDG3) in the ADC.
660 [..] A typical configuration Analog Watchdog is done following these steps :
661 (#) The ADC guarded channel(s) is (are) selected using the functions:
662 (++) ADC_AnalogWatchdog1SingleChannelConfig().
663 (++) ADC_AnalogWatchdog2SingleChannelConfig().
664 (++) ADC_AnalogWatchdog3SingleChannelConfig().
666 (#) The Analog watchdog lower and higher threshold are configured using the functions:
667 (++) ADC_AnalogWatchdog1ThresholdsConfig().
668 (++) ADC_AnalogWatchdog2ThresholdsConfig().
669 (++) ADC_AnalogWatchdog3ThresholdsConfig().
671 (#) The Analog watchdog is enabled and configured to enable the check, on one
672 or more channels, using the function:
673 (++) ADC_AnalogWatchdogCmd().
680 * @brief Enables or disables the analog watchdog on single/all regular
681 * or injected channels
682 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
683 * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration.
684 * This parameter can be one of the following values:
685 * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single regular channel
686 * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single injected channel
687 * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a single regular or injected channel
688 * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular channel
689 * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected channel
690 * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all regular and injected channels
691 * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog
694 void ADC_AnalogWatchdogCmd(ADC_TypeDef
* ADCx
, uint32_t ADC_AnalogWatchdog
)
697 /* Check the parameters */
698 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
699 assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog
));
700 /* Get the old register value */
702 /* Clear AWDEN, AWDENJ and AWDSGL bits */
703 tmpreg
&= ~(uint32_t)(ADC_CFGR_AWD1SGL
|ADC_CFGR_AWD1EN
|ADC_CFGR_JAWD1EN
);
704 /* Set the analog watchdog enable mode */
705 tmpreg
|= ADC_AnalogWatchdog
;
706 /* Store the new register value */
711 * @brief Configures the high and low thresholds of the analog watchdog1.
712 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
713 * @param HighThreshold: the ADC analog watchdog High threshold value.
714 * This parameter must be a 12bit value.
715 * @param LowThreshold: the ADC analog watchdog Low threshold value.
716 * This parameter must be a 12bit value.
719 void ADC_AnalogWatchdog1ThresholdsConfig(ADC_TypeDef
* ADCx
, uint16_t HighThreshold
,
720 uint16_t LowThreshold
)
722 /* Check the parameters */
723 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
724 assert_param(IS_ADC_THRESHOLD(HighThreshold
));
725 assert_param(IS_ADC_THRESHOLD(LowThreshold
));
726 /* Set the ADCx high threshold */
727 ADCx
->TR1
&= ~(uint32_t)ADC_TR1_HT1
;
728 ADCx
->TR1
|= (uint32_t)((uint32_t)HighThreshold
<< 16);
730 /* Set the ADCx low threshold */
731 ADCx
->TR1
&= ~(uint32_t)ADC_TR1_LT1
;
732 ADCx
->TR1
|= LowThreshold
;
736 * @brief Configures the high and low thresholds of the analog watchdog2.
737 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
738 * @param HighThreshold: the ADC analog watchdog High threshold value.
739 * This parameter must be a 8bit value.
740 * @param LowThreshold: the ADC analog watchdog Low threshold value.
741 * This parameter must be a 8bit value.
744 void ADC_AnalogWatchdog2ThresholdsConfig(ADC_TypeDef
* ADCx
, uint8_t HighThreshold
,
745 uint8_t LowThreshold
)
747 /* Check the parameters */
748 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
750 /* Set the ADCx high threshold */
751 ADCx
->TR2
&= ~(uint32_t)ADC_TR2_HT2
;
752 ADCx
->TR2
|= (uint32_t)((uint32_t)HighThreshold
<< 16);
754 /* Set the ADCx low threshold */
755 ADCx
->TR2
&= ~(uint32_t)ADC_TR2_LT2
;
756 ADCx
->TR2
|= LowThreshold
;
760 * @brief Configures the high and low thresholds of the analog watchdog3.
761 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
762 * @param HighThreshold: the ADC analog watchdog High threshold value.
763 * This parameter must be a 8bit value.
764 * @param LowThreshold: the ADC analog watchdog Low threshold value.
765 * This parameter must be a 8bit value.
768 void ADC_AnalogWatchdog3ThresholdsConfig(ADC_TypeDef
* ADCx
, uint8_t HighThreshold
,
769 uint8_t LowThreshold
)
771 /* Check the parameters */
772 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
774 /* Set the ADCx high threshold */
775 ADCx
->TR3
&= ~(uint32_t)ADC_TR3_HT3
;
776 ADCx
->TR3
|= (uint32_t)((uint32_t)HighThreshold
<< 16);
778 /* Set the ADCx low threshold */
779 ADCx
->TR3
&= ~(uint32_t)ADC_TR3_LT3
;
780 ADCx
->TR3
|= LowThreshold
;
784 * @brief Configures the analog watchdog 2 guarded single channel
785 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
786 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
787 * This parameter can be one of the following values:
788 * @arg ADC_Channel_1: ADC Channel1 selected
789 * @arg ADC_Channel_2: ADC Channel2 selected
790 * @arg ADC_Channel_3: ADC Channel3 selected
791 * @arg ADC_Channel_4: ADC Channel4 selected
792 * @arg ADC_Channel_5: ADC Channel5 selected
793 * @arg ADC_Channel_6: ADC Channel6 selected
794 * @arg ADC_Channel_7: ADC Channel7 selected
795 * @arg ADC_Channel_8: ADC Channel8 selected
796 * @arg ADC_Channel_9: ADC Channel9 selected
797 * @arg ADC_Channel_10: ADC Channel10 selected
798 * @arg ADC_Channel_11: ADC Channel11 selected
799 * @arg ADC_Channel_12: ADC Channel12 selected
800 * @arg ADC_Channel_13: ADC Channel13 selected
801 * @arg ADC_Channel_14: ADC Channel14 selected
802 * @arg ADC_Channel_15: ADC Channel15 selected
803 * @arg ADC_Channel_16: ADC Channel16 selected
804 * @arg ADC_Channel_17: ADC Channel17 selected
805 * @arg ADC_Channel_18: ADC Channel18 selected
808 void ADC_AnalogWatchdog1SingleChannelConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
)
811 /* Check the parameters */
812 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
813 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
814 /* Get the old register value */
816 /* Clear the Analog watchdog channel select bits */
817 tmpreg
&= ~(uint32_t)ADC_CFGR_AWD1CH
;
818 /* Set the Analog watchdog channel */
819 tmpreg
|= (uint32_t)((uint32_t)ADC_Channel
<< 26);
820 /* Store the new register value */
825 * @brief Configures the analog watchdog 2 guarded single channel
826 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
827 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
828 * This parameter can be one of the following values:
829 * @arg ADC_Channel_1: ADC Channel1 selected
830 * @arg ADC_Channel_2: ADC Channel2 selected
831 * @arg ADC_Channel_3: ADC Channel3 selected
832 * @arg ADC_Channel_4: ADC Channel4 selected
833 * @arg ADC_Channel_5: ADC Channel5 selected
834 * @arg ADC_Channel_6: ADC Channel6 selected
835 * @arg ADC_Channel_7: ADC Channel7 selected
836 * @arg ADC_Channel_8: ADC Channel8 selected
837 * @arg ADC_Channel_9: ADC Channel9 selected
838 * @arg ADC_Channel_10: ADC Channel10 selected
839 * @arg ADC_Channel_11: ADC Channel11 selected
840 * @arg ADC_Channel_12: ADC Channel12 selected
841 * @arg ADC_Channel_13: ADC Channel13 selected
842 * @arg ADC_Channel_14: ADC Channel14 selected
843 * @arg ADC_Channel_15: ADC Channel15 selected
844 * @arg ADC_Channel_16: ADC Channel16 selected
845 * @arg ADC_Channel_17: ADC Channel17 selected
846 * @arg ADC_Channel_18: ADC Channel18 selected
849 void ADC_AnalogWatchdog2SingleChannelConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
)
852 /* Check the parameters */
853 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
854 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
855 /* Get the old register value */
856 tmpreg
= ADCx
->AWD2CR
;
857 /* Clear the Analog watchdog channel select bits */
858 tmpreg
&= ~(uint32_t)ADC_AWD2CR_AWD2CH
;
859 /* Set the Analog watchdog channel */
860 tmpreg
|= (uint32_t)1 << (ADC_Channel
);
861 /* Store the new register value */
862 ADCx
->AWD2CR
|= tmpreg
;
866 * @brief Configures the analog watchdog 3 guarded single channel
867 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
868 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
869 * This parameter can be one of the following values:
870 * @arg ADC_Channel_1: ADC Channel1 selected
871 * @arg ADC_Channel_2: ADC Channel2 selected
872 * @arg ADC_Channel_3: ADC Channel3 selected
873 * @arg ADC_Channel_4: ADC Channel4 selected
874 * @arg ADC_Channel_5: ADC Channel5 selected
875 * @arg ADC_Channel_6: ADC Channel6 selected
876 * @arg ADC_Channel_7: ADC Channel7 selected
877 * @arg ADC_Channel_8: ADC Channel8 selected
878 * @arg ADC_Channel_9: ADC Channel9 selected
879 * @arg ADC_Channel_10: ADC Channel10 selected
880 * @arg ADC_Channel_11: ADC Channel11 selected
881 * @arg ADC_Channel_12: ADC Channel12 selected
882 * @arg ADC_Channel_13: ADC Channel13 selected
883 * @arg ADC_Channel_14: ADC Channel14 selected
884 * @arg ADC_Channel_15: ADC Channel15 selected
885 * @arg ADC_Channel_16: ADC Channel16 selected
886 * @arg ADC_Channel_17: ADC Channel17 selected
887 * @arg ADC_Channel_18: ADC Channel18 selected
890 void ADC_AnalogWatchdog3SingleChannelConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
)
893 /* Check the parameters */
894 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
895 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
896 /* Get the old register value */
897 tmpreg
= ADCx
->AWD3CR
;
898 /* Clear the Analog watchdog channel select bits */
899 tmpreg
&= ~(uint32_t)ADC_AWD3CR_AWD3CH
;
900 /* Set the Analog watchdog channel */
901 tmpreg
|= (uint32_t)1 << (ADC_Channel
);
902 /* Store the new register value */
903 ADCx
->AWD3CR
|= tmpreg
;
910 /** @defgroup ADC_Group3 Temperature Sensor - Vrefint (Internal Reference Voltage) and VBAT management functions
911 * @brief Vbat, Temperature Sensor & Vrefint (Internal Reference Voltage) management function
914 ====================================================================================================
915 ##### Temperature Sensor - Vrefint (Internal Reference Voltage) and VBAT management functions #####
916 ====================================================================================================
918 [..] This section provides a function allowing to enable/ disable the internal
919 connections between the ADC and the Vbat/2, Temperature Sensor and the Vrefint source.
921 [..] A typical configuration to get the Temperature sensor and Vrefint channels
922 voltages is done following these steps :
923 (#) Enable the internal connection of Vbat/2, Temperature sensor and Vrefint sources
924 with the ADC channels using:
925 (++) ADC_TempSensorCmd()
926 (++) ADC_VrefintCmd()
929 (#) select the ADC_Channel_TempSensor and/or ADC_Channel_Vrefint and/or ADC_Channel_Vbat using
930 (++) ADC_RegularChannelConfig() or
931 (++) ADC_InjectedInit() functions
933 (#) Get the voltage values, using:
934 (++) ADC_GetConversionValue() or
935 (++) ADC_GetInjectedConversionValue().
942 * @brief Enables or disables the temperature sensor channel.
943 * @param ADCx: where x can be 1 to select the ADC peripheral.
944 * @param NewState: new state of the temperature sensor.
945 * This parameter can be: ENABLE or DISABLE.
948 void ADC_TempSensorCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
952 /* Check the parameters */
953 assert_param(IS_FUNCTIONAL_STATE(NewState
));
955 if (NewState
!= DISABLE
)
957 /* Enable the temperature sensor channel*/
958 ADC1_2
->CCR
|= ADC12_CCR_TSEN
;
962 /* Disable the temperature sensor channel*/
963 ADC1_2
->CCR
&= ~(uint32_t)ADC12_CCR_TSEN
;
968 * @brief Enables or disables the Vrefint channel.
969 * @param ADCx: where x can be 1 or 4 to select the ADC peripheral.
970 * @param NewState: new state of the Vrefint.
971 * This parameter can be: ENABLE or DISABLE.
974 void ADC_VrefintCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
976 /* Check the parameters */
977 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
978 assert_param(IS_FUNCTIONAL_STATE(NewState
));
980 if((ADCx
== ADC1
) || (ADCx
== ADC2
))
982 if (NewState
!= DISABLE
)
984 /* Enable the Vrefint channel*/
985 ADC1_2
->CCR
|= ADC12_CCR_VREFEN
;
989 /* Disable the Vrefint channel*/
990 ADC1_2
->CCR
&= ~(uint32_t)ADC12_CCR_VREFEN
;
995 if (NewState
!= DISABLE
)
997 /* Enable the Vrefint channel*/
998 ADC3_4
->CCR
|= ADC34_CCR_VREFEN
;
1002 /* Disable the Vrefint channel*/
1003 ADC3_4
->CCR
&= ~(uint32_t)ADC34_CCR_VREFEN
;
1009 * @brief Enables or disables the Vbat channel.
1010 * @param ADCx: where x can be 1 to select the ADC peripheral.
1011 * @param NewState: new state of the Vbat.
1012 * This parameter can be: ENABLE or DISABLE.
1015 void ADC_VbatCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1018 /* Check the parameters */
1019 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1021 if (NewState
!= DISABLE
)
1023 /* Enable the Vbat channel*/
1024 ADC1_2
->CCR
|= ADC12_CCR_VBATEN
;
1028 /* Disable the Vbat channel*/
1029 ADC1_2
->CCR
&= ~(uint32_t)ADC12_CCR_VBATEN
;
1037 /** @defgroup ADC_Group4 Regular Channels Configuration functions
1038 * @brief Regular Channels Configuration functions
1041 ===============================================================================
1042 ##### Channels Configuration functions #####
1043 ===============================================================================
1045 [..] This section provides functions allowing to manage the ADC regular channels.
1047 [..] To configure a regular sequence of channels use:
1048 (#) ADC_RegularChannelConfig()
1049 this fuction allows:
1050 (++) Configure the rank in the regular group sequencer for each channel
1051 (++) Configure the sampling time for each channel
1053 (#) ADC_RegularChannelSequencerLengthConfig() to set the length of the regular sequencer
1055 [..] The regular trigger is configured using the following functions:
1056 (#) ADC_SelectExternalTrigger()
1057 (#) ADC_ExternalTriggerPolarityConfig()
1059 [..] The start and the stop conversion are controlled by:
1060 (#) ADC_StartConversion()
1061 (#) ADC_StopConversion()
1064 (@)Please Note that the following features for regular channels are configurated
1065 using the ADC_Init() function :
1066 (++) continuous mode activation
1068 (++) Data Alignement
1071 [..] Get the conversion data: This subsection provides an important function in
1072 the ADC peripheral since it returns the converted data of the current
1073 regular channel. When the Conversion value is read, the EOC Flag is
1074 automatically cleared.
1076 [..] To configure the discontinous mode, the following functions should be used:
1077 (#) ADC_DiscModeChannelCountConfig() to configure the number of discontinuous channel to be converted.
1078 (#) ADC_DiscModeCmd() to enable the discontinuous mode.
1080 [..] To configure and enable/disable the Channel offset use the functions:
1081 (++) ADC_SetChannelOffset1()
1082 (++) ADC_SetChannelOffset2()
1083 (++) ADC_SetChannelOffset3()
1084 (++) ADC_SetChannelOffset4()
1085 (++) ADC_ChannelOffset1Cmd()
1086 (++) ADC_ChannelOffset2Cmd()
1087 (++) ADC_ChannelOffset3Cmd()
1088 (++) ADC_ChannelOffset4Cmd()
1095 * @brief Configures for the selected ADC regular channel its corresponding
1096 * rank in the sequencer and its sample time.
1097 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1098 * @param ADC_Channel: the ADC channel to configure.
1099 * This parameter can be one of the following values:
1100 * @arg ADC_Channel_1: ADC Channel1 selected
1101 * @arg ADC_Channel_2: ADC Channel2 selected
1102 * @arg ADC_Channel_3: ADC Channel3 selected
1103 * @arg ADC_Channel_4: ADC Channel4 selected
1104 * @arg ADC_Channel_5: ADC Channel5 selected
1105 * @arg ADC_Channel_6: ADC Channel6 selected
1106 * @arg ADC_Channel_7: ADC Channel7 selected
1107 * @arg ADC_Channel_8: ADC Channel8 selected
1108 * @arg ADC_Channel_9: ADC Channel9 selected
1109 * @arg ADC_Channel_10: ADC Channel10 selected
1110 * @arg ADC_Channel_11: ADC Channel11 selected
1111 * @arg ADC_Channel_12: ADC Channel12 selected
1112 * @arg ADC_Channel_13: ADC Channel13 selected
1113 * @arg ADC_Channel_14: ADC Channel14 selected
1114 * @arg ADC_Channel_15: ADC Channel15 selected
1115 * @arg ADC_Channel_16: ADC Channel16 selected
1116 * @arg ADC_Channel_17: ADC Channel17 selected
1117 * @arg ADC_Channel_18: ADC Channel18 selected
1118 * @param Rank: The rank in the regular group sequencer. This parameter must be between 1 to 16.
1119 * @param ADC_SampleTime: The sample time value to be set for the selected channel.
1120 * This parameter can be one of the following values:
1121 * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
1122 * @arg ADC_SampleTime_2Cycles5: Sample time equal to 2.5 cycles
1123 * @arg ADC_SampleTime_4Cycles5: Sample time equal to 4.5 cycles
1124 * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
1125 * @arg ADC_SampleTime_19Cycles5: Sample time equal to 19.5 cycles
1126 * @arg ADC_SampleTime_61Cycles5: Sample time equal to 61.5 cycles
1127 * @arg ADC_SampleTime_181Cycles5: Sample time equal to 181.5 cycles
1128 * @arg ADC_SampleTime_601Cycles5: Sample time equal to 601.5 cycles
1131 void ADC_RegularChannelConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, uint8_t Rank
, uint8_t ADC_SampleTime
)
1133 uint32_t tmpreg1
= 0, tmpreg2
= 0;
1134 /* Check the parameters */
1135 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1136 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
1137 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime
));
1139 /* Regular sequence configuration */
1140 /* For Rank 1 to 4 */
1143 /* Get the old register value */
1144 tmpreg1
= ADCx
->SQR1
;
1145 /* Calculate the mask to clear */
1146 tmpreg2
= 0x1F << (6 * (Rank
));
1147 /* Clear the old SQx bits for the selected rank */
1148 tmpreg1
&= ~tmpreg2
;
1149 /* Calculate the mask to set */
1150 tmpreg2
= (uint32_t)(ADC_Channel
) << (6 * (Rank
));
1151 /* Set the SQx bits for the selected rank */
1153 /* Store the new register value */
1154 ADCx
->SQR1
= tmpreg1
;
1156 /* For Rank 5 to 9 */
1159 /* Get the old register value */
1160 tmpreg1
= ADCx
->SQR2
;
1161 /* Calculate the mask to clear */
1162 tmpreg2
= ADC_SQR2_SQ5
<< (6 * (Rank
- 5));
1163 /* Clear the old SQx bits for the selected rank */
1164 tmpreg1
&= ~tmpreg2
;
1165 /* Calculate the mask to set */
1166 tmpreg2
= (uint32_t)(ADC_Channel
) << (6 * (Rank
- 5));
1167 /* Set the SQx bits for the selected rank */
1169 /* Store the new register value */
1170 ADCx
->SQR2
= tmpreg1
;
1172 /* For Rank 10 to 14 */
1175 /* Get the old register value */
1176 tmpreg1
= ADCx
->SQR3
;
1177 /* Calculate the mask to clear */
1178 tmpreg2
= ADC_SQR3_SQ10
<< (6 * (Rank
- 10));
1179 /* Clear the old SQx bits for the selected rank */
1180 tmpreg1
&= ~tmpreg2
;
1181 /* Calculate the mask to set */
1182 tmpreg2
= (uint32_t)(ADC_Channel
) << (6 * (Rank
- 10));
1183 /* Set the SQx bits for the selected rank */
1185 /* Store the new register value */
1186 ADCx
->SQR3
= tmpreg1
;
1190 /* Get the old register value */
1191 tmpreg1
= ADCx
->SQR4
;
1192 /* Calculate the mask to clear */
1193 tmpreg2
= ADC_SQR3_SQ15
<< (6 * (Rank
- 15));
1194 /* Clear the old SQx bits for the selected rank */
1195 tmpreg1
&= ~tmpreg2
;
1196 /* Calculate the mask to set */
1197 tmpreg2
= (uint32_t)(ADC_Channel
) << (6 * (Rank
- 15));
1198 /* Set the SQx bits for the selected rank */
1200 /* Store the new register value */
1201 ADCx
->SQR4
= tmpreg1
;
1204 /* Channel sampling configuration */
1205 /* if ADC_Channel_10 ... ADC_Channel_18 is selected */
1206 if (ADC_Channel
> ADC_Channel_9
)
1208 /* Get the old register value */
1209 tmpreg1
= ADCx
->SMPR2
;
1210 /* Calculate the mask to clear */
1211 tmpreg2
= ADC_SMPR2_SMP10
<< (3 * (ADC_Channel
- 10));
1212 /* Clear the old channel sample time */
1213 ADCx
->SMPR2
&= ~tmpreg2
;
1214 /* Calculate the mask to set */
1215 ADCx
->SMPR2
|= (uint32_t)ADC_SampleTime
<< (3 * (ADC_Channel
- 10));
1218 else /* ADC_Channel include in ADC_Channel_[0..9] */
1220 /* Get the old register value */
1221 tmpreg1
= ADCx
->SMPR1
;
1222 /* Calculate the mask to clear */
1223 tmpreg2
= ADC_SMPR1_SMP1
<< (3 * (ADC_Channel
- 1));
1224 /* Clear the old channel sample time */
1225 ADCx
->SMPR1
&= ~tmpreg2
;
1226 /* Calculate the mask to set */
1227 ADCx
->SMPR1
|= (uint32_t)ADC_SampleTime
<< (3 * (ADC_Channel
));
1232 * @brief Sets the ADC regular channel sequence lenght.
1233 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1234 * @param SequenceLength: The Regular sequence length. This parameter must be between 1 to 16.
1235 * This parameter can be: ENABLE or DISABLE.
1238 void ADC_RegularChannelSequencerLengthConfig(ADC_TypeDef
* ADCx
, uint8_t SequencerLength
)
1240 /* Check the parameters */
1241 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1243 /* Configure the ADC sequence lenght */
1244 ADCx
->SQR1
&= ~(uint32_t)ADC_SQR1_L
;
1245 ADCx
->SQR1
|= (uint32_t)(SequencerLength
- 1);
1249 * @brief External Trigger Enable and Polarity Selection for regular channels.
1250 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1251 * @param ADC_ExternalTrigConvEvent: ADC external Trigger source.
1252 * This parameter can be one of the following values:
1253 * @arg ADC_ExternalTrigger_Event0: External trigger event 0
1254 * @arg ADC_ExternalTrigger_Event1: External trigger event 1
1255 * @arg ADC_ExternalTrigger_Event2: External trigger event 2
1256 * @arg ADC_ExternalTrigger_Event3: External trigger event 3
1257 * @arg ADC_ExternalTrigger_Event4: External trigger event 4
1258 * @arg ADC_ExternalTrigger_Event5: External trigger event 5
1259 * @arg ADC_ExternalTrigger_Event6: External trigger event 6
1260 * @arg ADC_ExternalTrigger_Event7: External trigger event 7
1261 * @arg ADC_ExternalTrigger_Event8: External trigger event 8
1262 * @arg ADC_ExternalTrigger_Event9: External trigger event 9
1263 * @arg ADC_ExternalTrigger_Event10: External trigger event 10
1264 * @arg ADC_ExternalTrigger_Event11: External trigger event 11
1265 * @arg ADC_ExternalTrigger_Event12: External trigger event 12
1266 * @arg ADC_ExternalTrigger_Event13: External trigger event 13
1267 * @arg ADC_ExternalTrigger_Event14: External trigger event 14
1268 * @arg ADC_ExternalTrigger_Event15: External trigger event 15
1269 * @param ADC_ExternalTrigEventEdge: ADC external Trigger Polarity.
1270 * This parameter can be one of the following values:
1271 * @arg ADC_ExternalTrigEventEdge_OFF: Hardware trigger detection disabled
1272 * (conversions can be launched by software)
1273 * @arg ADC_ExternalTrigEventEdge_RisingEdge: Hardware trigger detection on the rising edge
1274 * @arg ADC_ExternalTrigEventEdge_FallingEdge: Hardware trigger detection on the falling edge
1275 * @arg ADC_ExternalTrigEventEdge_BothEdge: Hardware trigger detection on both the rising and falling edges
1278 void ADC_ExternalTriggerConfig(ADC_TypeDef
* ADCx
, uint16_t ADC_ExternalTrigConvEvent
, uint16_t ADC_ExternalTrigEventEdge
)
1280 /* Check the parameters */
1281 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1282 assert_param(IS_ADC_EXT_TRIG(ADC_ExternalTrigConvEvent
));
1283 assert_param(IS_EXTERNALTRIG_EDGE(ADC_ExternalTrigEventEdge
));
1285 /* Disable the selected ADC conversion on external event */
1286 ADCx
->CFGR
&= ~(ADC_CFGR_EXTEN
| ADC_CFGR_EXTSEL
);
1287 ADCx
->CFGR
|= (uint32_t)(ADC_ExternalTrigEventEdge
| ADC_ExternalTrigConvEvent
);
1291 * @brief Enables or disables the selected ADC start conversion .
1292 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1295 void ADC_StartConversion(ADC_TypeDef
* ADCx
)
1297 /* Check the parameters */
1298 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1300 /* Set the ADSTART bit */
1301 ADCx
->CR
|= ADC_CR_ADSTART
;
1305 * @brief Gets the selected ADC start conversion Status.
1306 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1307 * @retval The new state of ADC start conversion (SET or RESET).
1309 FlagStatus
ADC_GetStartConversionStatus(ADC_TypeDef
* ADCx
)
1311 FlagStatus bitstatus
= RESET
;
1312 /* Check the parameters */
1313 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1314 /* Check the status of ADSTART bit */
1315 if ((ADCx
->CR
& ADC_CR_ADSTART
) != (uint32_t)RESET
)
1317 /* ADSTART bit is set */
1322 /* ADSTART bit is reset */
1325 /* Return the ADSTART bit status */
1330 * @brief Stops the selected ADC ongoing conversion.
1331 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1334 void ADC_StopConversion(ADC_TypeDef
* ADCx
)
1336 /* Check the parameters */
1337 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1339 /* Set the ADSTP bit */
1340 ADCx
->CR
|= ADC_CR_ADSTP
;
1345 * @brief Configures the discontinuous mode for the selected ADC regular
1347 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1348 * @param Number: specifies the discontinuous mode regular channel
1349 * count value. This number must be between 1 and 8.
1352 void ADC_DiscModeChannelCountConfig(ADC_TypeDef
* ADCx
, uint8_t Number
)
1354 uint32_t tmpreg1
= 0;
1355 uint32_t tmpreg2
= 0;
1356 /* Check the parameters */
1357 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1358 assert_param(IS_ADC_REGULAR_DISC_NUMBER(Number
));
1359 /* Get the old register value */
1360 tmpreg1
= ADCx
->CFGR
;
1361 /* Clear the old discontinuous mode channel count */
1362 tmpreg1
&= ~(uint32_t)(ADC_CFGR_DISCNUM
);
1363 /* Set the discontinuous mode channel count */
1364 tmpreg2
= Number
- 1;
1365 tmpreg1
|= tmpreg2
<< 17;
1366 /* Store the new register value */
1367 ADCx
->CFGR
= tmpreg1
;
1371 * @brief Enables or disables the discontinuous mode on regular group
1372 * channel for the specified ADC
1373 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1374 * @param NewState: new state of the selected ADC discontinuous mode
1375 * on regular group channel.
1376 * This parameter can be: ENABLE or DISABLE.
1379 void ADC_DiscModeCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1381 /* Check the parameters */
1382 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1383 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1384 if (NewState
!= DISABLE
)
1386 /* Enable the selected ADC regular discontinuous mode */
1387 ADCx
->CFGR
|= ADC_CFGR_DISCEN
;
1391 /* Disable the selected ADC regular discontinuous mode */
1392 ADCx
->CFGR
&= ~(uint32_t)(ADC_CFGR_DISCEN
);
1397 * @brief Returns the last ADCx conversion result data for regular channel.
1398 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1399 * @retval The Data conversion value.
1401 uint16_t ADC_GetConversionValue(ADC_TypeDef
* ADCx
)
1403 /* Check the parameters */
1404 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1405 /* Return the selected ADC conversion value */
1406 return (uint16_t) ADCx
->DR
;
1410 * @brief Returns the last ADC1, ADC2, ADC3 and ADC4 regular conversions results
1411 * data in the selected dual mode.
1412 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1413 * @retval The Data conversion value.
1414 * @note In dual mode, the value returned by this function is as following
1415 * Data[15:0] : these bits contain the regular data of the Master ADC.
1416 * Data[31:16]: these bits contain the regular data of the Slave ADC.
1418 uint32_t ADC_GetDualModeConversionValue(ADC_TypeDef
* ADCx
)
1420 uint32_t tmpreg1
= 0;
1422 /* Check the parameters */
1423 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1425 if((ADCx
== ADC1
) || (ADCx
== ADC2
))
1427 /* Get the dual mode conversion value */
1428 tmpreg1
= ADC1_2
->CDR
;
1432 /* Get the dual mode conversion value */
1433 tmpreg1
= ADC3_4
->CDR
;
1435 /* Return the dual mode conversion value */
1436 return (uint32_t) tmpreg1
;
1440 * @brief Set the ADC channels conversion value offset1
1441 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1442 * @param ADC_Channel: the ADC channel to configure.
1443 * This parameter can be one of the following values:
1444 * @arg ADC_Channel_1: ADC Channel1 selected
1445 * @arg ADC_Channel_2: ADC Channel2 selected
1446 * @arg ADC_Channel_3: ADC Channel3 selected
1447 * @arg ADC_Channel_4: ADC Channel4 selected
1448 * @arg ADC_Channel_5: ADC Channel5 selected
1449 * @arg ADC_Channel_6: ADC Channel6 selected
1450 * @arg ADC_Channel_7: ADC Channel7 selected
1451 * @arg ADC_Channel_8: ADC Channel8 selected
1452 * @arg ADC_Channel_9: ADC Channel9 selected
1453 * @arg ADC_Channel_10: ADC Channel10 selected
1454 * @arg ADC_Channel_11: ADC Channel11 selected
1455 * @arg ADC_Channel_12: ADC Channel12 selected
1456 * @arg ADC_Channel_13: ADC Channel13 selected
1457 * @arg ADC_Channel_14: ADC Channel14 selected
1458 * @arg ADC_Channel_15: ADC Channel15 selected
1459 * @arg ADC_Channel_16: ADC Channel16 selected
1460 * @arg ADC_Channel_17: ADC Channel17 selected
1461 * @arg ADC_Channel_18: ADC Channel18 selected
1462 * @param Offset: the offset value for the selected ADC Channel
1463 * This parameter must be a 12bit value.
1466 void ADC_SetChannelOffset1(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, uint16_t Offset
)
1468 /* Check the parameters */
1469 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1470 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
1471 assert_param(IS_ADC_OFFSET(Offset
));
1473 /* Select the Channel */
1474 ADCx
->OFR1
&= ~ (uint32_t) ADC_OFR1_OFFSET1_CH
;
1475 ADCx
->OFR1
|= (uint32_t)((uint32_t)ADC_Channel
<< 26);
1477 /* Set the data offset */
1478 ADCx
->OFR1
&= ~ (uint32_t) ADC_OFR1_OFFSET1
;
1479 ADCx
->OFR1
|= (uint32_t)Offset
;
1483 * @brief Set the ADC channels conversion value offset2
1484 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1485 * @param ADC_Channel: the ADC channel to configure.
1486 * This parameter can be one of the following values:
1487 * @arg ADC_Channel_1: ADC Channel1 selected
1488 * @arg ADC_Channel_2: ADC Channel2 selected
1489 * @arg ADC_Channel_3: ADC Channel3 selected
1490 * @arg ADC_Channel_4: ADC Channel4 selected
1491 * @arg ADC_Channel_5: ADC Channel5 selected
1492 * @arg ADC_Channel_6: ADC Channel6 selected
1493 * @arg ADC_Channel_7: ADC Channel7 selected
1494 * @arg ADC_Channel_8: ADC Channel8 selected
1495 * @arg ADC_Channel_9: ADC Channel9 selected
1496 * @arg ADC_Channel_10: ADC Channel10 selected
1497 * @arg ADC_Channel_11: ADC Channel11 selected
1498 * @arg ADC_Channel_12: ADC Channel12 selected
1499 * @arg ADC_Channel_13: ADC Channel13 selected
1500 * @arg ADC_Channel_14: ADC Channel14 selected
1501 * @arg ADC_Channel_15: ADC Channel15 selected
1502 * @arg ADC_Channel_16: ADC Channel16 selected
1503 * @arg ADC_Channel_17: ADC Channel17 selected
1504 * @arg ADC_Channel_18: ADC Channel18 selected
1505 * @param Offset: the offset value for the selected ADC Channel
1506 * This parameter must be a 12bit value.
1509 void ADC_SetChannelOffset2(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, uint16_t Offset
)
1511 /* Check the parameters */
1512 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1513 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
1514 assert_param(IS_ADC_OFFSET(Offset
));
1516 /* Select the Channel */
1517 ADCx
->OFR2
&= ~ (uint32_t) ADC_OFR2_OFFSET2_CH
;
1518 ADCx
->OFR2
|= (uint32_t)((uint32_t)ADC_Channel
<< 26);
1520 /* Set the data offset */
1521 ADCx
->OFR2
&= ~ (uint32_t) ADC_OFR2_OFFSET2
;
1522 ADCx
->OFR2
|= (uint32_t)Offset
;
1526 * @brief Set the ADC channels conversion value offset3
1527 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1528 * @param ADC_Channel: the ADC channel to configure.
1529 * This parameter can be one of the following values:
1530 * @arg ADC_Channel_1: ADC Channel1 selected
1531 * @arg ADC_Channel_2: ADC Channel2 selected
1532 * @arg ADC_Channel_3: ADC Channel3 selected
1533 * @arg ADC_Channel_4: ADC Channel4 selected
1534 * @arg ADC_Channel_5: ADC Channel5 selected
1535 * @arg ADC_Channel_6: ADC Channel6 selected
1536 * @arg ADC_Channel_7: ADC Channel7 selected
1537 * @arg ADC_Channel_8: ADC Channel8 selected
1538 * @arg ADC_Channel_9: ADC Channel9 selected
1539 * @arg ADC_Channel_10: ADC Channel10 selected
1540 * @arg ADC_Channel_11: ADC Channel11 selected
1541 * @arg ADC_Channel_12: ADC Channel12 selected
1542 * @arg ADC_Channel_13: ADC Channel13 selected
1543 * @arg ADC_Channel_14: ADC Channel14 selected
1544 * @arg ADC_Channel_15: ADC Channel15 selected
1545 * @arg ADC_Channel_16: ADC Channel16 selected
1546 * @arg ADC_Channel_17: ADC Channel17 selected
1547 * @arg ADC_Channel_18: ADC Channel18 selected
1548 * @param Offset: the offset value for the selected ADC Channel
1549 * This parameter must be a 12bit value.
1552 void ADC_SetChannelOffset3(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, uint16_t Offset
)
1554 /* Check the parameters */
1555 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1556 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
1557 assert_param(IS_ADC_OFFSET(Offset
));
1559 /* Select the Channel */
1560 ADCx
->OFR3
&= ~ (uint32_t) ADC_OFR3_OFFSET3_CH
;
1561 ADCx
->OFR3
|= (uint32_t)((uint32_t)ADC_Channel
<< 26);
1563 /* Set the data offset */
1564 ADCx
->OFR3
&= ~ (uint32_t) ADC_OFR3_OFFSET3
;
1565 ADCx
->OFR3
|= (uint32_t)Offset
;
1569 * @brief Set the ADC channels conversion value offset4
1570 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1571 * @param ADC_Channel: the ADC channel to configure.
1572 * This parameter can be one of the following values:
1573 * @arg ADC_Channel_1: ADC Channel1 selected
1574 * @arg ADC_Channel_2: ADC Channel2 selected
1575 * @arg ADC_Channel_3: ADC Channel3 selected
1576 * @arg ADC_Channel_4: ADC Channel4 selected
1577 * @arg ADC_Channel_5: ADC Channel5 selected
1578 * @arg ADC_Channel_6: ADC Channel6 selected
1579 * @arg ADC_Channel_7: ADC Channel7 selected
1580 * @arg ADC_Channel_8: ADC Channel8 selected
1581 * @arg ADC_Channel_9: ADC Channel9 selected
1582 * @arg ADC_Channel_10: ADC Channel10 selected
1583 * @arg ADC_Channel_11: ADC Channel11 selected
1584 * @arg ADC_Channel_12: ADC Channel12 selected
1585 * @arg ADC_Channel_13: ADC Channel13 selected
1586 * @arg ADC_Channel_14: ADC Channel14 selected
1587 * @arg ADC_Channel_15: ADC Channel15 selected
1588 * @arg ADC_Channel_16: ADC Channel16 selected
1589 * @arg ADC_Channel_17: ADC Channel17 selected
1590 * @arg ADC_Channel_18: ADC Channel18 selected
1591 * @param Offset: the offset value for the selected ADC Channel
1592 * This parameter must be a 12bit value.
1595 void ADC_SetChannelOffset4(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, uint16_t Offset
)
1597 /* Check the parameters */
1598 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1599 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
1600 assert_param(IS_ADC_OFFSET(Offset
));
1602 /* Select the Channel */
1603 ADCx
->OFR4
&= ~ (uint32_t) ADC_OFR4_OFFSET4_CH
;
1604 ADCx
->OFR4
|= (uint32_t)((uint32_t)ADC_Channel
<< 26);
1606 /* Set the data offset */
1607 ADCx
->OFR4
&= ~ (uint32_t) ADC_OFR4_OFFSET4
;
1608 ADCx
->OFR4
|= (uint32_t)Offset
;
1612 * @brief Enables or disables the Offset1.
1613 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1614 * @param NewState: new state of the ADCx offset1.
1615 * This parameter can be: ENABLE or DISABLE.
1618 void ADC_ChannelOffset1Cmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1620 /* Check the parameters */
1621 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1622 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1624 if (NewState
!= DISABLE
)
1626 /* Set the OFFSET1_EN bit */
1627 ADCx
->OFR1
|= ADC_OFR1_OFFSET1_EN
;
1631 /* Reset the OFFSET1_EN bit */
1632 ADCx
->OFR1
&= ~(ADC_OFR1_OFFSET1_EN
);
1637 * @brief Enables or disables the Offset2.
1638 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1639 * @param NewState: new state of the ADCx offset2.
1640 * This parameter can be: ENABLE or DISABLE.
1643 void ADC_ChannelOffset2Cmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1645 /* Check the parameters */
1646 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1647 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1649 if (NewState
!= DISABLE
)
1651 /* Set the OFFSET1_EN bit */
1652 ADCx
->OFR2
|= ADC_OFR2_OFFSET2_EN
;
1656 /* Reset the OFFSET1_EN bit */
1657 ADCx
->OFR2
&= ~(ADC_OFR2_OFFSET2_EN
);
1662 * @brief Enables or disables the Offset3.
1663 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1664 * @param NewState: new state of the ADCx offset3.
1665 * This parameter can be: ENABLE or DISABLE.
1668 void ADC_ChannelOffset3Cmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1670 /* Check the parameters */
1671 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1672 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1674 if (NewState
!= DISABLE
)
1676 /* Set the OFFSET1_EN bit */
1677 ADCx
->OFR3
|= ADC_OFR3_OFFSET3_EN
;
1681 /* Reset the OFFSET1_EN bit */
1682 ADCx
->OFR3
&= ~(ADC_OFR3_OFFSET3_EN
);
1687 * @brief Enables or disables the Offset4.
1688 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1689 * @param NewState: new state of the ADCx offset4.
1690 * This parameter can be: ENABLE or DISABLE.
1693 void ADC_ChannelOffset4Cmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1695 /* Check the parameters */
1696 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1697 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1699 if (NewState
!= DISABLE
)
1701 /* Set the OFFSET1_EN bit */
1702 ADCx
->OFR4
|= ADC_OFR4_OFFSET4_EN
;
1706 /* Reset the OFFSET1_EN bit */
1707 ADCx
->OFR4
&= ~(ADC_OFR4_OFFSET4_EN
);
1715 /** @defgroup ADC_Group5 Regular Channels DMA Configuration functions
1716 * @brief Regular Channels DMA Configuration functions
1719 ===============================================================================
1720 ##### Regular Channels DMA Configuration functions #####
1721 ===============================================================================
1723 [..] This section provides functions allowing to configure the DMA for ADC regular
1724 channels. Since converted regular channel values are stored into a unique data register,
1725 it is useful to use DMA for conversion of more than one regular channel. This
1726 avoids the loss of the data already stored in the ADC Data register.
1728 (#) ADC_DMACmd() function is used to enable the ADC DMA mode, after each
1729 conversion of a regular channel, a DMA request is generated.
1730 (#) ADC_DMAConfig() function is used to select between the one shot DMA mode
1731 or the circular DMA mode
1738 * @brief Enables or disables the specified ADC DMA request.
1739 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1740 * @param NewState: new state of the selected ADC DMA transfer.
1741 * This parameter can be: ENABLE or DISABLE.
1744 void ADC_DMACmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1746 /* Check the parameters */
1747 assert_param(IS_ADC_DMA_PERIPH(ADCx
));
1748 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1749 if (NewState
!= DISABLE
)
1751 /* Enable the selected ADC DMA request */
1752 ADCx
->CFGR
|= ADC_CFGR_DMAEN
;
1756 /* Disable the selected ADC DMA request */
1757 ADCx
->CFGR
&= ~(uint32_t)ADC_CFGR_DMAEN
;
1762 * @brief Configure ADC DMA mode.
1763 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1764 * @param ADC_DMAMode: select the ADC DMA mode.
1765 * This parameter can be one of the following values:
1766 * @arg ADC_DMAMode_OneShot: ADC DMA Oneshot mode
1767 * @arg ADC_DMAMode_Circular: ADC DMA circular mode
1770 void ADC_DMAConfig(ADC_TypeDef
* ADCx
, uint32_t ADC_DMAMode
)
1772 /* Check the parameters */
1773 assert_param(IS_ADC_DMA_PERIPH(ADCx
));
1774 assert_param(IS_ADC_DMA_MODE(ADC_DMAMode
));
1776 /* Set or reset the DMACFG bit */
1777 ADCx
->CFGR
&= ~(uint32_t)ADC_CFGR_DMACFG
;
1778 ADCx
->CFGR
|= ADC_DMAMode
;
1785 /** @defgroup ADC_Group6 Injected channels Configuration functions
1786 * @brief Injected channels Configuration functions
1789 ===============================================================================
1790 ##### Injected channels Configuration functions #####
1791 ===============================================================================
1793 [..] This section provide functions allowing to manage the ADC Injected channels,
1796 (#) Configuration functions for Injected channels sample time
1797 (#) Functions to start and stop the injected conversion
1798 (#) unction to select the discontinuous mode
1799 (#) Function to get the Specified Injected channel conversion data: This subsection
1800 provides an important function in the ADC peripheral since it returns the
1801 converted data of the specific injected channel.
1808 * @brief Configures for the selected ADC injected channel its corresponding
1810 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1811 * @param ADC_Channel: the ADC channel to configure.
1812 * This parameter can be one of the following values:
1813 * @arg ADC_InjectedChannel_1: ADC Channel1 selected
1814 * @arg ADC_InjectedChannel_2: ADC Channel2 selected
1815 * @arg ADC_InjectedChannel_3: ADC Channel3 selected
1816 * @arg ADC_InjectedChannel_4: ADC Channel4 selected
1817 * @arg ADC_InjectedChannel_5: ADC Channel5 selected
1818 * @arg ADC_InjectedChannel_6: ADC Channel6 selected
1819 * @arg ADC_InjectedChannel_7: ADC Channel7 selected
1820 * @arg ADC_InjectedChannel_8: ADC Channel8 selected
1821 * @arg ADC_InjectedChannel_9: ADC Channel9 selected
1822 * @arg ADC_InjectedChannel_10: ADC Channel10 selected
1823 * @arg ADC_InjectedChannel_11: ADC Channel11 selected
1824 * @arg ADC_InjectedChannel_12: ADC Channel12 selected
1825 * @arg ADC_InjectedChannel_13: ADC Channel13 selected
1826 * @arg ADC_InjectedChannel_14: ADC Channel14 selected
1827 * @arg ADC_InjectedChannel_15: ADC Channel15 selected
1828 * @arg ADC_InjectedChannel_16: ADC Channel16 selected
1829 * @arg ADC_InjectedChannel_17: ADC Channel17 selected
1830 * @arg ADC_InjectedChannel_18: ADC Channel18 selected
1831 * @param ADC_SampleTime: The sample time value to be set for the selected channel.
1832 * This parameter can be one of the following values:
1833 * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
1834 * @arg ADC_SampleTime_2Cycles5: Sample time equal to 2.5 cycles
1835 * @arg ADC_SampleTime_4Cycles5: Sample time equal to 4.5 cycles
1836 * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
1837 * @arg ADC_SampleTime_19Cycles5: Sample time equal to 19.5 cycles
1838 * @arg ADC_SampleTime_61Cycles5: Sample time equal to 61.5 cycles
1839 * @arg ADC_SampleTime_181Cycles5: Sample time equal to 181.5 cycles
1840 * @arg ADC_SampleTime_601Cycles5: Sample time equal to 601.5 cycles
1843 void ADC_InjectedChannelSampleTimeConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_InjectedChannel
, uint8_t ADC_SampleTime
)
1845 uint32_t tmpreg1
= 0;
1846 /* Check the parameters */
1847 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1848 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel
));
1849 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime
));
1851 /* Channel sampling configuration */
1852 /* if ADC_InjectedChannel_10 ... ADC_InjectedChannel_18 is selected */
1853 if (ADC_InjectedChannel
> ADC_InjectedChannel_9
)
1855 /* Calculate the mask to clear */
1856 tmpreg1
= ADC_SMPR2_SMP10
<< (3 * (ADC_InjectedChannel
- 10));
1857 /* Clear the old channel sample time */
1858 ADCx
->SMPR2
&= ~tmpreg1
;
1859 /* Calculate the mask to set */
1860 ADCx
->SMPR2
|= (uint32_t)ADC_SampleTime
<< (3 * (ADC_InjectedChannel
- 10));
1863 else /* ADC_InjectedChannel include in ADC_InjectedChannel_[0..9] */
1865 /* Calculate the mask to clear */
1866 tmpreg1
= ADC_SMPR1_SMP1
<< (3 * (ADC_InjectedChannel
- 1));
1867 /* Clear the old channel sample time */
1868 ADCx
->SMPR1
&= ~tmpreg1
;
1869 /* Calculate the mask to set */
1870 ADCx
->SMPR1
|= (uint32_t)ADC_SampleTime
<< (3 * (ADC_InjectedChannel
));
1875 * @brief Enables or disables the selected ADC start of the injected
1876 * channels conversion.
1877 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1878 * @param NewState: new state of the selected ADC software start injected conversion.
1879 * This parameter can be: ENABLE or DISABLE.
1882 void ADC_StartInjectedConversion(ADC_TypeDef
* ADCx
)
1884 /* Check the parameters */
1885 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1887 /* Enable the selected ADC conversion for injected group on external event and start the selected
1888 ADC injected conversion */
1889 ADCx
->CR
|= ADC_CR_JADSTART
;
1893 * @brief Stops the selected ADC ongoing injected conversion.
1894 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1897 void ADC_StopInjectedConversion(ADC_TypeDef
* ADCx
)
1899 /* Check the parameters */
1900 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1902 /* Set the JADSTP bit */
1903 ADCx
->CR
|= ADC_CR_JADSTP
;
1907 * @brief Gets the selected ADC Software start injected conversion Status.
1908 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1909 * @retval The new state of ADC start injected conversion (SET or RESET).
1911 FlagStatus
ADC_GetStartInjectedConversionStatus(ADC_TypeDef
* ADCx
)
1913 FlagStatus bitstatus
= RESET
;
1914 /* Check the parameters */
1915 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1917 /* Check the status of JADSTART bit */
1918 if ((ADCx
->CR
& ADC_CR_JADSTART
) != (uint32_t)RESET
)
1920 /* JADSTART bit is set */
1925 /* JADSTART bit is reset */
1928 /* Return the JADSTART bit status */
1933 * @brief Enables or disables the selected ADC automatic injected group
1934 * conversion after regular one.
1935 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1936 * @param NewState: new state of the selected ADC auto injected conversion
1937 * This parameter can be: ENABLE or DISABLE.
1940 void ADC_AutoInjectedConvCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1942 /* Check the parameters */
1943 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1944 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1945 if (NewState
!= DISABLE
)
1947 /* Enable the selected ADC automatic injected group conversion */
1948 ADCx
->CFGR
|= ADC_CFGR_JAUTO
;
1952 /* Disable the selected ADC automatic injected group conversion */
1953 ADCx
->CFGR
&= ~ADC_CFGR_JAUTO
;
1958 * @brief Enables or disables the discontinuous mode for injected group
1959 * channel for the specified ADC
1960 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1961 * @param NewState: new state of the selected ADC discontinuous mode
1962 * on injected group channel.
1963 * This parameter can be: ENABLE or DISABLE.
1966 void ADC_InjectedDiscModeCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
1968 /* Check the parameters */
1969 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1970 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1971 if (NewState
!= DISABLE
)
1973 /* Enable the selected ADC injected discontinuous mode */
1974 ADCx
->CFGR
|= ADC_CFGR_JDISCEN
;
1978 /* Disable the selected ADC injected discontinuous mode */
1979 ADCx
->CFGR
&= ~ADC_CFGR_JDISCEN
;
1984 * @brief Returns the ADC injected channel conversion result
1985 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
1986 * @param ADC_InjectedSequence: the converted ADC injected sequence.
1987 * This parameter can be one of the following values:
1988 * @arg ADC_InjectedSequence_1: Injected Sequence1 selected
1989 * @arg ADC_InjectedSequence_2: Injected Sequence2 selected
1990 * @arg ADC_InjectedSequence_3: Injected Sequence3 selected
1991 * @arg ADC_InjectedSequence_4: Injected Sequence4 selected
1992 * @retval The Data conversion value.
1994 uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef
* ADCx
, uint8_t ADC_InjectedSequence
)
1996 __IO
uint32_t tmp
= 0;
1998 /* Check the parameters */
1999 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2000 assert_param(IS_ADC_INJECTED_SEQUENCE(ADC_InjectedSequence
));
2002 tmp
= (uint32_t)ADCx
;
2003 tmp
+= ((ADC_InjectedSequence
- 1 )<< 2) + JDR_Offset
;
2005 /* Returns the selected injected channel conversion data value */
2006 return (uint16_t) (*(__IO
uint32_t*) tmp
);
2013 /** @defgroup ADC_Group7 Interrupts and flags management functions
2014 * @brief Interrupts and flags management functions
2017 ===============================================================================
2018 ##### Interrupts and flags management functions #####
2019 ===============================================================================
2021 [..] This section provides functions allowing to configure the ADC Interrupts, get
2022 the status and clear flags and Interrupts pending bits.
2024 [..] The ADC provide 11 Interrupts sources and 11 Flags which can be divided into 3 groups:
2026 (#) Flags and Interrupts for ADC regular channels
2028 (+) ADC_FLAG_RDY: ADC Ready flag
2029 (+) ADC_FLAG_EOSMP: ADC End of Sampling flag
2030 (+) ADC_FLAG_EOC: ADC End of Regular Conversion flag.
2031 (+) ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
2032 (+) ADC_FLAG_OVR: ADC overrun flag
2035 (+) ADC_IT_RDY: ADC Ready interrupt source
2036 (+) ADC_IT_EOSMP: ADC End of Sampling interrupt source
2037 (+) ADC_IT_EOC: ADC End of Regular Conversion interrupt source
2038 (+) ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt
2039 (+) ADC_IT_OVR: ADC overrun interrupt source
2042 (#) Flags and Interrupts for ADC regular channels
2044 (+) ADC_FLAG_JEOC: ADC Ready flag
2045 (+) ADC_FLAG_JEOS: ADC End of Sampling flag
2046 (+) ADC_FLAG_JQOVF: ADC End of Regular Conversion flag.
2049 (+) ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
2050 (+) ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
2051 (+) ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
2053 (#) General Flags and Interrupts for the ADC
2055 (+) ADC_FLAG_AWD1: ADC Analog watchdog 1 flag
2056 (+) ADC_FLAG_AWD2: ADC Analog watchdog 2 flag
2057 (+) ADC_FLAG_AWD3: ADC Analog watchdog 3 flag
2060 (+) ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
2061 (+) ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
2062 (+) ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
2064 (#) Flags for ADC dual mode
2065 (##)Flags for Master
2066 (+) ADC_FLAG_MSTRDY: ADC master Ready (ADRDY) flag
2067 (+) ADC_FLAG_MSTEOSMP: ADC master End of Sampling flag
2068 (+) ADC_FLAG_MSTEOC: ADC master End of Regular Conversion flag
2069 (+) ADC_FLAG_MSTEOS: ADC master End of Regular sequence of Conversions flag
2070 (+) ADC_FLAG_MSTOVR: ADC master overrun flag
2071 (+) ADC_FLAG_MSTJEOC: ADC master End of Injected Conversion flag
2072 (+) ADC_FLAG_MSTJEOS: ADC master End of Injected sequence of Conversions flag
2073 (+) ADC_FLAG_MSTAWD1: ADC master Analog watchdog 1 flag
2074 (+) ADC_FLAG_MSTAWD2: ADC master Analog watchdog 2 flag
2075 (+) ADC_FLAG_MSTAWD3: ADC master Analog watchdog 3 flag
2076 (+) ADC_FLAG_MSTJQOVF: ADC master Injected Context Queue Overflow flag
2078 (##) Flags for Slave
2079 (+) ADC_FLAG_SLVRDY: ADC slave Ready (ADRDY) flag
2080 (+) ADC_FLAG_SLVEOSMP: ADC slave End of Sampling flag
2081 (+) ADC_FLAG_SLVEOC: ADC slave End of Regular Conversion flag
2082 (+) ADC_FLAG_SLVEOS: ADC slave End of Regular sequence of Conversions flag
2083 (+) ADC_FLAG_SLVOVR: ADC slave overrun flag
2084 (+) ADC_FLAG_SLVJEOC: ADC slave End of Injected Conversion flag
2085 (+) ADC_FLAG_SLVJEOS: ADC slave End of Injected sequence of Conversions flag
2086 (+) ADC_FLAG_SLVAWD1: ADC slave Analog watchdog 1 flag
2087 (+) ADC_FLAG_SLVAWD2: ADC slave Analog watchdog 2 flag
2088 (+) ADC_FLAG_SLVAWD3: ADC slave Analog watchdog 3 flag
2089 (+) ADC_FLAG_SLVJQOVF: ADC slave Injected Context Queue Overflow flag
2091 The user should identify which mode will be used in his application to manage
2092 the ADC controller events: Polling mode or Interrupt mode.
2094 In the Polling Mode it is advised to use the following functions:
2095 - ADC_GetFlagStatus() : to check if flags events occur.
2096 - ADC_ClearFlag() : to clear the flags events.
2098 In the Interrupt Mode it is advised to use the following functions:
2099 - ADC_ITConfig() : to enable or disable the interrupt source.
2100 - ADC_GetITStatus() : to check if Interrupt occurs.
2101 - ADC_ClearITPendingBit() : to clear the Interrupt pending Bit
2102 (corresponding Flag).
2108 * @brief Enables or disables the specified ADC interrupts.
2109 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
2110 * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
2111 * This parameter can be any combination of the following values:
2112 * @arg ADC_IT_RDY: ADC Ready (ADRDY) interrupt source
2113 * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
2114 * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
2115 * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
2116 * @arg ADC_IT_OVR: ADC overrun interrupt source
2117 * @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
2118 * @arg ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
2119 * @arg ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
2120 * @arg ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
2121 * @arg ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
2122 * @arg ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
2123 * @param NewState: new state of the specified ADC interrupts.
2124 * This parameter can be: ENABLE or DISABLE.
2127 void ADC_ITConfig(ADC_TypeDef
* ADCx
, uint32_t ADC_IT
, FunctionalState NewState
)
2129 /* Check the parameters */
2130 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2131 assert_param(IS_FUNCTIONAL_STATE(NewState
));
2132 assert_param(IS_ADC_IT(ADC_IT
));
2134 if (NewState
!= DISABLE
)
2136 /* Enable the selected ADC interrupts */
2137 ADCx
->IER
|= ADC_IT
;
2141 /* Disable the selected ADC interrupts */
2142 ADCx
->IER
&= (~(uint32_t)ADC_IT
);
2147 * @brief Checks whether the specified ADC flag is set or not.
2148 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
2149 * @param ADC_FLAG: specifies the flag to check.
2150 * This parameter can be one of the following values:
2151 * @arg ADC_FLAG_RDY: ADC Ready (ADRDY) flag
2152 * @arg ADC_FLAG_EOSMP: ADC End of Sampling flag
2153 * @arg ADC_FLAG_EOC: ADC End of Regular Conversion flag
2154 * @arg ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
2155 * @arg ADC_FLAG_OVR: ADC overrun flag
2156 * @arg ADC_FLAG_JEOC: ADC End of Injected Conversion flag
2157 * @arg ADC_FLAG_JEOS: ADC End of Injected sequence of Conversions flag
2158 * @arg ADC_FLAG_AWD1: ADC Analog watchdog 1 flag
2159 * @arg ADC_FLAG_AWD2: ADC Analog watchdog 2 flag
2160 * @arg ADC_FLAG_AWD3: ADC Analog watchdog 3 flag
2161 * @arg ADC_FLAG_JQOVF: ADC Injected Context Queue Overflow flag
2162 * @retval The new state of ADC_FLAG (SET or RESET).
2164 FlagStatus
ADC_GetFlagStatus(ADC_TypeDef
* ADCx
, uint32_t ADC_FLAG
)
2166 FlagStatus bitstatus
= RESET
;
2167 /* Check the parameters */
2168 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2169 assert_param(IS_ADC_GET_FLAG(ADC_FLAG
));
2171 /* Check the status of the specified ADC flag */
2172 if ((ADCx
->ISR
& ADC_FLAG
) != (uint32_t)RESET
)
2174 /* ADC_FLAG is set */
2179 /* ADC_FLAG is reset */
2182 /* Return the ADC_FLAG status */
2187 * @brief Clears the ADCx's pending flags.
2188 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
2189 * @param ADC_FLAG: specifies the flag to clear.
2190 * This parameter can be any combination of the following values:
2191 * @arg ADC_FLAG_RDY: ADC Ready (ADRDY) flag
2192 * @arg ADC_FLAG_EOSMP: ADC End of Sampling flag
2193 * @arg ADC_FLAG_EOC: ADC End of Regular Conversion flag
2194 * @arg ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
2195 * @arg ADC_FLAG_OVR: ADC overrun flag
2196 * @arg ADC_FLAG_JEOC: ADC End of Injected Conversion flag
2197 * @arg ADC_FLAG_JEOS: ADC End of Injected sequence of Conversions flag
2198 * @arg ADC_FLAG_AWD1: ADC Analog watchdog 1 flag
2199 * @arg ADC_FLAG_AWD2: ADC Analog watchdog 2 flag
2200 * @arg ADC_FLAG_AWD3: ADC Analog watchdog 3 flag
2201 * @arg ADC_FLAG_JQOVF: ADC Injected Context Queue Overflow flag
2204 void ADC_ClearFlag(ADC_TypeDef
* ADCx
, uint32_t ADC_FLAG
)
2206 /* Check the parameters */
2207 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2208 assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG
));
2209 /* Clear the selected ADC flags */
2210 ADCx
->ISR
= (uint32_t)ADC_FLAG
;
2214 * @brief Checks whether the specified ADC flag is set or not.
2215 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
2216 * @param ADC_FLAG: specifies the master or slave flag to check.
2217 * This parameter can be one of the following values:
2218 * @arg ADC_FLAG_MSTRDY: ADC master Ready (ADRDY) flag
2219 * @arg ADC_FLAG_MSTEOSMP: ADC master End of Sampling flag
2220 * @arg ADC_FLAG_MSTEOC: ADC master End of Regular Conversion flag
2221 * @arg ADC_FLAG_MSTEOS: ADC master End of Regular sequence of Conversions flag
2222 * @arg ADC_FLAG_MSTOVR: ADC master overrun flag
2223 * @arg ADC_FLAG_MSTJEOC: ADC master End of Injected Conversion flag
2224 * @arg ADC_FLAG_MSTJEOS: ADC master End of Injected sequence of Conversions flag
2225 * @arg ADC_FLAG_MSTAWD1: ADC master Analog watchdog 1 flag
2226 * @arg ADC_FLAG_MSTAWD2: ADC master Analog watchdog 2 flag
2227 * @arg ADC_FLAG_MSTAWD3: ADC master Analog watchdog 3 flag
2228 * @arg ADC_FLAG_MSTJQOVF: ADC master Injected Context Queue Overflow flag
2229 * @arg ADC_FLAG_SLVRDY: ADC slave Ready (ADRDY) flag
2230 * @arg ADC_FLAG_SLVEOSMP: ADC slave End of Sampling flag
2231 * @arg ADC_FLAG_SLVEOC: ADC slave End of Regular Conversion flag
2232 * @arg ADC_FLAG_SLVEOS: ADC slave End of Regular sequence of Conversions flag
2233 * @arg ADC_FLAG_SLVOVR: ADC slave overrun flag
2234 * @arg ADC_FLAG_SLVJEOC: ADC slave End of Injected Conversion flag
2235 * @arg ADC_FLAG_SLVJEOS: ADC slave End of Injected sequence of Conversions flag
2236 * @arg ADC_FLAG_SLVAWD1: ADC slave Analog watchdog 1 flag
2237 * @arg ADC_FLAG_SLVAWD2: ADC slave Analog watchdog 2 flag
2238 * @arg ADC_FLAG_SLVAWD3: ADC slave Analog watchdog 3 flag
2239 * @arg ADC_FLAG_SLVJQOVF: ADC slave Injected Context Queue Overflow flag
2240 * @retval The new state of ADC_FLAG (SET or RESET).
2242 FlagStatus
ADC_GetCommonFlagStatus(ADC_TypeDef
* ADCx
, uint32_t ADC_FLAG
)
2244 uint32_t tmpreg1
= 0;
2245 FlagStatus bitstatus
= RESET
;
2247 /* Check the parameters */
2248 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2249 assert_param(IS_ADC_GET_COMMONFLAG(ADC_FLAG
));
2251 if((ADCx
== ADC1
) || (ADCx
== ADC2
))
2253 tmpreg1
= ADC1_2
->CSR
;
2257 tmpreg1
= ADC3_4
->CSR
;
2259 /* Check the status of the specified ADC flag */
2260 if ((tmpreg1
& ADC_FLAG
) != (uint32_t)RESET
)
2262 /* ADC_FLAG is set */
2267 /* ADC_FLAG is reset */
2270 /* Return the ADC_FLAG status */
2275 * @brief Clears the ADCx's pending flags.
2276 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
2277 * @param ADC_FLAG: specifies the master or slave flag to clear.
2278 * This parameter can be one of the following values:
2279 * @arg ADC_FLAG_MSTRDY: ADC master Ready (ADRDY) flag
2280 * @arg ADC_FLAG_MSTEOSMP: ADC master End of Sampling flag
2281 * @arg ADC_FLAG_MSTEOC: ADC master End of Regular Conversion flag
2282 * @arg ADC_FLAG_MSTEOS: ADC master End of Regular sequence of Conversions flag
2283 * @arg ADC_FLAG_MSTOVR: ADC master overrun flag
2284 * @arg ADC_FLAG_MSTJEOC: ADC master End of Injected Conversion flag
2285 * @arg ADC_FLAG_MSTJEOS: ADC master End of Injected sequence of Conversions flag
2286 * @arg ADC_FLAG_MSTAWD1: ADC master Analog watchdog 1 flag
2287 * @arg ADC_FLAG_MSTAWD2: ADC master Analog watchdog 2 flag
2288 * @arg ADC_FLAG_MSTAWD3: ADC master Analog watchdog 3 flag
2289 * @arg ADC_FLAG_MSTJQOVF: ADC master Injected Context Queue Overflow flag
2290 * @arg ADC_FLAG_SLVRDY: ADC slave Ready (ADRDY) flag
2291 * @arg ADC_FLAG_SLVEOSMP: ADC slave End of Sampling flag
2292 * @arg ADC_FLAG_SLVEOC: ADC slave End of Regular Conversion flag
2293 * @arg ADC_FLAG_SLVEOS: ADC slave End of Regular sequence of Conversions flag
2294 * @arg ADC_FLAG_SLVOVR: ADC slave overrun flag
2295 * @arg ADC_FLAG_SLVJEOC: ADC slave End of Injected Conversion flag
2296 * @arg ADC_FLAG_SLVJEOS: ADC slave End of Injected sequence of Conversions flag
2297 * @arg ADC_FLAG_SLVAWD1: ADC slave Analog watchdog 1 flag
2298 * @arg ADC_FLAG_SLVAWD2: ADC slave Analog watchdog 2 flag
2299 * @arg ADC_FLAG_SLVAWD3: ADC slave Analog watchdog 3 flag
2300 * @arg ADC_FLAG_SLVJQOVF: ADC slave Injected Context Queue Overflow flag
2303 void ADC_ClearCommonFlag(ADC_TypeDef
* ADCx
, uint32_t ADC_FLAG
)
2305 /* Check the parameters */
2306 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2307 assert_param(IS_ADC_CLEAR_COMMONFLAG(ADC_FLAG
));
2309 if((ADCx
== ADC1
) || (ADCx
== ADC2
))
2311 /* Clear the selected ADC flags */
2312 ADC1_2
->CSR
|= (uint32_t)ADC_FLAG
;
2316 /* Clear the selected ADC flags */
2317 ADC3_4
->CSR
|= (uint32_t)ADC_FLAG
;
2322 * @brief Checks whether the specified ADC interrupt has occurred or not.
2323 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
2324 * @param ADC_IT: specifies the ADC interrupt source to check.
2325 * This parameter can be one of the following values:
2326 * @arg ADC_IT_RDY: ADC Ready (ADRDY) interrupt source
2327 * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
2328 * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
2329 * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
2330 * @arg ADC_IT_OVR: ADC overrun interrupt source
2331 * @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
2332 * @arg ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
2333 * @arg ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
2334 * @arg ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
2335 * @arg ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
2336 * @arg ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
2337 * @retval The new state of ADC_IT (SET or RESET).
2339 ITStatus
ADC_GetITStatus(ADC_TypeDef
* ADCx
, uint32_t ADC_IT
)
2341 ITStatus bitstatus
= RESET
;
2342 uint16_t itstatus
= 0x0, itenable
= 0x0;
2343 /* Check the parameters */
2344 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2345 assert_param(IS_ADC_GET_IT(ADC_IT
));
2347 itstatus
= ADCx
->ISR
& ADC_IT
;
2349 itenable
= ADCx
->IER
& ADC_IT
;
2350 if ((itstatus
!= (uint32_t)RESET
) && (itenable
!= (uint32_t)RESET
))
2362 * @brief Clears the ADCx's interrupt pending bits.
2363 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
2364 * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
2365 * This parameter can be any combination of the following values:
2366 * @arg ADC_IT_RDY: ADC Ready (ADRDY) interrupt source
2367 * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
2368 * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
2369 * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
2370 * @arg ADC_IT_OVR: ADC overrun interrupt source
2371 * @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
2372 * @arg ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
2373 * @arg ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
2374 * @arg ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
2375 * @arg ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
2376 * @arg ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
2379 void ADC_ClearITPendingBit(ADC_TypeDef
* ADCx
, uint32_t ADC_IT
)
2381 /* Check the parameters */
2382 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
2383 assert_param(IS_ADC_IT(ADC_IT
));
2384 /* Clear the selected ADC interrupt pending bit */
2385 ADCx
->ISR
= (uint32_t)ADC_IT
;
2404 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/