1 /******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
\r
2 * File Name : stm32f10x_adc.c
\r
3 * Author : MCD Application Team
\r
4 * Date First Issued : 09/29/2006
\r
5 * Description : This file provides all the ADC firmware functions.
\r
6 ********************************************************************************
\r
11 ********************************************************************************
\r
12 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
13 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
\r
14 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
\r
15 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
\r
16 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
\r
17 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
18 *******************************************************************************/
\r
20 /* Includes ------------------------------------------------------------------*/
\r
21 #include "stm32f10x_adc.h"
\r
22 #include "stm32f10x_rcc.h"
\r
24 /* Private typedef -----------------------------------------------------------*/
\r
25 /* Private define ------------------------------------------------------------*/
\r
27 #define CR2_ADON_Set ((u32)0x00000001)
\r
28 #define CR2_ADON_Reset ((u32)0xFFFFFFFE)
\r
31 #define CR2_DMA_Set ((u16)0x0100)
\r
32 #define CR2_DMA_Reset ((u16)0xFEFF)
\r
34 /* ADC RSTCAL mask */
\r
35 #define CR2_RSTCAL_Set ((u16)0x0008)
\r
38 #define CR2_CAL_Set ((u16)0x0004)
\r
40 /* ADC SWSTRT mask */
\r
41 #define CR2_SWSTRT_Set ((u32)0x00400000)
\r
43 /* ADC DISCNUM mask */
\r
44 #define CR1_DISCNUM_Reset ((u32)0xFFFF1FFF)
\r
46 /* ADC DISCEN mask */
\r
47 #define CR1_DISCEN_Set ((u32)0x00000800)
\r
48 #define CR1_DISCEN_Reset ((u32)0xFFFFF7FF)
\r
50 /* ADC EXTTRIG mask */
\r
51 #define CR2_EXTTRIG_Set ((u32)0x00100000)
\r
52 #define CR2_EXTTRIG_Reset ((u32)0xFFEFFFFF)
\r
54 /* ADC Software start mask */
\r
55 #define CR2_EXTTRIG_SWSTRT_Set ((u32)0x00500000)
\r
56 #define CR2_EXTTRIG_SWSTRT_Reset ((u32)0xFFAFFFFF)
\r
58 /* ADC JAUTO mask */
\r
59 #define CR1_JAUTO_Set ((u32)0x00000400)
\r
60 #define CR1_JAUTO_Reset ((u32)0xFFFFFBFF)
\r
62 /* ADC JDISCEN mask */
\r
63 #define CR1_JDISCEN_Set ((u32)0x00001000)
\r
64 #define CR1_JDISCEN_Reset ((u32)0xFFFFEFFF)
\r
66 /* ADC JEXTSEL mask */
\r
67 #define CR2_JEXTSEL_Reset ((u32)0xFFFF8FFF)
\r
69 /* ADC JEXTTRIG mask */
\r
70 #define CR2_JEXTTRIG_Set ((u32)0x00008000)
\r
71 #define CR2_JEXTTRIG_Reset ((u32)0xFFFF7FFF)
\r
73 /* ADC JSWSTRT mask */
\r
74 #define CR2_JSWSTRT_Set ((u32)0x00200000)
\r
76 /* ADC injected software start mask */
\r
77 #define CR2_JEXTTRIG_JSWSTRT_Set ((u32)0x00208000)
\r
78 #define CR2_JEXTTRIG_JSWSTRT_Reset ((u32)0xFFDF7FFF)
\r
80 /* ADC AWDCH mask */
\r
81 #define CR1_AWDCH_Reset ((u32)0xFFFFFFE0)
\r
84 #define SQR3_SQ_Set ((u8)0x1F)
\r
85 #define SQR2_SQ_Set ((u8)0x1F)
\r
86 #define SQR1_SQ_Set ((u8)0x1F)
\r
89 #define JSQR_JSQ_Set ((u8)0x1F)
\r
92 #define JSQR_JL_Reset ((u32)0xFFCFFFFF)
\r
95 #define SMPR1_SMP_Set ((u8)0x07)
\r
96 #define SMPR2_SMP_Set ((u8)0x07)
\r
98 /* ADC Analog watchdog enable mode mask */
\r
99 #define CR1_AWDMode_Reset ((u32)0xFF3FFDFF)
\r
101 /* ADC TSPD mask */
\r
102 #define CR2_TSPD_Set ((u32)0x00800000)
\r
103 #define CR2_TSPD_Reset ((u32)0xFF7FFFFF)
\r
105 /* ADC JDRx registers= offset */
\r
106 #define JDR_Offset ((u8)0x28)
\r
108 /* ADC registers Masks */
\r
109 #define CR1_CLEAR_Mask ((u32)0xFFF0FEFF)
\r
110 #define CR2_CLEAR_Mask ((u32)0xFFF1F7FD)
\r
111 #define SQR1_CLEAR_Mask ((u32)0xFF0FFFFF)
\r
113 /* Private macro -------------------------------------------------------------*/
\r
114 /* Private variables ---------------------------------------------------------*/
\r
115 /* Private function prototypes -----------------------------------------------*/
\r
116 /* Private functions ---------------------------------------------------------*/
\r
118 /*******************************************************************************
\r
119 * Function Name : ADC_DeInit
\r
120 * Description : Deinitializes the ADCx peripheral registers to their default
\r
122 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
125 *******************************************************************************/
\r
126 void ADC_DeInit(ADC_TypeDef* ADCx)
\r
128 switch (*(u32*)&ADCx)
\r
131 /* Enable ADC1 reset state */
\r
132 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
\r
133 /* Release ADC1 from reset state */
\r
134 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
\r
138 /* Enable ADC2 reset state */
\r
139 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, ENABLE);
\r
140 /* Release ADC2 from reset state */
\r
141 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC2, DISABLE);
\r
149 /*******************************************************************************
\r
150 * Function Name : ADC_Init
\r
151 * Description : Initializes the ADCx according to the specified parameters
\r
152 * in the ADC_InitStruct.
\r
153 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
154 * - ADC_InitStruct: pointer to a ADC_InitTypeDef structure that
\r
155 * contains the configuration information for the specified
\r
159 ******************************************************************************/
\r
160 void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
\r
165 /* Check the parameters */
\r
166 assert(IS_ADC_MODE(ADC_InitStruct->ADC_Mode));
\r
167 assert(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ScanConvMode));
\r
168 assert(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ContinuousConvMode));
\r
169 assert(IS_ADC_EXT_TRIG(ADC_InitStruct->ADC_ExternalTrigConv));
\r
170 assert(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
\r
171 assert(IS_ADC_REGULAR_LENGTH(ADC_InitStruct->ADC_NbrOfChannel));
\r
173 /*---------------------------- ADCx CR1 Configuration -----------------*/
\r
174 /* Get the ADCx CR1 value */
\r
175 tmpreg1 = ADCx->CR1;
\r
176 /* Clear DUALMODE and SCAN bits */
\r
177 tmpreg1 &= CR1_CLEAR_Mask;
\r
178 /* Configure ADCx: Dual mode and scan conversion mode */
\r
179 /* Set DUALMODE bits according to ADC_Mode value */
\r
180 /* Set SCAN bit according to ADC_ScanConvMode value */
\r
181 tmpreg1 |= (u32)(ADC_InitStruct->ADC_Mode | ((u32)ADC_InitStruct->ADC_ScanConvMode << 8));
\r
182 /* Write to ADCx CR1 */
\r
183 ADCx->CR1 = tmpreg1;
\r
185 /*---------------------------- ADCx CR2 Configuration -----------------*/
\r
186 /* Get the ADCx CR2 value */
\r
187 tmpreg1 = ADCx->CR2;
\r
188 /* Clear CONT, ALIGN and EXTTRIG bits */
\r
189 tmpreg1 &= CR2_CLEAR_Mask;
\r
190 /* Configure ADCx: external trigger event and continuous conversion mode */
\r
191 /* Set ALIGN bit according to ADC_DataAlign value */
\r
192 /* Set EXTTRIG bits according to ADC_ExternalTrigConv value */
\r
193 /* Set CONT bit according to ADC_ContinuousConvMode value */
\r
194 tmpreg1 |= (u32)(ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ExternalTrigConv |
\r
195 ((u32)ADC_InitStruct->ADC_ContinuousConvMode << 1));
\r
196 /* Write to ADCx CR2 */
\r
197 ADCx->CR2 = tmpreg1;
\r
199 /*---------------------------- ADCx SQR1 Configuration -----------------*/
\r
200 /* Get the ADCx SQR1 value */
\r
201 tmpreg1 = ADCx->SQR1;
\r
203 tmpreg1 &= SQR1_CLEAR_Mask;
\r
204 /* Configure ADCx: regular channel sequence length */
\r
205 /* Set L bits according to ADC_NbrOfChannel value */
\r
206 tmpreg2 |= (ADC_InitStruct->ADC_NbrOfChannel - 1);
\r
207 tmpreg1 |= ((u32)tmpreg2 << 20);
\r
208 /* Write to ADCx SQR1 */
\r
209 ADCx->SQR1 = tmpreg1;
\r
212 /*******************************************************************************
\r
213 * Function Name : ADC_StructInit
\r
214 * Description : Fills each ADC_InitStruct member with its default value.
\r
215 * Input : ADC_InitStruct : pointer to a ADC_InitTypeDef structure
\r
216 * which will be initialized.
\r
219 *******************************************************************************/
\r
220 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
\r
222 /* Reset ADC init structure parameters values */
\r
223 /* Initialize the ADC_Mode member */
\r
224 ADC_InitStruct->ADC_Mode = ADC_Mode_Independent;
\r
226 /* initialize the ADC_ScanConvMode member */
\r
227 ADC_InitStruct->ADC_ScanConvMode = DISABLE;
\r
229 /* Initialize the ADC_ContinuousConvMode member */
\r
230 ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
\r
232 /* Initialize the ADC_ExternalTrigConv member */
\r
233 ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
\r
235 /* Initialize the ADC_DataAlign member */
\r
236 ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
\r
238 /* Initialize the ADC_NbrOfChannel member */
\r
239 ADC_InitStruct->ADC_NbrOfChannel = 1;
\r
242 /*******************************************************************************
\r
243 * Function Name : ADC_Cmd
\r
244 * Description : Enables or disables the specified ADC peripheral.
\r
245 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
246 * - NewState: new state of the ADCx peripheral. This parameter
\r
247 * can be: ENABLE or DISABLE.
\r
250 *******************************************************************************/
\r
251 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
253 /* Check the parameters */
\r
254 assert(IS_FUNCTIONAL_STATE(NewState));
\r
256 if (NewState != DISABLE)
\r
258 /* Set the ADON bit to wake up the ADC from power down mode */
\r
259 ADCx->CR2 |= CR2_ADON_Set;
\r
263 /* Disable the selected ADC peripheral */
\r
264 ADCx->CR2 &= CR2_ADON_Reset;
\r
268 /*******************************************************************************
\r
269 * Function Name : ADC_DMACmd
\r
270 * Description : Enables or disables the specified ADC DMA request.
\r
271 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
272 * - NewState: new state of the selected ADC DMA transfer.
\r
273 * This parameter can be: ENABLE or DISABLE.
\r
276 *******************************************************************************/
\r
277 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
279 /* Check the parameters */
\r
280 assert(IS_FUNCTIONAL_STATE(NewState));
\r
282 if (NewState != DISABLE)
\r
284 /* Enable the selected ADC DMA request */
\r
285 ADCx->CR2 |= CR2_DMA_Set;
\r
289 /* Disable the selected ADC DMA request */
\r
290 ADCx->CR2 &= CR2_DMA_Reset;
\r
294 /*******************************************************************************
\r
295 * Function Name : ADC_ITConfig
\r
296 * Description : Enables or disables the specified ADC interrupts.
\r
297 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
298 * - ADC_IT: specifies the ADC interrupts sources to be enabled
\r
300 * This parameter can be any combination of the following values:
\r
301 * - ADC_IT_EOC: End of conversion interrupt mask
\r
302 * - ADC_IT_AWD: Analog watchdog interrupt mask
\r
303 * - ADC_IT_JEOC: End of injected conversion interrupt mask
\r
304 * - NewState: new state of the specified ADC interrupts.
\r
305 * This parameter can be: ENABLE or DISABLE.
\r
308 *******************************************************************************/
\r
309 void ADC_ITConfig(ADC_TypeDef* ADCx, u16 ADC_IT, FunctionalState NewState)
\r
313 /* Check the parameters */
\r
314 assert(IS_FUNCTIONAL_STATE(NewState));
\r
315 assert(IS_ADC_IT(ADC_IT));
\r
317 /* Get the ADC IT index */
\r
318 itmask = (u8)ADC_IT;
\r
320 if (NewState != DISABLE)
\r
322 /* Enable the selected ADC interrupts */
\r
323 ADCx->CR1 |= itmask;
\r
327 /* Disable the selected ADC interrupts */
\r
328 ADCx->CR1 &= (~(u32)itmask);
\r
332 /*******************************************************************************
\r
333 * Function Name : ADC_ResetCalibration
\r
334 * Description : Resets the ADC calibration registers.
\r
335 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
338 *******************************************************************************/
\r
339 void ADC_ResetCalibration(ADC_TypeDef* ADCx)
\r
341 /* Resets the selected ADC calibartion registers */
\r
342 ADCx->CR2 |= CR2_RSTCAL_Set;
\r
345 /*******************************************************************************
\r
346 * Function Name : ADC_GetResetCalibrationStatus
\r
347 * Description : Gets the ADC reset calibration registers status.
\r
348 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
350 * Return : The new state of ADC Reset Calibration registers (SET or RESET).
\r
351 *******************************************************************************/
\r
352 FlagStatus ADC_GetResetCalibrationStatus(ADC_TypeDef* ADCx)
\r
354 FlagStatus bitstatus = RESET;
\r
356 /* Check the status of RSTCAL bit */
\r
357 if ((ADCx->CR2 & CR2_RSTCAL_Set) != (u16)RESET)
\r
359 /* RSTCAL bit is set */
\r
364 /* RSTCAL bit is reset */
\r
367 /* Return the RSTCAL bit status */
\r
371 /*******************************************************************************
\r
372 * Function Name : ADC_StartCalibration
\r
373 * Description : Starts the calibration process.
\r
374 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
377 *******************************************************************************/
\r
378 void ADC_StartCalibration(ADC_TypeDef* ADCx)
\r
380 /* Enable the selected ADC calibration process */
\r
381 ADCx->CR2 |= CR2_CAL_Set;
\r
384 /*******************************************************************************
\r
385 * Function Name : ADC_GetCalibrationStatus
\r
386 * Description : Gets the ADC calibration status.
\r
387 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
389 * Return : The new state of ADC calibration (SET or RESET).
\r
390 *******************************************************************************/
\r
391 FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx)
\r
393 FlagStatus bitstatus = RESET;
\r
395 /* Check the status of CAL bit */
\r
396 if ((ADCx->CR2 & CR2_CAL_Set) != (u16)RESET)
\r
398 /* CAL bit is set: calibration on going */
\r
403 /* CAL bit is reset: end of calibration */
\r
406 /* Return the CAL bit status */
\r
410 /*******************************************************************************
\r
411 * Function Name : ADC_SoftwareStartConvCmd
\r
412 * Description : Enables or disables the ADC software start conversion .
\r
413 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
414 * - NewState: new state of the selected ADC software start conversion.
\r
415 * This parameter can be: ENABLE or DISABLE.
\r
418 *******************************************************************************/
\r
419 void ADC_SoftwareStartConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
421 /* Check the parameters */
\r
422 assert(IS_FUNCTIONAL_STATE(NewState));
\r
424 if (NewState != DISABLE)
\r
426 /* Enable the selected ADC conversion on external event */
\r
427 /* Starts the selected ADC conversion */
\r
428 ADCx->CR2 |= CR2_EXTTRIG_SWSTRT_Set;
\r
432 /* Stops the selected ADC conversion */
\r
433 /* Disable the selected ADC conversion on external event */
\r
434 ADCx->CR2 &= CR2_EXTTRIG_SWSTRT_Reset;
\r
438 /*******************************************************************************
\r
439 * Function Name : ADC_GetSoftwareStartConvStatus
\r
440 * Description : Gets the ADC Software start conversion Status.
\r
441 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
443 * Return : The new state of ADC software start conversion (SET or RESET).
\r
444 *******************************************************************************/
\r
445 FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx)
\r
447 FlagStatus bitstatus = RESET;
\r
449 /* Check the status of SWSTRT bit */
\r
450 if ((ADCx->CR2 & CR2_SWSTRT_Set) != (u32)RESET)
\r
452 /* SWSTRT bit is set */
\r
457 /* SWSTRT bit is reset */
\r
460 /* Return the SWSTRT bit status */
\r
464 /*******************************************************************************
\r
465 * Function Name : ADC_DiscModeChannelCountConfig
\r
466 * Description : Configures the discontinuous mode for the selected ADC regular
\r
468 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
469 * - Number: specifies the discontinuous mode regular channel
\r
470 * count value. This mumber must be between 1 and 8.
\r
473 *******************************************************************************/
\r
474 void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, u8 Number)
\r
479 /* Check the parameters */
\r
480 assert(IS_ADC_REGULAR_DISC_NUMBER(Number));
\r
482 /* Get the old register value */
\r
483 tmpreg1 = ADCx->CR1;
\r
484 /* Clear the old discontinuous mode channel count */
\r
485 tmpreg1 &= CR1_DISCNUM_Reset;
\r
486 /* Set the discontinuous mode channel count */
\r
487 tmpreg2 = Number - 1;
\r
488 tmpreg1 |= ((u32)tmpreg2 << 13);
\r
489 /* Store the new register value */
\r
490 ADCx->CR1 = tmpreg1;
\r
493 /*******************************************************************************
\r
494 * Function Name : ADC_DiscModeCmd
\r
495 * Description : Enables or disables the discontinuous mode on regular group
\r
496 * channel for the specified ADC
\r
497 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
498 * - NewState: new state of the selected ADC discontinuous mode
\r
499 * on regular group channel.
\r
500 * This parameter can be: ENABLE or DISABLE.
\r
503 *******************************************************************************/
\r
504 void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
506 /* Check the parameters */
\r
507 assert(IS_FUNCTIONAL_STATE(NewState));
\r
509 if (NewState != DISABLE)
\r
511 /* Enable the selected ADC regular discontinuous mode */
\r
512 ADCx->CR1 |= CR1_DISCEN_Set;
\r
516 /* Disable the selected ADC regular discontinuous mode */
\r
517 ADCx->CR1 &= CR1_DISCEN_Reset;
\r
521 /*******************************************************************************
\r
522 * Function Name : ADC_RegularChannelConfig
\r
523 * Description : Configures for the selected ADC regular channel its corresponding
\r
524 * rank in the sequencer and its sample time.
\r
525 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
526 * - ADC_Channel: the ADC channel to configure.
\r
527 * This parameter can be one of the following values:
\r
528 * - ADC_Channel_0: ADC Channel0 selected
\r
529 * - ADC_Channel_1: ADC Channel1 selected
\r
530 * - ADC_Channel_2: ADC Channel2 selected
\r
531 * - ADC_Channel_3: ADC Channel3 selected
\r
532 * - ADC_Channel_4: ADC Channel4 selected
\r
533 * - ADC_Channel_5: ADC Channel5 selected
\r
534 * - ADC_Channel_6: ADC Channel6 selected
\r
535 * - ADC_Channel_7: ADC Channel7 selected
\r
536 * - ADC_Channel_8: ADC Channel8 selected
\r
537 * - ADC_Channel_9: ADC Channel9 selected
\r
538 * - ADC_Channel_10: ADC Channel10 selected
\r
539 * - ADC_Channel_11: ADC Channel11 selected
\r
540 * - ADC_Channel_12: ADC Channel12 selected
\r
541 * - ADC_Channel_13: ADC Channel13 selected
\r
542 * - ADC_Channel_14: ADC Channel14 selected
\r
543 * - ADC_Channel_15: ADC Channel15 selected
\r
544 * - ADC_Channel_16: ADC Channel16 selected
\r
545 * - ADC_Channel_17: ADC Channel17 selected
\r
546 * - Rank: The rank in the regular group sequencer. This parameter
\r
547 * must be between 1 to 16.
\r
548 * - ADC_SampleTime: The sample time value to be set for the
\r
549 * selected channel.
\r
550 * This parameter can be one of the following values:
\r
551 * - ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
\r
552 * - ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
\r
553 * - ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
\r
554 * - ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles
\r
555 * - ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles
\r
556 * - ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles
\r
557 * - ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles
\r
558 * - ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles
\r
561 *******************************************************************************/
\r
562 void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, u8 ADC_Channel, u8 Rank, u8 ADC_SampleTime)
\r
564 u32 tmpreg1 = 0, tmpreg2 = 0;
\r
566 /* Check the parameters */
\r
567 assert(IS_ADC_CHANNEL(ADC_Channel));
\r
568 assert(IS_ADC_REGULAR_RANK(Rank));
\r
569 assert(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
\r
571 /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
\r
572 if (ADC_Channel > ADC_Channel_9)
\r
574 /* Get the old register value */
\r
575 tmpreg1 = ADCx->SMPR1;
\r
576 /* Calculate the mask to clear */
\r
577 tmpreg2 = (u32)SMPR1_SMP_Set << (3 * (ADC_Channel - 10));
\r
578 /* Clear the old discontinuous mode channel count */
\r
579 tmpreg1 &= ~tmpreg2;
\r
580 /* Calculate the mask to set */
\r
581 tmpreg2 = (u32)ADC_SampleTime << (3 * (ADC_Channel - 10));
\r
582 /* Set the discontinuous mode channel count */
\r
583 tmpreg1 |= tmpreg2;
\r
584 /* Store the new register value */
\r
585 ADCx->SMPR1 = tmpreg1;
\r
587 else /* ADC_Channel include in ADC_Channel_[0..9] */
\r
589 /* Get the old register value */
\r
590 tmpreg1 = ADCx->SMPR2;
\r
591 /* Calculate the mask to clear */
\r
592 tmpreg2 = (u32)SMPR2_SMP_Set << (3 * ADC_Channel);
\r
593 /* Clear the old discontinuous mode channel count */
\r
594 tmpreg1 &= ~tmpreg2;
\r
595 /* Calculate the mask to set */
\r
596 tmpreg2 = (u32)ADC_SampleTime << (3 * ADC_Channel);
\r
597 /* Set the discontinuous mode channel count */
\r
598 tmpreg1 |= tmpreg2;
\r
599 /* Store the new register value */
\r
600 ADCx->SMPR2 = tmpreg1;
\r
602 /* For Rank 1 to 6 */
\r
605 /* Get the old register value */
\r
606 tmpreg1 = ADCx->SQR3;
\r
607 /* Calculate the mask to clear */
\r
608 tmpreg2 = (u32)SQR3_SQ_Set << (5 * (Rank - 1));
\r
609 /* Clear the old SQx bits for the selected rank */
\r
610 tmpreg1 &= ~tmpreg2;
\r
611 /* Calculate the mask to set */
\r
612 tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 1));
\r
613 /* Set the SQx bits for the selected rank */
\r
614 tmpreg1 |= tmpreg2;
\r
615 /* Store the new register value */
\r
616 ADCx->SQR3 = tmpreg1;
\r
618 /* For Rank 7 to 12 */
\r
619 else if (Rank < 13)
\r
621 /* Get the old register value */
\r
622 tmpreg1 = ADCx->SQR2;
\r
623 /* Calculate the mask to clear */
\r
624 tmpreg2 = (u32)SQR2_SQ_Set << (5 * (Rank - 7));
\r
625 /* Clear the old SQx bits for the selected rank */
\r
626 tmpreg1 &= ~tmpreg2;
\r
627 /* Calculate the mask to set */
\r
628 tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 7));
\r
629 /* Set the SQx bits for the selected rank */
\r
630 tmpreg1 |= tmpreg2;
\r
631 /* Store the new register value */
\r
632 ADCx->SQR2 = tmpreg1;
\r
634 /* For Rank 13 to 16 */
\r
637 /* Get the old register value */
\r
638 tmpreg1 = ADCx->SQR1;
\r
639 /* Calculate the mask to clear */
\r
640 tmpreg2 = (u32)SQR1_SQ_Set << (5 * (Rank - 13));
\r
641 /* Clear the old SQx bits for the selected rank */
\r
642 tmpreg1 &= ~tmpreg2;
\r
643 /* Calculate the mask to set */
\r
644 tmpreg2 = (u32)ADC_Channel << (5 * (Rank - 13));
\r
645 /* Set the SQx bits for the selected rank */
\r
646 tmpreg1 |= tmpreg2;
\r
647 /* Store the new register value */
\r
648 ADCx->SQR1 = tmpreg1;
\r
652 /*******************************************************************************
\r
653 * Function Name : ADC_ExternalTrigConvCmd
\r
654 * Description : Enables or disables the ADCx conversion through external trigger.
\r
655 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
656 * - NewState: new state of the selected ADC external trigger
\r
657 * start of conversion.
\r
658 * This parameter can be: ENABLE or DISABLE.
\r
661 *******************************************************************************/
\r
662 void ADC_ExternalTrigConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
664 /* Check the parameters */
\r
665 assert(IS_FUNCTIONAL_STATE(NewState));
\r
667 if (NewState != DISABLE)
\r
669 /* Enable the selected ADC conversion on external event */
\r
670 ADCx->CR2 |= CR2_EXTTRIG_Set;
\r
674 /* Disable the selected ADC conversion on external event */
\r
675 ADCx->CR2 &= CR2_EXTTRIG_Reset;
\r
679 /*******************************************************************************
\r
680 * Function Name : ADC_GetConversionValue
\r
681 * Description : Returns the last ADC conversion result data for regular channel.
\r
682 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
684 * Return : The Data conversion value.
\r
685 *******************************************************************************/
\r
686 u16 ADC_GetConversionValue(ADC_TypeDef* ADCx)
\r
688 /* Return the selected ADC conversion value */
\r
689 return (u16) ADCx->DR;
\r
692 /*******************************************************************************
\r
693 * Function Name : ADC_GetDualModeConversionValue
\r
694 * Description : Returns the last ADCs conversion result data in dual mode.
\r
696 * Return : The Data conversion value.
\r
697 *******************************************************************************/
\r
698 u32 ADC_GetDualModeConversionValue(void)
\r
700 /* Return the dual mode conversion value */
\r
704 /*******************************************************************************
\r
705 * Function Name : ADC_AutoInjectedConvCmd
\r
706 * Description : Enables or disables the automatic injected group conversion
\r
707 * after regular one.
\r
708 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
709 * - NewState: new state of the selected ADC auto injected
\r
711 * This parameter can be: ENABLE or DISABLE.
\r
714 *******************************************************************************/
\r
715 void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
717 /* Check the parameters */
\r
718 assert(IS_FUNCTIONAL_STATE(NewState));
\r
720 if (NewState != DISABLE)
\r
722 /* Enable the selected ADC automatic injected group conversion */
\r
723 ADCx->CR1 |= CR1_JAUTO_Set;
\r
727 /* Disable the selected ADC automatic injected group conversion */
\r
728 ADCx->CR1 &= CR1_JAUTO_Reset;
\r
732 /*******************************************************************************
\r
733 * Function Name : ADC_InjectedDiscModeCmd
\r
734 * Description : Enables or disables the discontinuous mode for injected group
\r
735 * channel for the specified ADC
\r
736 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
737 * - NewState: new state of the selected ADC discontinuous mode
\r
738 * on injected group channel.
\r
739 * This parameter can be: ENABLE or DISABLE.
\r
742 *******************************************************************************/
\r
743 void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
745 /* Check the parameters */
\r
746 assert(IS_FUNCTIONAL_STATE(NewState));
\r
748 if (NewState != DISABLE)
\r
750 /* Enable the selected ADC injected discontinuous mode */
\r
751 ADCx->CR1 |= CR1_JDISCEN_Set;
\r
755 /* Disable the selected ADC injected discontinuous mode */
\r
756 ADCx->CR1 &= CR1_JDISCEN_Reset;
\r
760 /*******************************************************************************
\r
761 * Function Name : ADC_ExternalTrigInjectedConvConfig
\r
762 * Description : Configures the external trigger for injected channels conversion.
\r
763 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
764 * - ADC_ExternalTrigInjecConv: specifies the ADC trigger to
\r
765 * start injected conversion.
\r
766 * This parameter can be one of the following values:
\r
767 * - ADC_ExternalTrigInjecConv_T1_TRGO: Timer1 TRGO event
\r
769 * - ADC_ExternalTrigInjecConv_T1_CC4: Timer1 capture
\r
770 * compare4 selected
\r
771 * - ADC_ExternalTrigInjecConv_T2_TRGO: Timer2 TRGO event
\r
773 * - ADC_ExternalTrigInjecConv_T2_CC1: Timer2 capture
\r
774 * compare1 selected
\r
775 * - ADC_ExternalTrigInjecConv_T3_CC4: Timer3 capture
\r
776 * compare4 selected
\r
777 * - ADC_ExternalTrigInjecConv_T4_TRGO: Timer4 TRGO event
\r
779 * - ADC_ExternalTrigInjecConv_Ext_Interrupt15: External
\r
780 * interrupt 15 event selected
\r
781 * - ADC_ExternalTrigInjecConv_None: Injected conversion
\r
782 * started by software and not by external trigger
\r
785 *******************************************************************************/
\r
786 void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, u32 ADC_ExternalTrigInjecConv)
\r
790 /* Check the parameters */
\r
791 assert(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv));
\r
793 /* Get the old register value */
\r
794 tmpreg = ADCx->CR2;
\r
795 /* Clear the old external event selection for injected group */
\r
796 tmpreg &= CR2_JEXTSEL_Reset;
\r
797 /* Set the external event selection for injected group */
\r
798 tmpreg |= ADC_ExternalTrigInjecConv;
\r
799 /* Store the new register value */
\r
800 ADCx->CR2 = tmpreg;
\r
803 /*******************************************************************************
\r
804 * Function Name : ADC_ExternalTrigInjectedConvCmd
\r
805 * Description : Enables or disables the ADCx injected channels conversion
\r
806 * through external trigger
\r
807 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
808 * - NewState: new state of the selected ADC external trigger
\r
809 * start of injected conversion.
\r
810 * This parameter can be: ENABLE or DISABLE.
\r
813 *******************************************************************************/
\r
814 void ADC_ExternalTrigInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
816 /* Check the parameters */
\r
817 assert(IS_FUNCTIONAL_STATE(NewState));
\r
819 if (NewState != DISABLE)
\r
821 /* Enable the selected ADC external event selection for injected group */
\r
822 ADCx->CR2 |= CR2_JEXTTRIG_Set;
\r
826 /* Disable the selected ADC external event selection for injected group */
\r
827 ADCx->CR2 &= CR2_JEXTTRIG_Reset;
\r
831 /*******************************************************************************
\r
832 * Function Name : ADC_SoftwareStartInjectedConvCmd
\r
833 * Description : Enables or disables the start of the injected channels conversion.
\r
834 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
835 * - NewState: new state of the selected ADC software start
\r
836 * injected conversion.
\r
837 * This parameter can be: ENABLE or DISABLE.
\r
840 *******************************************************************************/
\r
841 void ADC_SoftwareStartInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
843 /* Check the parameters */
\r
844 assert(IS_FUNCTIONAL_STATE(NewState));
\r
846 if (NewState != DISABLE)
\r
848 /* Enable the selected ADC external event selection for injected group */
\r
849 /* Starts the selected ADC injected conversion */
\r
850 ADCx->CR2 |= CR2_JEXTTRIG_JSWSTRT_Set;
\r
854 /* Stops the selected ADC injected conversion */
\r
855 /* Disable the selected ADC external event selection for injected group */
\r
856 ADCx->CR2 &= CR2_JEXTTRIG_JSWSTRT_Reset;
\r
860 /*******************************************************************************
\r
861 * Function Name : ADC_GetSoftwareStartInjectedConvCmdStatus
\r
862 * Description : Gets the ADC Software start injected conversion Status.
\r
863 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
865 * Return : The new state of ADC software start injected conversion (SET or RESET).
\r
866 *******************************************************************************/
\r
867 FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx)
\r
869 FlagStatus bitstatus = RESET;
\r
871 /* Check the status of JSWSTRT bit */
\r
872 if ((ADCx->CR2 & CR2_JSWSTRT_Set) != (u32)RESET)
\r
874 /* JSWSTRT bit is set */
\r
879 /* JSWSTRT bit is reset */
\r
882 /* Return the JSWSTRT bit status */
\r
886 /*******************************************************************************
\r
887 * Function Name : ADC_InjectedChannelConfig
\r
888 * Description : Configures for the selected ADC injected channel its corresponding
\r
889 * rank in the sequencer and its sample time.
\r
890 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
891 * - ADC_Channel: the ADC channel to configure.
\r
892 * This parameter can be one of the following values:
\r
893 * - ADC_Channel_0: ADC Channel0 selected
\r
894 * - ADC_Channel_1: ADC Channel1 selected
\r
895 * - ADC_Channel_2: ADC Channel2 selected
\r
896 * - ADC_Channel_3: ADC Channel3 selected
\r
897 * - ADC_Channel_4: ADC Channel4 selected
\r
898 * - ADC_Channel_5: ADC Channel5 selected
\r
899 * - ADC_Channel_6: ADC Channel6 selected
\r
900 * - ADC_Channel_7: ADC Channel7 selected
\r
901 * - ADC_Channel_8: ADC Channel8 selected
\r
902 * - ADC_Channel_9: ADC Channel9 selected
\r
903 * - ADC_Channel_10: ADC Channel10 selected
\r
904 * - ADC_Channel_11: ADC Channel11 selected
\r
905 * - ADC_Channel_12: ADC Channel12 selected
\r
906 * - ADC_Channel_13: ADC Channel13 selected
\r
907 * - ADC_Channel_14: ADC Channel14 selected
\r
908 * - ADC_Channel_15: ADC Channel15 selected
\r
909 * - ADC_Channel_16: ADC Channel16 selected
\r
910 * - ADC_Channel_17: ADC Channel17 selected
\r
911 * - Rank: The rank in the injected group sequencer. This parameter
\r
912 * must be between 1 to 4.
\r
913 * - ADC_SampleTime: The sample time value to be set for the
\r
914 * selected channel.
\r
915 * This parameter can be one of the following values:
\r
916 * - ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
\r
917 * - ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
\r
918 * - ADC_SampleTime_13Cycles5: Sample time equal to 13.5 cycles
\r
919 * - ADC_SampleTime_28Cycles5: Sample time equal to 28.5 cycles
\r
920 * - ADC_SampleTime_41Cycles5: Sample time equal to 41.5 cycles
\r
921 * - ADC_SampleTime_55Cycles5: Sample time equal to 55.5 cycles
\r
922 * - ADC_SampleTime_71Cycles5: Sample time equal to 71.5 cycles
\r
923 * - ADC_SampleTime_239Cycles5: Sample time equal to 239.5 cycles
\r
926 *******************************************************************************/
\r
927 void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, u8 ADC_Channel, u8 Rank, u8 ADC_SampleTime)
\r
929 u32 tmpreg1 = 0, tmpreg2 = 0;
\r
932 /* Check the parameters */
\r
933 assert(IS_ADC_CHANNEL(ADC_Channel));
\r
934 assert(IS_ADC_INJECTED_RANK(Rank));
\r
935 assert(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
\r
937 /* if ADC_Channel_10 ... ADC_Channel_17 is selected */
\r
938 if (ADC_Channel > ADC_Channel_9)
\r
940 /* Get the old register value */
\r
941 tmpreg1 = ADCx->SMPR1;
\r
942 /* Calculate the mask to clear */
\r
943 tmpreg2 = (u32)SMPR1_SMP_Set << (3*(ADC_Channel - 10));
\r
944 /* Clear the old discontinuous mode channel count */
\r
945 tmpreg1 &= ~tmpreg2;
\r
946 /* Calculate the mask to set */
\r
947 tmpreg2 = (u32)ADC_SampleTime << (3*(ADC_Channel - 10));
\r
948 /* Set the discontinuous mode channel count */
\r
949 tmpreg1 |= tmpreg2;
\r
950 /* Store the new register value */
\r
951 ADCx->SMPR1 = tmpreg1;
\r
953 else /* ADC_Channel include in ADC_Channel_[0..9] */
\r
955 /* Get the old register value */
\r
956 tmpreg1 = ADCx->SMPR2;
\r
957 /* Calculate the mask to clear */
\r
958 tmpreg2 = (u32)SMPR2_SMP_Set << (3 * ADC_Channel);
\r
959 /* Clear the old discontinuous mode channel count */
\r
960 tmpreg1 &= ~tmpreg2;
\r
961 /* Calculate the mask to set */
\r
962 tmpreg2 = (u32)ADC_SampleTime << (3 * ADC_Channel);
\r
963 /* Set the discontinuous mode channel count */
\r
964 tmpreg1 |= tmpreg2;
\r
965 /* Store the new register value */
\r
966 ADCx->SMPR2 = tmpreg1;
\r
969 /* Rank configuration */
\r
970 /* Get the old register value */
\r
971 tmpreg1 = ADCx->JSQR;
\r
972 /* Get JL value: Number = JL+1 */
\r
973 tmpreg3 = (u8)((tmpreg1 & (u32)~JSQR_JL_Reset)>> 20);
\r
974 /* Calculate the mask to clear: ((Rank-1)+(4-JL-1)) */
\r
975 tmpreg2 = (u32)JSQR_JSQ_Set << (5 * ((Rank + 3) - (tmpreg3 + 1)));
\r
976 /* Clear the old JSQx bits for the selected rank */
\r
977 tmpreg1 &= ~tmpreg2;
\r
978 /* Calculate the mask to set: ((Rank-1)+(4-JL-1)) */
\r
979 tmpreg2 = (u32)ADC_Channel << (5 * ((Rank + 3) - (tmpreg3 + 1)));
\r
980 /* Set the JSQx bits for the selected rank */
\r
981 tmpreg1 |= tmpreg2;
\r
982 /* Store the new register value */
\r
983 ADCx->JSQR = tmpreg1;
\r
986 /*******************************************************************************
\r
987 * Function Name : ADC_InjectedSequencerLengthConfig
\r
988 * Description : Configures the sequencer for injected channels
\r
989 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
990 * - Length: The sequencer length.
\r
991 * This parameter must be a number between 1 to 4.
\r
994 *******************************************************************************/
\r
995 void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, u8 Length)
\r
1000 /* Check the parameters */
\r
1001 assert(IS_ADC_INJECTED_LENGTH(Length));
\r
1003 /* Get the old register value */
\r
1004 tmpreg1 = ADCx->JSQR;
\r
1005 /* Clear the old injected sequnence lenght JL bits */
\r
1006 tmpreg1 &= JSQR_JL_Reset;
\r
1007 /* Set the injected sequnence lenght JL bits */
\r
1008 tmpreg2 = Length - 1;
\r
1009 tmpreg1 |= (u32)tmpreg2 << 20;
\r
1010 /* Store the new register value */
\r
1011 ADCx->JSQR = tmpreg1;
\r
1014 /*******************************************************************************
\r
1015 * Function Name : ADC_SetInjectedOffset
\r
1016 * Description : Set the injected channels conversion value offset
\r
1017 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1018 * - ADC_InjectedChannel: the ADC injected channel to set its
\r
1020 * This parameter can be one of the following values:
\r
1021 * - ADC_InjectedChannel_1: Injected Channel1 selected
\r
1022 * - ADC_InjectedChannel_2: Injected Channel2 selected
\r
1023 * - ADC_InjectedChannel_3: Injected Channel3 selected
\r
1024 * - ADC_InjectedChannel_4: Injected Channel4 selected
\r
1027 *******************************************************************************/
\r
1028 void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, u8 ADC_InjectedChannel, u16 Offset)
\r
1030 /* Check the parameters */
\r
1031 assert(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
\r
1032 assert(IS_ADC_OFFSET(Offset));
\r
1034 /* Set the selected injected channel data offset */
\r
1035 *((u32 *)((*(u32*)&ADCx) + ADC_InjectedChannel)) = (u32)Offset;
\r
1038 /*******************************************************************************
\r
1039 * Function Name : ADC_GetInjectedConversionValue
\r
1040 * Description : Returns the ADC conversion result data for the selected
\r
1041 * injected channel
\r
1042 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1043 * - ADC_InjectedChannel: the converted ADC injected channel.
\r
1044 * This parameter can be one of the following values:
\r
1045 * - ADC_InjectedChannel_1: Injected Channel1 selected
\r
1046 * - ADC_InjectedChannel_2: Injected Channel2 selected
\r
1047 * - ADC_InjectedChannel_3: Injected Channel3 selected
\r
1048 * - ADC_InjectedChannel_4: Injected Channel4 selected
\r
1050 * Return : The Data conversion value.
\r
1051 *******************************************************************************/
\r
1052 u16 ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, u8 ADC_InjectedChannel)
\r
1054 /* Check the parameters */
\r
1055 assert(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
\r
1057 /* Returns the selected injected channel conversion data value */
\r
1058 return (u16) (*(u32*) (((*(u32*)&ADCx) + ADC_InjectedChannel + JDR_Offset)));
\r
1061 /*******************************************************************************
\r
1062 * Function Name : ADC_AnalogWatchdogCmd
\r
1063 * Description : Enables or disables the analog watchdog on single/all regular
\r
1064 * or injected channels
\r
1065 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1066 * - ADC_AnalogWatchdog: the ADC analog watchdog configuration.
\r
1067 * This parameter can be one of the following values:
\r
1068 * - ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on
\r
1069 * a single regular channel
\r
1070 * - ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on
\r
1071 * a single injected channel
\r
1072 * - ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog
\r
1073 * watchdog on a single regular or injected channel
\r
1074 * - ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on
\r
1075 * all regular channel
\r
1076 * - ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on
\r
1077 * all injected channel
\r
1078 * - ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog
\r
1079 * on all regular and injected channels
\r
1080 * - ADC_AnalogWatchdog_None: No channel guarded by the
\r
1084 *******************************************************************************/
\r
1085 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, u32 ADC_AnalogWatchdog)
\r
1089 /* Check the parameters */
\r
1090 assert(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog));
\r
1092 /* Get the old register value */
\r
1093 tmpreg = ADCx->CR1;
\r
1094 /* Clear AWDEN, AWDENJ and AWDSGL bits */
\r
1095 tmpreg &= CR1_AWDMode_Reset;
\r
1096 /* Set the analog watchdog enable mode */
\r
1097 tmpreg |= ADC_AnalogWatchdog;
\r
1098 /* Store the new register value */
\r
1099 ADCx->CR1 = tmpreg;
\r
1102 /*******************************************************************************
\r
1103 * Function Name : ADC_AnalogWatchdogThresholdsConfig
\r
1104 * Description : Configures the High and low thresholds of the analog watchdog.
\r
1105 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1106 * - HighThreshold: the ADC analog watchdog High threshold value.
\r
1107 * This parameter must be a 12bit value.
\r
1108 * - LowThreshold: the ADC analog watchdog Low threshold value.
\r
1109 * This parameter must be a 12bit value.
\r
1112 *******************************************************************************/
\r
1113 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, u16 HighThreshold,
\r
1116 /* Check the parameters */
\r
1117 assert(IS_ADC_THRESHOLD(HighThreshold));
\r
1118 assert(IS_ADC_THRESHOLD(LowThreshold));
\r
1120 /* Set the ADCx high threshold */
\r
1121 ADCx->HTR = HighThreshold;
\r
1122 /* Set the ADCx low threshold */
\r
1123 ADCx->LTR = LowThreshold;
\r
1126 /*******************************************************************************
\r
1127 * Function Name : ADC_AnalogWatchdogSingleChannelConfig
\r
1128 * Description : Configures the analog watchdog guarded single channel
\r
1129 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1130 * - ADC_Channel: the ADC channel to configure for the analog
\r
1132 * This parameter can be one of the following values:
\r
1133 * - ADC_Channel_0: ADC Channel0 selected
\r
1134 * - ADC_Channel_1: ADC Channel1 selected
\r
1135 * - ADC_Channel_2: ADC Channel2 selected
\r
1136 * - ADC_Channel_3: ADC Channel3 selected
\r
1137 * - ADC_Channel_4: ADC Channel4 selected
\r
1138 * - ADC_Channel_5: ADC Channel5 selected
\r
1139 * - ADC_Channel_6: ADC Channel6 selected
\r
1140 * - ADC_Channel_7: ADC Channel7 selected
\r
1141 * - ADC_Channel_8: ADC Channel8 selected
\r
1142 * - ADC_Channel_9: ADC Channel9 selected
\r
1143 * - ADC_Channel_10: ADC Channel10 selected
\r
1144 * - ADC_Channel_11: ADC Channel11 selected
\r
1145 * - ADC_Channel_12: ADC Channel12 selected
\r
1146 * - ADC_Channel_13: ADC Channel13 selected
\r
1147 * - ADC_Channel_14: ADC Channel14 selected
\r
1148 * - ADC_Channel_15: ADC Channel15 selected
\r
1149 * - ADC_Channel_16: ADC Channel16 selected
\r
1150 * - ADC_Channel_17: ADC Channel17 selected
\r
1153 *******************************************************************************/
\r
1154 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, u8 ADC_Channel)
\r
1158 /* Check the parameters */
\r
1159 assert(IS_ADC_CHANNEL(ADC_Channel));
\r
1161 /* Get the old register value */
\r
1162 tmpreg = ADCx->CR1;
\r
1163 /* Clear the Analog watchdog channel select bits */
\r
1164 tmpreg &= CR1_AWDCH_Reset;
\r
1165 /* Set the Analog watchdog channel */
\r
1166 tmpreg |= ADC_Channel;
\r
1167 /* Store the new register value */
\r
1168 ADCx->CR1 = tmpreg;
\r
1171 /*******************************************************************************
\r
1172 * Function Name : ADC_TempSensorCmd
\r
1173 * Description : Enables or disables the temperature sensor.
\r
1174 * Input : - NewState: new state of the temperature sensor.
\r
1175 * This parameter can be: ENABLE or DISABLE.
\r
1178 *******************************************************************************/
\r
1179 void ADC_TempSensorCmd(FunctionalState NewState)
\r
1181 /* Check the parameters */
\r
1182 assert(IS_FUNCTIONAL_STATE(NewState));
\r
1184 if (NewState != DISABLE)
\r
1186 /* Enable the temperature sensor */
\r
1187 ADC1->CR2 |= CR2_TSPD_Set;
\r
1191 /* Disable the temperature sensor */
\r
1192 ADC1->CR2 &= CR2_TSPD_Reset;
\r
1196 /*******************************************************************************
\r
1197 * Function Name : ADC_GetFlagStatus
\r
1198 * Description : Checks whether the specified ADC flag is set or not.
\r
1199 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1200 * - ADC_FLAG: specifies the flag to check.
\r
1201 * This parameter can be one of the following values:
\r
1202 * - ADC_FLAG_AWD: Analog watchdog flag
\r
1203 * - ADC_FLAG_EOC: End of conversion flag
\r
1204 * - ADC_FLAG_JEOC: End of injected group conversion flag
\r
1205 * - ADC_FLAG_JSTRT: Start of injected group conversion flag
\r
1206 * - ADC_FLAG_STRT: Start of regular group conversion flag
\r
1208 * Return : The new state of ADC_FLAG (SET or RESET).
\r
1209 *******************************************************************************/
\r
1210 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, u8 ADC_FLAG)
\r
1212 FlagStatus bitstatus = RESET;
\r
1214 /* Check the parameters */
\r
1215 assert(IS_ADC_GET_FLAG(ADC_FLAG));
\r
1217 /* Check the status of the specified ADC flag */
\r
1218 if ((ADCx->SR & ADC_FLAG) != (u8)RESET)
\r
1220 /* ADC_FLAG is set */
\r
1225 /* ADC_FLAG is reset */
\r
1226 bitstatus = RESET;
\r
1228 /* Return the ADC_FLAG status */
\r
1232 /*******************************************************************************
\r
1233 * Function Name : ADC_ClearFlag
\r
1234 * Description : Clears the ADCx's pending flags.
\r
1235 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1236 * - ADC_FLAG: specifies the flag to clear.
\r
1237 * This parameter can be any combination of the following values:
\r
1238 * - ADC_FLAG_AWD: Analog watchdog flag
\r
1239 * - ADC_FLAG_EOC: End of conversion flag
\r
1240 * - ADC_FLAG_JEOC: End of injected group conversion flag
\r
1241 * - ADC_FLAG_JSTRT: Start of injected group conversion flag
\r
1242 * - ADC_FLAG_STRT: Start of regular group conversion flag
\r
1245 *******************************************************************************/
\r
1246 void ADC_ClearFlag(ADC_TypeDef* ADCx, u8 ADC_FLAG)
\r
1248 /* Check the parameters */
\r
1249 assert(IS_ADC_CLEAR_FLAG(ADC_FLAG));
\r
1251 /* Clear the selected ADC flags */
\r
1252 ADCx->SR &= ~(u32)ADC_FLAG;
\r
1255 /*******************************************************************************
\r
1256 * Function Name : ADC_GetITStatus
\r
1257 * Description : Checks whether the specified ADC interrupt has occurred or not.
\r
1258 * Input : - ADCx: where x can be 1 or 2 to select the ADC peripheral.
\r
1259 * - ADC_IT: specifies the ADC interrupt source to check.
\r
1260 * This parameter can be one of the following values:
\r
1261 * - ADC_IT_EOC: End of conversion interrupt mask
\r
1262 * - ADC_IT_AWD: Analog watchdog interrupt mask
\r
1263 * - ADC_IT_JEOC: End of injected conversion interrupt mask
\r
1265 * Return : The new state of ADC_IT (SET or RESET).
\r
1266 *******************************************************************************/
\r
1267 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, u16 ADC_IT)
\r
1269 ITStatus bitstatus = RESET;
\r
1270 u8 itmask = 0, enablestatus;
\r
1272 /* Check the parameters */
\r
1273 assert(IS_ADC_GET_IT(ADC_IT));
\r
1275 /* Get the ADC IT index */
\r
1276 itmask = (u8)(ADC_IT >> 8);
\r
1278 /* Get the ADC_IT enable bit status */
\r
1279 enablestatus = (ADCx->CR1 & (u8)ADC_IT) ;
\r
1281 /* Check the status of the specified ADC interrupt */
\r
1282 if (((ADCx->SR & itmask) != (u8)RESET) && enablestatus)
\r
1284 /* ADC_IT is set */
\r
1289 /* ADC_IT is reset */
\r
1290 bitstatus = RESET;
\r
1292 /* Return the ADC_IT status */
\r
1296 /*******************************************************************************
\r
1297 * Function Name : ADC_ClearITPendingBit
\r
1298 * Description : Clears the ADC
\92s interrupt pending bits.
\r
1299 * Input : - ADC_IT: specifies the ADC interrupt pending bit to clear.
\r
1300 * This parameter can be any combination of the following values:
\r
1301 * - ADC_IT_EOC: End of conversion interrupt mask
\r
1302 * - ADC_IT_AWD: Analog watchdog interrupt mask
\r
1303 * - ADC_IT_JEOC: End of injected conversion interrupt mask
\r
1306 *******************************************************************************/
\r
1307 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, u16 ADC_IT)
\r
1311 /* Check the parameters */
\r
1312 assert(IS_ADC_IT(ADC_IT));
\r
1314 /* Get the ADC IT index */
\r
1315 itmask = (u8)(ADC_IT >> 8);
\r
1317 /* Clear the selected ADC interrupt pending bits */
\r
1318 ADCx->SR &= ~(u32)itmask;
\r
1321 /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
\r