2 ******************************************************************************
3 * @file stm32f10x_adc.c
4 * @author MCD Application Team
7 * @brief This file provides all the ADC firmware functions.
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x_adc.h"
24 #include "stm32f10x_rcc.h"
26 /** @addtogroup STM32F10x_StdPeriph_Driver
31 * @brief ADC driver modules
35 /** @defgroup ADC_Private_TypesDefinitions
43 /** @defgroup ADC_Private_Defines
47 /* ADC DISCNUM mask */
48 #define CR1_DISCNUM_Reset ((uint32_t)0xFFFF1FFF)
51 #define CR1_DISCEN_Set ((uint32_t)0x00000800)
52 #define CR1_DISCEN_Reset ((uint32_t)0xFFFFF7FF)
55 #define CR1_JAUTO_Set ((uint32_t)0x00000400)
56 #define CR1_JAUTO_Reset ((uint32_t)0xFFFFFBFF)
58 /* ADC JDISCEN mask */
59 #define CR1_JDISCEN_Set ((uint32_t)0x00001000)
60 #define CR1_JDISCEN_Reset ((uint32_t)0xFFFFEFFF)
63 #define CR1_AWDCH_Reset ((uint32_t)0xFFFFFFE0)
65 /* ADC Analog watchdog enable mode mask */
66 #define CR1_AWDMode_Reset ((uint32_t)0xFF3FFDFF)
68 /* CR1 register Mask */
69 #define CR1_CLEAR_Mask ((uint32_t)0xFFF0FEFF)
72 #define CR2_ADON_Set ((uint32_t)0x00000001)
73 #define CR2_ADON_Reset ((uint32_t)0xFFFFFFFE)
76 #define CR2_DMA_Set ((uint32_t)0x00000100)
77 #define CR2_DMA_Reset ((uint32_t)0xFFFFFEFF)
80 #define CR2_RSTCAL_Set ((uint32_t)0x00000008)
83 #define CR2_CAL_Set ((uint32_t)0x00000004)
85 /* ADC SWSTART mask */
86 #define CR2_SWSTART_Set ((uint32_t)0x00400000)
88 /* ADC EXTTRIG mask */
89 #define CR2_EXTTRIG_Set ((uint32_t)0x00100000)
90 #define CR2_EXTTRIG_Reset ((uint32_t)0xFFEFFFFF)
92 /* ADC Software start mask */
93 #define CR2_EXTTRIG_SWSTART_Set ((uint32_t)0x00500000)
94 #define CR2_EXTTRIG_SWSTART_Reset ((uint32_t)0xFFAFFFFF)
96 /* ADC JEXTSEL mask */
97 #define CR2_JEXTSEL_Reset ((uint32_t)0xFFFF8FFF)
99 /* ADC JEXTTRIG mask */
100 #define CR2_JEXTTRIG_Set ((uint32_t)0x00008000)
101 #define CR2_JEXTTRIG_Reset ((uint32_t)0xFFFF7FFF)
103 /* ADC JSWSTART mask */
104 #define CR2_JSWSTART_Set ((uint32_t)0x00200000)
106 /* ADC injected software start mask */
107 #define CR2_JEXTTRIG_JSWSTART_Set ((uint32_t)0x00208000)
108 #define CR2_JEXTTRIG_JSWSTART_Reset ((uint32_t)0xFFDF7FFF)
111 #define CR2_TSVREFE_Set ((uint32_t)0x00800000)
112 #define CR2_TSVREFE_Reset ((uint32_t)0xFF7FFFFF)
114 /* CR2 register Mask */
115 #define CR2_CLEAR_Mask ((uint32_t)0xFFF1F7FD)
118 #define SQR3_SQ_Set ((uint32_t)0x0000001F)
119 #define SQR2_SQ_Set ((uint32_t)0x0000001F)
120 #define SQR1_SQ_Set ((uint32_t)0x0000001F)
122 /* SQR1 register Mask */
123 #define SQR1_CLEAR_Mask ((uint32_t)0xFF0FFFFF)
126 #define JSQR_JSQ_Set ((uint32_t)0x0000001F)
129 #define JSQR_JL_Set ((uint32_t)0x00300000)
130 #define JSQR_JL_Reset ((uint32_t)0xFFCFFFFF)
133 #define SMPR1_SMP_Set ((uint32_t)0x00000007)
134 #define SMPR2_SMP_Set ((uint32_t)0x00000007)
136 /* ADC JDRx registers offset */
137 #define JDR_Offset ((uint8_t)0x28)
139 /* ADC1 DR register base address */
140 #define DR_ADDRESS ((uint32_t)0x4001244C)
146 /** @defgroup ADC_Private_Macros
154 /** @defgroup ADC_Private_Variables
162 /** @defgroup ADC_Private_FunctionPrototypes
170 /** @defgroup ADC_Private_Functions
175 * @brief Deinitializes the ADCx peripheral registers to their default reset values.
176 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
179 void ADC_DeInit(ADC_TypeDef
* ADCx
)
181 /* Check the parameters */
182 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
186 /* Enable ADC1 reset state */
187 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1
, ENABLE
);
188 /* Release ADC1 from reset state */
189 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1
, DISABLE
);
191 else if (ADCx
== ADC2
)
193 /* Enable ADC2 reset state */
194 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2
, ENABLE
);
195 /* Release ADC2 from reset state */
196 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2
, DISABLE
);
202 /* Enable ADC3 reset state */
203 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3
, ENABLE
);
204 /* Release ADC3 from reset state */
205 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC3
, DISABLE
);
211 * @brief Initializes the ADCx peripheral according to the specified parameters
212 * in the ADC_InitStruct.
213 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
214 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
215 * the configuration information for the specified ADC peripheral.
218 void ADC_Init(ADC_TypeDef
* ADCx
, ADC_InitTypeDef
* ADC_InitStruct
)
220 uint32_t tmpreg1
= 0;
222 /* Check the parameters */
223 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
224 assert_param(IS_ADC_MODE(ADC_InitStruct
->ADC_Mode
));
225 assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct
->ADC_ScanConvMode
));
226 assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct
->ADC_ContinuousConvMode
));
227 assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct
->ADC_ExternalTrigConv
));
228 assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct
->ADC_DataAlign
));
229 assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct
->ADC_NbrOfChannel
));
231 /*---------------------------- ADCx CR1 Configuration -----------------*/
232 /* Get the ADCx CR1 value */
234 /* Clear DUALMOD and SCAN bits */
235 tmpreg1
&= CR1_CLEAR_Mask
;
236 /* Configure ADCx: Dual mode and scan conversion mode */
237 /* Set DUALMOD bits according to ADC_Mode value */
238 /* Set SCAN bit according to ADC_ScanConvMode value */
239 tmpreg1
|= (uint32_t)(ADC_InitStruct
->ADC_Mode
| ((uint32_t)ADC_InitStruct
->ADC_ScanConvMode
<< 8));
240 /* Write to ADCx CR1 */
243 /*---------------------------- ADCx CR2 Configuration -----------------*/
244 /* Get the ADCx CR2 value */
246 /* Clear CONT, ALIGN and EXTSEL bits */
247 tmpreg1
&= CR2_CLEAR_Mask
;
248 /* Configure ADCx: external trigger event and continuous conversion mode */
249 /* Set ALIGN bit according to ADC_DataAlign value */
250 /* Set EXTSEL bits according to ADC_ExternalTrigConv value */
251 /* Set CONT bit according to ADC_ContinuousConvMode value */
252 tmpreg1
|= (uint32_t)(ADC_InitStruct
->ADC_DataAlign
| ADC_InitStruct
->ADC_ExternalTrigConv
|
253 ((uint32_t)ADC_InitStruct
->ADC_ContinuousConvMode
<< 1));
254 /* Write to ADCx CR2 */
257 /*---------------------------- ADCx SQR1 Configuration -----------------*/
258 /* Get the ADCx SQR1 value */
259 tmpreg1
= ADCx
->SQR1
;
261 tmpreg1
&= SQR1_CLEAR_Mask
;
262 /* Configure ADCx: regular channel sequence length */
263 /* Set L bits according to ADC_NbrOfChannel value */
264 tmpreg2
|= (uint8_t) (ADC_InitStruct
->ADC_NbrOfChannel
- (uint8_t)1);
265 tmpreg1
|= (uint32_t)tmpreg2
<< 20;
266 /* Write to ADCx SQR1 */
267 ADCx
->SQR1
= tmpreg1
;
271 * @brief Fills each ADC_InitStruct member with its default value.
272 * @param ADC_InitStruct : pointer to an ADC_InitTypeDef structure which will be initialized.
275 void ADC_StructInit(ADC_InitTypeDef
* ADC_InitStruct
)
277 /* Reset ADC init structure parameters values */
278 /* Initialize the ADC_Mode member */
279 ADC_InitStruct
->ADC_Mode
= ADC_Mode_Independent
;
280 /* initialize the ADC_ScanConvMode member */
281 ADC_InitStruct
->ADC_ScanConvMode
= DISABLE
;
282 /* Initialize the ADC_ContinuousConvMode member */
283 ADC_InitStruct
->ADC_ContinuousConvMode
= DISABLE
;
284 /* Initialize the ADC_ExternalTrigConv member */
285 ADC_InitStruct
->ADC_ExternalTrigConv
= ADC_ExternalTrigConv_T1_CC1
;
286 /* Initialize the ADC_DataAlign member */
287 ADC_InitStruct
->ADC_DataAlign
= ADC_DataAlign_Right
;
288 /* Initialize the ADC_NbrOfChannel member */
289 ADC_InitStruct
->ADC_NbrOfChannel
= 1;
293 * @brief Enables or disables the specified ADC peripheral.
294 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
295 * @param NewState: new state of the ADCx peripheral.
296 * This parameter can be: ENABLE or DISABLE.
299 void ADC_Cmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
301 /* Check the parameters */
302 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
303 assert_param(IS_FUNCTIONAL_STATE(NewState
));
304 if (NewState
!= DISABLE
)
306 /* Set the ADON bit to wake up the ADC from power down mode */
307 ADCx
->CR2
|= CR2_ADON_Set
;
311 /* Disable the selected ADC peripheral */
312 ADCx
->CR2
&= CR2_ADON_Reset
;
317 * @brief Enables or disables the specified ADC DMA request.
318 * @param ADCx: where x can be 1 or 3 to select the ADC peripheral.
319 * Note: ADC2 hasn't a DMA capability.
320 * @param NewState: new state of the selected ADC DMA transfer.
321 * This parameter can be: ENABLE or DISABLE.
324 void ADC_DMACmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
326 /* Check the parameters */
327 assert_param(IS_ADC_DMA_PERIPH(ADCx
));
328 assert_param(IS_FUNCTIONAL_STATE(NewState
));
329 if (NewState
!= DISABLE
)
331 /* Enable the selected ADC DMA request */
332 ADCx
->CR2
|= CR2_DMA_Set
;
336 /* Disable the selected ADC DMA request */
337 ADCx
->CR2
&= CR2_DMA_Reset
;
342 * @brief Enables or disables the specified ADC interrupts.
343 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
344 * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
345 * This parameter can be any combination of the following values:
346 * @arg ADC_IT_EOC: End of conversion interrupt mask
347 * @arg ADC_IT_AWD: Analog watchdog interrupt mask
348 * @arg ADC_IT_JEOC: End of injected conversion interrupt mask
349 * @param NewState: new state of the specified ADC interrupts.
350 * This parameter can be: ENABLE or DISABLE.
353 void ADC_ITConfig(ADC_TypeDef
* ADCx
, uint16_t ADC_IT
, FunctionalState NewState
)
356 /* Check the parameters */
357 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
358 assert_param(IS_FUNCTIONAL_STATE(NewState
));
359 assert_param(IS_ADC_IT(ADC_IT
));
360 /* Get the ADC IT index */
361 itmask
= (uint8_t)ADC_IT
;
362 if (NewState
!= DISABLE
)
364 /* Enable the selected ADC interrupts */
369 /* Disable the selected ADC interrupts */
370 ADCx
->CR1
&= (~(uint32_t)itmask
);
375 * @brief Resets the selected ADC calibration registers.
376 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
379 void ADC_ResetCalibration(ADC_TypeDef
* ADCx
)
381 /* Check the parameters */
382 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
383 /* Resets the selected ADC calibration registers */
384 ADCx
->CR2
|= CR2_RSTCAL_Set
;
388 * @brief Gets the selected ADC reset calibration registers status.
389 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
390 * @retval The new state of ADC reset calibration registers (SET or RESET).
392 FlagStatus
ADC_GetResetCalibrationStatus(ADC_TypeDef
* ADCx
)
394 FlagStatus bitstatus
= RESET
;
395 /* Check the parameters */
396 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
397 /* Check the status of RSTCAL bit */
398 if ((ADCx
->CR2
& CR2_RSTCAL_Set
) != (uint32_t)RESET
)
400 /* RSTCAL bit is set */
405 /* RSTCAL bit is reset */
408 /* Return the RSTCAL bit status */
413 * @brief Starts the selected ADC calibration process.
414 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
417 void ADC_StartCalibration(ADC_TypeDef
* ADCx
)
419 /* Check the parameters */
420 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
421 /* Enable the selected ADC calibration process */
422 ADCx
->CR2
|= CR2_CAL_Set
;
426 * @brief Gets the selected ADC calibration status.
427 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
428 * @retval The new state of ADC calibration (SET or RESET).
430 FlagStatus
ADC_GetCalibrationStatus(ADC_TypeDef
* ADCx
)
432 FlagStatus bitstatus
= RESET
;
433 /* Check the parameters */
434 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
435 /* Check the status of CAL bit */
436 if ((ADCx
->CR2
& CR2_CAL_Set
) != (uint32_t)RESET
)
438 /* CAL bit is set: calibration on going */
443 /* CAL bit is reset: end of calibration */
446 /* Return the CAL bit status */
451 * @brief Enables or disables the selected ADC software start conversion .
452 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
453 * @param NewState: new state of the selected ADC software start conversion.
454 * This parameter can be: ENABLE or DISABLE.
457 void ADC_SoftwareStartConvCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
459 /* Check the parameters */
460 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
461 assert_param(IS_FUNCTIONAL_STATE(NewState
));
462 if (NewState
!= DISABLE
)
464 /* Enable the selected ADC conversion on external event and start the selected
466 ADCx
->CR2
|= CR2_EXTTRIG_SWSTART_Set
;
470 /* Disable the selected ADC conversion on external event and stop the selected
472 ADCx
->CR2
&= CR2_EXTTRIG_SWSTART_Reset
;
477 * @brief Gets the selected ADC Software start conversion Status.
478 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
479 * @retval The new state of ADC software start conversion (SET or RESET).
481 FlagStatus
ADC_GetSoftwareStartConvStatus(ADC_TypeDef
* ADCx
)
483 FlagStatus bitstatus
= RESET
;
484 /* Check the parameters */
485 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
486 /* Check the status of SWSTART bit */
487 if ((ADCx
->CR2
& CR2_SWSTART_Set
) != (uint32_t)RESET
)
489 /* SWSTART bit is set */
494 /* SWSTART bit is reset */
497 /* Return the SWSTART bit status */
502 * @brief Configures the discontinuous mode for the selected ADC regular
504 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
505 * @param Number: specifies the discontinuous mode regular channel
506 * count value. This number must be between 1 and 8.
509 void ADC_DiscModeChannelCountConfig(ADC_TypeDef
* ADCx
, uint8_t Number
)
511 uint32_t tmpreg1
= 0;
512 uint32_t tmpreg2
= 0;
513 /* Check the parameters */
514 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
515 assert_param(IS_ADC_REGULAR_DISC_NUMBER(Number
));
516 /* Get the old register value */
518 /* Clear the old discontinuous mode channel count */
519 tmpreg1
&= CR1_DISCNUM_Reset
;
520 /* Set the discontinuous mode channel count */
521 tmpreg2
= Number
- 1;
522 tmpreg1
|= tmpreg2
<< 13;
523 /* Store the new register value */
528 * @brief Enables or disables the discontinuous mode on regular group
529 * channel for the specified ADC
530 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
531 * @param NewState: new state of the selected ADC discontinuous mode
532 * on regular group channel.
533 * This parameter can be: ENABLE or DISABLE.
536 void ADC_DiscModeCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
538 /* Check the parameters */
539 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
540 assert_param(IS_FUNCTIONAL_STATE(NewState
));
541 if (NewState
!= DISABLE
)
543 /* Enable the selected ADC regular discontinuous mode */
544 ADCx
->CR1
|= CR1_DISCEN_Set
;
548 /* Disable the selected ADC regular discontinuous mode */
549 ADCx
->CR1
&= CR1_DISCEN_Reset
;
554 * @brief Configures for the selected ADC regular channel its corresponding
555 * rank in the sequencer and its sample time.
556 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
557 * @param ADC_Channel: the ADC channel to configure.
558 * This parameter can be one of the following values:
559 * @arg ADC_Channel_0: ADC Channel0 selected
560 * @arg ADC_Channel_1: ADC Channel1 selected
561 * @arg ADC_Channel_2: ADC Channel2 selected
562 * @arg ADC_Channel_3: ADC Channel3 selected
563 * @arg ADC_Channel_4: ADC Channel4 selected
564 * @arg ADC_Channel_5: ADC Channel5 selected
565 * @arg ADC_Channel_6: ADC Channel6 selected
566 * @arg ADC_Channel_7: ADC Channel7 selected
567 * @arg ADC_Channel_8: ADC Channel8 selected
568 * @arg ADC_Channel_9: ADC Channel9 selected
569 * @arg ADC_Channel_10: ADC Channel10 selected
570 * @arg ADC_Channel_11: ADC Channel11 selected
571 * @arg ADC_Channel_12: ADC Channel12 selected
572 * @arg ADC_Channel_13: ADC Channel13 selected
573 * @arg ADC_Channel_14: ADC Channel14 selected
574 * @arg ADC_Channel_15: ADC Channel15 selected
575 * @arg ADC_Channel_16: ADC Channel16 selected
576 * @arg ADC_Channel_17: ADC Channel17 selected
577 * @param Rank: The rank in the regular group sequencer. This parameter must be between 1 to 16.
578 * @param ADC_SampleTime: The sample time value to be set for the selected channel.
579 * This parameter can be one of the following values:
580 * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
581 * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
582 * @arg ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
583 * @arg ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles
584 * @arg ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles
585 * @arg ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles
586 * @arg ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles
587 * @arg ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles
590 void ADC_RegularChannelConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, uint8_t Rank
, uint8_t ADC_SampleTime
)
592 uint32_t tmpreg1
= 0, tmpreg2
= 0;
593 /* Check the parameters */
594 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
595 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
596 assert_param(IS_ADC_REGULAR_RANK(Rank
));
597 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime
));
598 /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
599 if (ADC_Channel
> ADC_Channel_9
)
601 /* Get the old register value */
602 tmpreg1
= ADCx
->SMPR1
;
603 /* Calculate the mask to clear */
604 tmpreg2
= SMPR1_SMP_Set
<< (3 * (ADC_Channel
- 10));
605 /* Clear the old channel sample time */
607 /* Calculate the mask to set */
608 tmpreg2
= (uint32_t)ADC_SampleTime
<< (3 * (ADC_Channel
- 10));
609 /* Set the new channel sample time */
611 /* Store the new register value */
612 ADCx
->SMPR1
= tmpreg1
;
614 else /* ADC_Channel include in ADC_Channel_[0..9] */
616 /* Get the old register value */
617 tmpreg1
= ADCx
->SMPR2
;
618 /* Calculate the mask to clear */
619 tmpreg2
= SMPR2_SMP_Set
<< (3 * ADC_Channel
);
620 /* Clear the old channel sample time */
622 /* Calculate the mask to set */
623 tmpreg2
= (uint32_t)ADC_SampleTime
<< (3 * ADC_Channel
);
624 /* Set the new channel sample time */
626 /* Store the new register value */
627 ADCx
->SMPR2
= tmpreg1
;
629 /* For Rank 1 to 6 */
632 /* Get the old register value */
633 tmpreg1
= ADCx
->SQR3
;
634 /* Calculate the mask to clear */
635 tmpreg2
= SQR3_SQ_Set
<< (5 * (Rank
- 1));
636 /* Clear the old SQx bits for the selected rank */
638 /* Calculate the mask to set */
639 tmpreg2
= (uint32_t)ADC_Channel
<< (5 * (Rank
- 1));
640 /* Set the SQx bits for the selected rank */
642 /* Store the new register value */
643 ADCx
->SQR3
= tmpreg1
;
645 /* For Rank 7 to 12 */
648 /* Get the old register value */
649 tmpreg1
= ADCx
->SQR2
;
650 /* Calculate the mask to clear */
651 tmpreg2
= SQR2_SQ_Set
<< (5 * (Rank
- 7));
652 /* Clear the old SQx bits for the selected rank */
654 /* Calculate the mask to set */
655 tmpreg2
= (uint32_t)ADC_Channel
<< (5 * (Rank
- 7));
656 /* Set the SQx bits for the selected rank */
658 /* Store the new register value */
659 ADCx
->SQR2
= tmpreg1
;
661 /* For Rank 13 to 16 */
664 /* Get the old register value */
665 tmpreg1
= ADCx
->SQR1
;
666 /* Calculate the mask to clear */
667 tmpreg2
= SQR1_SQ_Set
<< (5 * (Rank
- 13));
668 /* Clear the old SQx bits for the selected rank */
670 /* Calculate the mask to set */
671 tmpreg2
= (uint32_t)ADC_Channel
<< (5 * (Rank
- 13));
672 /* Set the SQx bits for the selected rank */
674 /* Store the new register value */
675 ADCx
->SQR1
= tmpreg1
;
680 * @brief Enables or disables the ADCx conversion through external trigger.
681 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
682 * @param NewState: new state of the selected ADC external trigger start of conversion.
683 * This parameter can be: ENABLE or DISABLE.
686 void ADC_ExternalTrigConvCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
688 /* Check the parameters */
689 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
690 assert_param(IS_FUNCTIONAL_STATE(NewState
));
691 if (NewState
!= DISABLE
)
693 /* Enable the selected ADC conversion on external event */
694 ADCx
->CR2
|= CR2_EXTTRIG_Set
;
698 /* Disable the selected ADC conversion on external event */
699 ADCx
->CR2
&= CR2_EXTTRIG_Reset
;
704 * @brief Returns the last ADCx conversion result data for regular channel.
705 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
706 * @retval The Data conversion value.
708 uint16_t ADC_GetConversionValue(ADC_TypeDef
* ADCx
)
710 /* Check the parameters */
711 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
712 /* Return the selected ADC conversion value */
713 return (uint16_t) ADCx
->DR
;
717 * @brief Returns the last ADC1 and ADC2 conversion result data in dual mode.
718 * @retval The Data conversion value.
720 uint32_t ADC_GetDualModeConversionValue(void)
722 /* Return the dual mode conversion value */
723 return (*(__IO
uint32_t *) DR_ADDRESS
);
727 * @brief Enables or disables the selected ADC automatic injected group
728 * conversion after regular one.
729 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
730 * @param NewState: new state of the selected ADC auto injected conversion
731 * This parameter can be: ENABLE or DISABLE.
734 void ADC_AutoInjectedConvCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
736 /* Check the parameters */
737 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
738 assert_param(IS_FUNCTIONAL_STATE(NewState
));
739 if (NewState
!= DISABLE
)
741 /* Enable the selected ADC automatic injected group conversion */
742 ADCx
->CR1
|= CR1_JAUTO_Set
;
746 /* Disable the selected ADC automatic injected group conversion */
747 ADCx
->CR1
&= CR1_JAUTO_Reset
;
752 * @brief Enables or disables the discontinuous mode for injected group
753 * channel for the specified ADC
754 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
755 * @param NewState: new state of the selected ADC discontinuous mode
756 * on injected group channel.
757 * This parameter can be: ENABLE or DISABLE.
760 void ADC_InjectedDiscModeCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
762 /* Check the parameters */
763 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
764 assert_param(IS_FUNCTIONAL_STATE(NewState
));
765 if (NewState
!= DISABLE
)
767 /* Enable the selected ADC injected discontinuous mode */
768 ADCx
->CR1
|= CR1_JDISCEN_Set
;
772 /* Disable the selected ADC injected discontinuous mode */
773 ADCx
->CR1
&= CR1_JDISCEN_Reset
;
778 * @brief Configures the ADCx external trigger for injected channels conversion.
779 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
780 * @param ADC_ExternalTrigInjecConv: specifies the ADC trigger to start injected conversion.
781 * This parameter can be one of the following values:
782 * @arg ADC_ExternalTrigInjecConv_T1_TRGO: Timer1 TRGO event selected (for ADC1, ADC2 and ADC3)
783 * @arg ADC_ExternalTrigInjecConv_T1_CC4: Timer1 capture compare4 selected (for ADC1, ADC2 and ADC3)
784 * @arg ADC_ExternalTrigInjecConv_T2_TRGO: Timer2 TRGO event selected (for ADC1 and ADC2)
785 * @arg ADC_ExternalTrigInjecConv_T2_CC1: Timer2 capture compare1 selected (for ADC1 and ADC2)
786 * @arg ADC_ExternalTrigInjecConv_T3_CC4: Timer3 capture compare4 selected (for ADC1 and ADC2)
787 * @arg ADC_ExternalTrigInjecConv_T4_TRGO: Timer4 TRGO event selected (for ADC1 and ADC2)
788 * @arg ADC_ExternalTrigInjecConv_Ext_IT15_TIM8_CC4: External interrupt line 15 or Timer8
789 * capture compare4 event selected (for ADC1 and ADC2)
790 * @arg ADC_ExternalTrigInjecConv_T4_CC3: Timer4 capture compare3 selected (for ADC3 only)
791 * @arg ADC_ExternalTrigInjecConv_T8_CC2: Timer8 capture compare2 selected (for ADC3 only)
792 * @arg ADC_ExternalTrigInjecConv_T8_CC4: Timer8 capture compare4 selected (for ADC3 only)
793 * @arg ADC_ExternalTrigInjecConv_T5_TRGO: Timer5 TRGO event selected (for ADC3 only)
794 * @arg ADC_ExternalTrigInjecConv_T5_CC4: Timer5 capture compare4 selected (for ADC3 only)
795 * @arg ADC_ExternalTrigInjecConv_None: Injected conversion started by software and not
796 * by external trigger (for ADC1, ADC2 and ADC3)
799 void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef
* ADCx
, uint32_t ADC_ExternalTrigInjecConv
)
802 /* Check the parameters */
803 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
804 assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv
));
805 /* Get the old register value */
807 /* Clear the old external event selection for injected group */
808 tmpreg
&= CR2_JEXTSEL_Reset
;
809 /* Set the external event selection for injected group */
810 tmpreg
|= ADC_ExternalTrigInjecConv
;
811 /* Store the new register value */
816 * @brief Enables or disables the ADCx injected channels conversion through
818 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
819 * @param NewState: new state of the selected ADC external trigger start of
820 * injected conversion.
821 * This parameter can be: ENABLE or DISABLE.
824 void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
826 /* Check the parameters */
827 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
828 assert_param(IS_FUNCTIONAL_STATE(NewState
));
829 if (NewState
!= DISABLE
)
831 /* Enable the selected ADC external event selection for injected group */
832 ADCx
->CR2
|= CR2_JEXTTRIG_Set
;
836 /* Disable the selected ADC external event selection for injected group */
837 ADCx
->CR2
&= CR2_JEXTTRIG_Reset
;
842 * @brief Enables or disables the selected ADC start of the injected
843 * channels conversion.
844 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
845 * @param NewState: new state of the selected ADC software start injected conversion.
846 * This parameter can be: ENABLE or DISABLE.
849 void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef
* ADCx
, FunctionalState NewState
)
851 /* Check the parameters */
852 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
853 assert_param(IS_FUNCTIONAL_STATE(NewState
));
854 if (NewState
!= DISABLE
)
856 /* Enable the selected ADC conversion for injected group on external event and start the selected
857 ADC injected conversion */
858 ADCx
->CR2
|= CR2_JEXTTRIG_JSWSTART_Set
;
862 /* Disable the selected ADC conversion on external event for injected group and stop the selected
863 ADC injected conversion */
864 ADCx
->CR2
&= CR2_JEXTTRIG_JSWSTART_Reset
;
869 * @brief Gets the selected ADC Software start injected conversion Status.
870 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
871 * @retval The new state of ADC software start injected conversion (SET or RESET).
873 FlagStatus
ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef
* ADCx
)
875 FlagStatus bitstatus
= RESET
;
876 /* Check the parameters */
877 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
878 /* Check the status of JSWSTART bit */
879 if ((ADCx
->CR2
& CR2_JSWSTART_Set
) != (uint32_t)RESET
)
881 /* JSWSTART bit is set */
886 /* JSWSTART bit is reset */
889 /* Return the JSWSTART bit status */
894 * @brief Configures for the selected ADC injected channel its corresponding
895 * rank in the sequencer and its sample time.
896 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
897 * @param ADC_Channel: the ADC channel to configure.
898 * This parameter can be one of the following values:
899 * @arg ADC_Channel_0: ADC Channel0 selected
900 * @arg ADC_Channel_1: ADC Channel1 selected
901 * @arg ADC_Channel_2: ADC Channel2 selected
902 * @arg ADC_Channel_3: ADC Channel3 selected
903 * @arg ADC_Channel_4: ADC Channel4 selected
904 * @arg ADC_Channel_5: ADC Channel5 selected
905 * @arg ADC_Channel_6: ADC Channel6 selected
906 * @arg ADC_Channel_7: ADC Channel7 selected
907 * @arg ADC_Channel_8: ADC Channel8 selected
908 * @arg ADC_Channel_9: ADC Channel9 selected
909 * @arg ADC_Channel_10: ADC Channel10 selected
910 * @arg ADC_Channel_11: ADC Channel11 selected
911 * @arg ADC_Channel_12: ADC Channel12 selected
912 * @arg ADC_Channel_13: ADC Channel13 selected
913 * @arg ADC_Channel_14: ADC Channel14 selected
914 * @arg ADC_Channel_15: ADC Channel15 selected
915 * @arg ADC_Channel_16: ADC Channel16 selected
916 * @arg ADC_Channel_17: ADC Channel17 selected
917 * @param Rank: The rank in the injected group sequencer. This parameter must be between 1 and 4.
918 * @param ADC_SampleTime: The sample time value to be set for the selected channel.
919 * This parameter can be one of the following values:
920 * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
921 * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
922 * @arg ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
923 * @arg ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles
924 * @arg ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles
925 * @arg ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles
926 * @arg ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles
927 * @arg ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles
930 void ADC_InjectedChannelConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
, uint8_t Rank
, uint8_t ADC_SampleTime
)
932 uint32_t tmpreg1
= 0, tmpreg2
= 0, tmpreg3
= 0;
933 /* Check the parameters */
934 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
935 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
936 assert_param(IS_ADC_INJECTED_RANK(Rank
));
937 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime
));
938 /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
939 if (ADC_Channel
> ADC_Channel_9
)
941 /* Get the old register value */
942 tmpreg1
= ADCx
->SMPR1
;
943 /* Calculate the mask to clear */
944 tmpreg2
= SMPR1_SMP_Set
<< (3*(ADC_Channel
- 10));
945 /* Clear the old channel sample time */
947 /* Calculate the mask to set */
948 tmpreg2
= (uint32_t)ADC_SampleTime
<< (3*(ADC_Channel
- 10));
949 /* Set the new channel sample time */
951 /* Store the new register value */
952 ADCx
->SMPR1
= tmpreg1
;
954 else /* ADC_Channel include in ADC_Channel_[0..9] */
956 /* Get the old register value */
957 tmpreg1
= ADCx
->SMPR2
;
958 /* Calculate the mask to clear */
959 tmpreg2
= SMPR2_SMP_Set
<< (3 * ADC_Channel
);
960 /* Clear the old channel sample time */
962 /* Calculate the mask to set */
963 tmpreg2
= (uint32_t)ADC_SampleTime
<< (3 * ADC_Channel
);
964 /* Set the new channel sample time */
966 /* Store the new register value */
967 ADCx
->SMPR2
= tmpreg1
;
969 /* Rank configuration */
970 /* Get the old register value */
971 tmpreg1
= ADCx
->JSQR
;
972 /* Get JL value: Number = JL+1 */
973 tmpreg3
= (tmpreg1
& JSQR_JL_Set
)>> 20;
974 /* Calculate the mask to clear: ((Rank-1)+(4-JL-1)) */
975 tmpreg2
= JSQR_JSQ_Set
<< (5 * (uint8_t)((Rank
+ 3) - (tmpreg3
+ 1)));
976 /* Clear the old JSQx bits for the selected rank */
978 /* Calculate the mask to set: ((Rank-1)+(4-JL-1)) */
979 tmpreg2
= (uint32_t)ADC_Channel
<< (5 * (uint8_t)((Rank
+ 3) - (tmpreg3
+ 1)));
980 /* Set the JSQx bits for the selected rank */
982 /* Store the new register value */
983 ADCx
->JSQR
= tmpreg1
;
987 * @brief Configures the sequencer length for injected channels
988 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
989 * @param Length: The sequencer length.
990 * This parameter must be a number between 1 to 4.
993 void ADC_InjectedSequencerLengthConfig(ADC_TypeDef
* ADCx
, uint8_t Length
)
995 uint32_t tmpreg1
= 0;
996 uint32_t tmpreg2
= 0;
997 /* Check the parameters */
998 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
999 assert_param(IS_ADC_INJECTED_LENGTH(Length
));
1001 /* Get the old register value */
1002 tmpreg1
= ADCx
->JSQR
;
1003 /* Clear the old injected sequnence lenght JL bits */
1004 tmpreg1
&= JSQR_JL_Reset
;
1005 /* Set the injected sequnence lenght JL bits */
1006 tmpreg2
= Length
- 1;
1007 tmpreg1
|= tmpreg2
<< 20;
1008 /* Store the new register value */
1009 ADCx
->JSQR
= tmpreg1
;
1013 * @brief Set the injected channels conversion value offset
1014 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1015 * @param ADC_InjectedChannel: the ADC injected channel to set its offset.
1016 * This parameter can be one of the following values:
1017 * @arg ADC_InjectedChannel_1: Injected Channel1 selected
1018 * @arg ADC_InjectedChannel_2: Injected Channel2 selected
1019 * @arg ADC_InjectedChannel_3: Injected Channel3 selected
1020 * @arg ADC_InjectedChannel_4: Injected Channel4 selected
1021 * @param Offset: the offset value for the selected ADC injected channel
1022 * This parameter must be a 12bit value.
1025 void ADC_SetInjectedOffset(ADC_TypeDef
* ADCx
, uint8_t ADC_InjectedChannel
, uint16_t Offset
)
1027 __IO
uint32_t tmp
= 0;
1029 /* Check the parameters */
1030 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1031 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel
));
1032 assert_param(IS_ADC_OFFSET(Offset
));
1034 tmp
= (uint32_t)ADCx
;
1035 tmp
+= ADC_InjectedChannel
;
1037 /* Set the selected injected channel data offset */
1038 *(__IO
uint32_t *) tmp
= (uint32_t)Offset
;
1042 * @brief Returns the ADC injected channel conversion result
1043 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1044 * @param ADC_InjectedChannel: the converted ADC injected channel.
1045 * This parameter can be one of the following values:
1046 * @arg ADC_InjectedChannel_1: Injected Channel1 selected
1047 * @arg ADC_InjectedChannel_2: Injected Channel2 selected
1048 * @arg ADC_InjectedChannel_3: Injected Channel3 selected
1049 * @arg ADC_InjectedChannel_4: Injected Channel4 selected
1050 * @retval The Data conversion value.
1052 uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef
* ADCx
, uint8_t ADC_InjectedChannel
)
1054 __IO
uint32_t tmp
= 0;
1056 /* Check the parameters */
1057 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1058 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel
));
1060 tmp
= (uint32_t)ADCx
;
1061 tmp
+= ADC_InjectedChannel
+ JDR_Offset
;
1063 /* Returns the selected injected channel conversion data value */
1064 return (uint16_t) (*(__IO
uint32_t*) tmp
);
1068 * @brief Enables or disables the analog watchdog on single/all regular
1069 * or injected channels
1070 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1071 * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration.
1072 * This parameter can be one of the following values:
1073 * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single regular channel
1074 * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single injected channel
1075 * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a single regular or injected channel
1076 * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular channel
1077 * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected channel
1078 * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all regular and injected channels
1079 * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog
1082 void ADC_AnalogWatchdogCmd(ADC_TypeDef
* ADCx
, uint32_t ADC_AnalogWatchdog
)
1084 uint32_t tmpreg
= 0;
1085 /* Check the parameters */
1086 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1087 assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog
));
1088 /* Get the old register value */
1090 /* Clear AWDEN, AWDENJ and AWDSGL bits */
1091 tmpreg
&= CR1_AWDMode_Reset
;
1092 /* Set the analog watchdog enable mode */
1093 tmpreg
|= ADC_AnalogWatchdog
;
1094 /* Store the new register value */
1099 * @brief Configures the high and low thresholds of the analog watchdog.
1100 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1101 * @param HighThreshold: the ADC analog watchdog High threshold value.
1102 * This parameter must be a 12bit value.
1103 * @param LowThreshold: the ADC analog watchdog Low threshold value.
1104 * This parameter must be a 12bit value.
1107 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef
* ADCx
, uint16_t HighThreshold
,
1108 uint16_t LowThreshold
)
1110 /* Check the parameters */
1111 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1112 assert_param(IS_ADC_THRESHOLD(HighThreshold
));
1113 assert_param(IS_ADC_THRESHOLD(LowThreshold
));
1114 /* Set the ADCx high threshold */
1115 ADCx
->HTR
= HighThreshold
;
1116 /* Set the ADCx low threshold */
1117 ADCx
->LTR
= LowThreshold
;
1121 * @brief Configures the analog watchdog guarded single channel
1122 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1123 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
1124 * This parameter can be one of the following values:
1125 * @arg ADC_Channel_0: ADC Channel0 selected
1126 * @arg ADC_Channel_1: ADC Channel1 selected
1127 * @arg ADC_Channel_2: ADC Channel2 selected
1128 * @arg ADC_Channel_3: ADC Channel3 selected
1129 * @arg ADC_Channel_4: ADC Channel4 selected
1130 * @arg ADC_Channel_5: ADC Channel5 selected
1131 * @arg ADC_Channel_6: ADC Channel6 selected
1132 * @arg ADC_Channel_7: ADC Channel7 selected
1133 * @arg ADC_Channel_8: ADC Channel8 selected
1134 * @arg ADC_Channel_9: ADC Channel9 selected
1135 * @arg ADC_Channel_10: ADC Channel10 selected
1136 * @arg ADC_Channel_11: ADC Channel11 selected
1137 * @arg ADC_Channel_12: ADC Channel12 selected
1138 * @arg ADC_Channel_13: ADC Channel13 selected
1139 * @arg ADC_Channel_14: ADC Channel14 selected
1140 * @arg ADC_Channel_15: ADC Channel15 selected
1141 * @arg ADC_Channel_16: ADC Channel16 selected
1142 * @arg ADC_Channel_17: ADC Channel17 selected
1145 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef
* ADCx
, uint8_t ADC_Channel
)
1147 uint32_t tmpreg
= 0;
1148 /* Check the parameters */
1149 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1150 assert_param(IS_ADC_CHANNEL(ADC_Channel
));
1151 /* Get the old register value */
1153 /* Clear the Analog watchdog channel select bits */
1154 tmpreg
&= CR1_AWDCH_Reset
;
1155 /* Set the Analog watchdog channel */
1156 tmpreg
|= ADC_Channel
;
1157 /* Store the new register value */
1162 * @brief Enables or disables the temperature sensor and Vrefint channel.
1163 * @param NewState: new state of the temperature sensor.
1164 * This parameter can be: ENABLE or DISABLE.
1167 void ADC_TempSensorVrefintCmd(FunctionalState NewState
)
1169 /* Check the parameters */
1170 assert_param(IS_FUNCTIONAL_STATE(NewState
));
1171 if (NewState
!= DISABLE
)
1173 /* Enable the temperature sensor and Vrefint channel*/
1174 ADC1
->CR2
|= CR2_TSVREFE_Set
;
1178 /* Disable the temperature sensor and Vrefint channel*/
1179 ADC1
->CR2
&= CR2_TSVREFE_Reset
;
1184 * @brief Checks whether the specified ADC flag is set or not.
1185 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1186 * @param ADC_FLAG: specifies the flag to check.
1187 * This parameter can be one of the following values:
1188 * @arg ADC_FLAG_AWD: Analog watchdog flag
1189 * @arg ADC_FLAG_EOC: End of conversion flag
1190 * @arg ADC_FLAG_JEOC: End of injected group conversion flag
1191 * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
1192 * @arg ADC_FLAG_STRT: Start of regular group conversion flag
1193 * @retval The new state of ADC_FLAG (SET or RESET).
1195 FlagStatus
ADC_GetFlagStatus(ADC_TypeDef
* ADCx
, uint8_t ADC_FLAG
)
1197 FlagStatus bitstatus
= RESET
;
1198 /* Check the parameters */
1199 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1200 assert_param(IS_ADC_GET_FLAG(ADC_FLAG
));
1201 /* Check the status of the specified ADC flag */
1202 if ((ADCx
->SR
& ADC_FLAG
) != (uint8_t)RESET
)
1204 /* ADC_FLAG is set */
1209 /* ADC_FLAG is reset */
1212 /* Return the ADC_FLAG status */
1217 * @brief Clears the ADCx's pending flags.
1218 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1219 * @param ADC_FLAG: specifies the flag to clear.
1220 * This parameter can be any combination of the following values:
1221 * @arg ADC_FLAG_AWD: Analog watchdog flag
1222 * @arg ADC_FLAG_EOC: End of conversion flag
1223 * @arg ADC_FLAG_JEOC: End of injected group conversion flag
1224 * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
1225 * @arg ADC_FLAG_STRT: Start of regular group conversion flag
1228 void ADC_ClearFlag(ADC_TypeDef
* ADCx
, uint8_t ADC_FLAG
)
1230 /* Check the parameters */
1231 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1232 assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG
));
1233 /* Clear the selected ADC flags */
1234 ADCx
->SR
= ~(uint32_t)ADC_FLAG
;
1238 * @brief Checks whether the specified ADC interrupt has occurred or not.
1239 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1240 * @param ADC_IT: specifies the ADC interrupt source to check.
1241 * This parameter can be one of the following values:
1242 * @arg ADC_IT_EOC: End of conversion interrupt mask
1243 * @arg ADC_IT_AWD: Analog watchdog interrupt mask
1244 * @arg ADC_IT_JEOC: End of injected conversion interrupt mask
1245 * @retval The new state of ADC_IT (SET or RESET).
1247 ITStatus
ADC_GetITStatus(ADC_TypeDef
* ADCx
, uint16_t ADC_IT
)
1249 ITStatus bitstatus
= RESET
;
1250 uint32_t itmask
= 0, enablestatus
= 0;
1251 /* Check the parameters */
1252 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1253 assert_param(IS_ADC_GET_IT(ADC_IT
));
1254 /* Get the ADC IT index */
1255 itmask
= ADC_IT
>> 8;
1256 /* Get the ADC_IT enable bit status */
1257 enablestatus
= (ADCx
->CR1
& (uint8_t)ADC_IT
) ;
1258 /* Check the status of the specified ADC interrupt */
1259 if (((ADCx
->SR
& itmask
) != (uint32_t)RESET
) && enablestatus
)
1266 /* ADC_IT is reset */
1269 /* Return the ADC_IT status */
1274 * @brief Clears the ADCx's interrupt pending bits.
1275 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
1276 * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
1277 * This parameter can be any combination of the following values:
1278 * @arg ADC_IT_EOC: End of conversion interrupt mask
1279 * @arg ADC_IT_AWD: Analog watchdog interrupt mask
1280 * @arg ADC_IT_JEOC: End of injected conversion interrupt mask
1283 void ADC_ClearITPendingBit(ADC_TypeDef
* ADCx
, uint16_t ADC_IT
)
1286 /* Check the parameters */
1287 assert_param(IS_ADC_ALL_PERIPH(ADCx
));
1288 assert_param(IS_ADC_IT(ADC_IT
));
1289 /* Get the ADC IT index */
1290 itmask
= (uint8_t)(ADC_IT
>> 8);
1291 /* Clear the selected ADC interrupt pending bits */
1292 ADCx
->SR
= ~(uint32_t)itmask
;
1307 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/