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