2 ******************************************************************************
\r
3 * @file stm32l1xx_adc.c
\r
4 * @author MCD Application Team
\r
6 * @date 05-March-2012
\r
7 * @brief This file provides firmware functions to manage the following
\r
8 * functionalities of the Analog to Digital Convertor (ADC) peripheral:
\r
9 * + Initialization and Configuration
\r
11 * + Analog Watchdog configuration
\r
12 * + Temperature Sensor & Vrefint (Voltage Reference internal) management
\r
13 * + Regular Channels Configuration
\r
14 * + Regular Channels DMA Configuration
\r
15 * + Injected channels Configuration
\r
16 * + Interrupts and flags management
\r
19 ================================================================================
\r
20 ##### How to use this driver #####
\r
21 ================================================================================
\r
23 (#) Configure the ADC Prescaler, conversion resolution and data alignment
\r
24 using the ADC_Init() function.
\r
25 (#) Activate the ADC peripheral using ADC_Cmd() function.
\r
27 *** Regular channels group configuration ***
\r
28 ============================================
\r
30 (+) To configure the ADC regular channels group features, use
\r
31 ADC_Init() and ADC_RegularChannelConfig() functions.
\r
32 (+) To activate the continuous mode, use the ADC_continuousModeCmd()
\r
34 (+) To configurate and activate the Discontinuous mode, use the
\r
35 ADC_DiscModeChannelCountConfig() and ADC_DiscModeCmd() functions.
\r
36 (+) To read the ADC converted values, use the ADC_GetConversionValue()
\r
39 *** DMA for Regular channels group features configuration ***
\r
40 =============================================================
\r
42 (+) To enable the DMA mode for regular channels group, use the
\r
43 ADC_DMACmd() function.
\r
44 (+) To enable the generation of DMA requests continuously at the end
\r
45 of the last DMA transfer, use the ADC_DMARequestAfterLastTransferCmd()
\r
48 *** Injected channels group configuration ***
\r
49 =============================================
\r
51 (+) To configure the ADC Injected channels group features, use
\r
52 ADC_InjectedChannelConfig() and ADC_InjectedSequencerLengthConfig()
\r
54 (+) To activate the continuous mode, use the ADC_continuousModeCmd()
\r
56 (+) To activate the Injected Discontinuous mode, use the
\r
57 ADC_InjectedDiscModeCmd() function.
\r
58 (+) To activate the AutoInjected mode, use the ADC_AutoInjectedConvCmd()
\r
60 (+) To read the ADC converted values, use the ADC_GetInjectedConversionValue()
\r
65 ******************************************************************************
\r
68 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
\r
70 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
71 * You may not use this file except in compliance with the License.
\r
72 * You may obtain a copy of the License at:
\r
74 * http://www.st.com/software_license_agreement_liberty_v2
\r
76 * Unless required by applicable law or agreed to in writing, software
\r
77 * distributed under the License is distributed on an "AS IS" BASIS,
\r
78 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
79 * See the License for the specific language governing permissions and
\r
80 * limitations under the License.
\r
82 ******************************************************************************
\r
85 /* Includes ------------------------------------------------------------------*/
\r
86 #include "stm32l1xx_adc.h"
\r
87 #include "stm32l1xx_rcc.h"
\r
89 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
94 * @brief ADC driver modules
\r
98 /* Private typedef -----------------------------------------------------------*/
\r
99 /* Private define ------------------------------------------------------------*/
\r
100 /* ADC DISCNUM mask */
\r
101 #define CR1_DISCNUM_RESET ((uint32_t)0xFFFF1FFF)
\r
103 /* ADC AWDCH mask */
\r
104 #define CR1_AWDCH_RESET ((uint32_t)0xFFFFFFE0)
\r
106 /* ADC Analog watchdog enable mode mask */
\r
107 #define CR1_AWDMODE_RESET ((uint32_t)0xFF3FFDFF)
\r
109 /* CR1 register Mask */
\r
110 #define CR1_CLEAR_MASK ((uint32_t)0xFCFFFEFF)
\r
112 /* ADC DELAY mask */
\r
113 #define CR2_DELS_RESET ((uint32_t)0xFFFFFF0F)
\r
115 /* ADC JEXTEN mask */
\r
116 #define CR2_JEXTEN_RESET ((uint32_t)0xFFCFFFFF)
\r
118 /* ADC JEXTSEL mask */
\r
119 #define CR2_JEXTSEL_RESET ((uint32_t)0xFFF0FFFF)
\r
121 /* CR2 register Mask */
\r
122 #define CR2_CLEAR_MASK ((uint32_t)0xC0FFF7FD)
\r
125 #define SQR5_SQ_SET ((uint32_t)0x0000001F)
\r
126 #define SQR4_SQ_SET ((uint32_t)0x0000001F)
\r
127 #define SQR3_SQ_SET ((uint32_t)0x0000001F)
\r
128 #define SQR2_SQ_SET ((uint32_t)0x0000001F)
\r
129 #define SQR1_SQ_SET ((uint32_t)0x0000001F)
\r
132 #define SQR1_L_RESET ((uint32_t)0xFE0FFFFF)
\r
134 /* ADC JSQx mask */
\r
135 #define JSQR_JSQ_SET ((uint32_t)0x0000001F)
\r
138 #define JSQR_JL_SET ((uint32_t)0x00300000)
\r
139 #define JSQR_JL_RESET ((uint32_t)0xFFCFFFFF)
\r
141 /* ADC SMPx mask */
\r
142 #define SMPR1_SMP_SET ((uint32_t)0x00000007)
\r
143 #define SMPR2_SMP_SET ((uint32_t)0x00000007)
\r
144 #define SMPR3_SMP_SET ((uint32_t)0x00000007)
\r
145 #define SMPR0_SMP_SET ((uint32_t)0x00000007)
\r
147 /* ADC JDRx registers offset */
\r
148 #define JDR_OFFSET ((uint8_t)0x30)
\r
150 /* ADC CCR register Mask */
\r
151 #define CR_CLEAR_MASK ((uint32_t)0xFFFCFFFF)
\r
153 /* Private macro -------------------------------------------------------------*/
\r
154 /* Private variables ---------------------------------------------------------*/
\r
155 /* Private function prototypes -----------------------------------------------*/
\r
156 /* Private functions ---------------------------------------------------------*/
\r
158 /** @defgroup ADC_Private_Functions
\r
162 /** @defgroup ADC_Group1 Initialization and Configuration functions
\r
163 * @brief Initialization and Configuration functions.
\r
166 ===============================================================================
\r
167 ##### Initialization and Configuration functions #####
\r
168 ===============================================================================
\r
169 [..] This section provides functions allowing to:
\r
170 (+) Initialize and configure the ADC Prescaler.
\r
171 (+) ADC Conversion Resolution (12bit..6bit).
\r
172 (+) Scan Conversion Mode (multichannel or one channel) for regular group.
\r
173 (+) ADC Continuous Conversion Mode (Continuous or Single conversion) for
\r
175 (+) External trigger Edge and source of regular group.
\r
176 (+) Converted data alignment (left or right).
\r
177 (+) The number of ADC conversions that will be done using the sequencer
\r
178 for regular channel group.
\r
179 (+) Enable or disable the ADC peripheral.
\r
186 * @brief Deinitializes ADC1 peripheral registers to their default reset values.
\r
190 void ADC_DeInit(ADC_TypeDef* ADCx)
\r
192 /* Check the parameters */
\r
193 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
197 /* Enable ADC1 reset state */
\r
198 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
\r
199 /* Release ADC1 from reset state */
\r
200 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
\r
205 * @brief Initializes the ADCx peripheral according to the specified parameters
\r
206 * in the ADC_InitStruct.
\r
207 * @note This function is used to configure the global features of the ADC (
\r
208 * Resolution and Data Alignment), however, the rest of the configuration
\r
209 * parameters are specific to the regular channels group (scan mode
\r
210 * activation, continuous mode activation, External trigger source and
\r
211 * edge, number of conversion in the regular channels group sequencer).
\r
212 * @param ADCx: where x can be 1 to select the ADC peripheral.
\r
213 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
\r
214 * the configuration information for the specified ADC peripheral.
\r
217 void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
\r
219 uint32_t tmpreg1 = 0;
\r
220 uint8_t tmpreg2 = 0;
\r
222 /* Check the parameters */
\r
223 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
224 assert_param(IS_ADC_RESOLUTION(ADC_InitStruct->ADC_Resolution));
\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_EDGE(ADC_InitStruct->ADC_ExternalTrigConvEdge));
\r
228 assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct->ADC_ExternalTrigConv));
\r
229 assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
\r
230 assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct->ADC_NbrOfConversion));
\r
232 /*---------------------------- ADCx CR1 Configuration -----------------*/
\r
233 /* Get the ADCx CR1 value */
\r
234 tmpreg1 = ADCx->CR1;
\r
235 /* Clear RES and SCAN bits */
\r
236 tmpreg1 &= CR1_CLEAR_MASK;
\r
237 /* Configure ADCx: scan conversion mode and resolution */
\r
238 /* Set SCAN bit according to ADC_ScanConvMode value */
\r
239 /* Set RES bit according to ADC_Resolution value */
\r
240 tmpreg1 |= (uint32_t)(((uint32_t)ADC_InitStruct->ADC_ScanConvMode << 8) | ADC_InitStruct->ADC_Resolution);
\r
241 /* Write to ADCx CR1 */
\r
242 ADCx->CR1 = tmpreg1;
\r
244 /*---------------------------- ADCx CR2 Configuration -----------------*/
\r
245 /* Get the ADCx CR2 value */
\r
246 tmpreg1 = ADCx->CR2;
\r
247 /* Clear CONT, ALIGN, EXTEN and EXTSEL bits */
\r
248 tmpreg1 &= CR2_CLEAR_MASK;
\r
249 /* Configure ADCx: external trigger event and edge, data alignment and continuous conversion mode */
\r
250 /* Set ALIGN bit according to ADC_DataAlign value */
\r
251 /* Set EXTEN bits according to ADC_ExternalTrigConvEdge value */
\r
252 /* Set EXTSEL bits according to ADC_ExternalTrigConv value */
\r
253 /* Set CONT bit according to ADC_ContinuousConvMode value */
\r
254 tmpreg1 |= (uint32_t)(ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ExternalTrigConv |
\r
255 ADC_InitStruct->ADC_ExternalTrigConvEdge | ((uint32_t)ADC_InitStruct->ADC_ContinuousConvMode << 1));
\r
256 /* Write to ADCx CR2 */
\r
257 ADCx->CR2 = tmpreg1;
\r
259 /*---------------------------- ADCx SQR1 Configuration -----------------*/
\r
260 /* Get the ADCx SQR1 value */
\r
261 tmpreg1 = ADCx->SQR1;
\r
263 tmpreg1 &= SQR1_L_RESET;
\r
264 /* Configure ADCx: regular channel sequence length */
\r
265 /* Set L bits according to ADC_NbrOfConversion value */
\r
266 tmpreg2 |= (uint8_t)(ADC_InitStruct->ADC_NbrOfConversion - (uint8_t)1);
\r
267 tmpreg1 |= ((uint32_t)tmpreg2 << 20);
\r
268 /* Write to ADCx SQR1 */
\r
269 ADCx->SQR1 = tmpreg1;
\r
273 * @brief Fills each ADC_InitStruct member with its default value.
\r
274 * @note This function is used to initialize the global features of the ADC (
\r
275 * Resolution and Data Alignment), however, the rest of the configuration
\r
276 * parameters are specific to the regular channels group (scan mode
\r
277 * activation, continuous mode activation, External trigger source and
\r
278 * edge, number of conversion in the regular channels group sequencer).
\r
279 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure which will
\r
283 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
\r
285 /* Reset ADC init structure parameters values */
\r
286 /* Initialize the ADC_Resolution member */
\r
287 ADC_InitStruct->ADC_Resolution = ADC_Resolution_12b;
\r
289 /* Initialize the ADC_ScanConvMode member */
\r
290 ADC_InitStruct->ADC_ScanConvMode = DISABLE;
\r
292 /* Initialize the ADC_ContinuousConvMode member */
\r
293 ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
\r
295 /* Initialize the ADC_ExternalTrigConvEdge member */
\r
296 ADC_InitStruct->ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
\r
298 /* Initialize the ADC_ExternalTrigConv member */
\r
299 ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;
\r
301 /* Initialize the ADC_DataAlign member */
\r
302 ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
\r
304 /* Initialize the ADC_NbrOfConversion member */
\r
305 ADC_InitStruct->ADC_NbrOfConversion = 1;
\r
309 * @brief Initializes the ADCs peripherals according to the specified parameters
\r
310 * in the ADC_CommonInitStruct.
\r
311 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
\r
312 * that contains the configuration information (Prescaler) for ADC1 peripheral.
\r
315 void ADC_CommonInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct)
\r
317 uint32_t tmpreg = 0;
\r
319 /* Check the parameters */
\r
320 assert_param(IS_ADC_PRESCALER(ADC_CommonInitStruct->ADC_Prescaler));
\r
322 /*---------------------------- ADC CCR Configuration -----------------*/
\r
323 /* Get the ADC CCR value */
\r
326 /* Clear ADCPRE bit */
\r
327 tmpreg &= CR_CLEAR_MASK;
\r
329 /* Configure ADCx: ADC prescaler according to ADC_Prescaler */
\r
330 tmpreg |= (uint32_t)(ADC_CommonInitStruct->ADC_Prescaler);
\r
332 /* Write to ADC CCR */
\r
337 * @brief Fills each ADC_CommonInitStruct member with its default value.
\r
338 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
\r
339 * which will be initialized.
\r
342 void ADC_CommonStructInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct)
\r
344 /* Reset ADC init structure parameters values */
\r
345 /* Initialize the ADC_Prescaler member */
\r
346 ADC_CommonInitStruct->ADC_Prescaler = ADC_Prescaler_Div1;
\r
350 * @brief Enables or disables the specified ADC peripheral.
\r
351 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
352 * @param NewState: new state of the ADCx peripheral.
\r
353 * This parameter can be: ENABLE or DISABLE.
\r
356 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
358 /* Check the parameters */
\r
359 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
360 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
362 if (NewState != DISABLE)
\r
364 /* Set the ADON bit to wake up the ADC from power down mode */
\r
365 ADCx->CR2 |= (uint32_t)ADC_CR2_ADON;
\r
369 /* Disable the selected ADC peripheral */
\r
370 ADCx->CR2 &= (uint32_t)(~ADC_CR2_ADON);
\r
375 * @brief Selects the specified ADC Channels Bank.
\r
376 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
377 * @param ADC_Bank: ADC Channels Bank.
\r
378 * @arg ADC_Bank_A: ADC Channels Bank A.
\r
379 * @arg ADC_Bank_B: ADC Channels Bank B.
\r
382 void ADC_BankSelection(ADC_TypeDef* ADCx, uint8_t ADC_Bank)
\r
384 /* Check the parameters */
\r
385 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
386 assert_param(IS_ADC_BANK(ADC_Bank));
\r
388 if (ADC_Bank != ADC_Bank_A)
\r
390 /* Set the ADC_CFG bit to select the ADC Bank B channels */
\r
391 ADCx->CR2 |= (uint32_t)ADC_CR2_CFG;
\r
395 /* Reset the ADC_CFG bit to select the ADC Bank A channels */
\r
396 ADCx->CR2 &= (uint32_t)(~ADC_CR2_CFG);
\r
404 /** @defgroup ADC_Group2 Power saving functions
\r
405 * @brief Power saving functions
\r
408 ===============================================================================
\r
409 ##### Power saving functions #####
\r
410 ===============================================================================
\r
411 [..] This section provides functions allowing to reduce power consumption.
\r
412 [..] The two function must be combined to get the maximal benefits:
\r
413 When the ADC frequency is higher than the CPU one, it is recommended to:
\r
414 (#) Insert a freeze delay :
\r
415 ==> using ADC_DelaySelectionConfig(ADC1, ADC_DelayLength_Freeze).
\r
416 (#) Enable the power down in Idle and Delay phases :
\r
417 ==> using ADC_PowerDownCmd(ADC1, ADC_PowerDown_Idle_Delay, ENABLE).
\r
424 * @brief Enables or disables the ADC Power Down during Delay and/or Idle phase.
\r
425 * @note ADC power-on and power-off can be managed by hardware to cut the
\r
426 * consumption when the ADC is not converting.
\r
427 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
428 * @param ADC_PowerDown: The ADC power down configuration.
\r
429 * This parameter can be one of the following values:
\r
430 * @arg ADC_PowerDown_Delay: ADC is powered down during delay phase.
\r
431 * @arg ADC_PowerDown_Idle: ADC is powered down during Idle phase.
\r
432 * @arg ADC_PowerDown_Idle_Delay: ADC is powered down during Delay and Idle phases.
\r
433 * @note The ADC can be powered down:
\r
434 * @note During the hardware delay insertion (using the ADC_PowerDown_Delay
\r
436 * => The ADC is powered up again at the end of the delay.
\r
437 * @note During the ADC is waiting for a trigger event ( using the
\r
438 * ADC_PowerDown_Idle parameter).
\r
439 * => The ADC is powered up at the next trigger event.
\r
440 * @note During the hardware delay insertion or the ADC is waiting for a
\r
441 * trigger event (using the ADC_PowerDown_Idle_Delay parameter).
\r
442 * => The ADC is powered up only at the end of the delay and at the
\r
443 * next trigger event.
\r
444 * @param NewState: new state of the ADCx power down.
\r
445 * This parameter can be: ENABLE or DISABLE.
\r
448 void ADC_PowerDownCmd(ADC_TypeDef* ADCx, uint32_t ADC_PowerDown, FunctionalState NewState)
\r
450 /* Check the parameters */
\r
451 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
452 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
453 assert_param(IS_ADC_POWER_DOWN(ADC_PowerDown));
\r
455 if (NewState != DISABLE)
\r
457 /* Enable the ADC power-down during Delay and/or Idle phase */
\r
458 ADCx->CR1 |= ADC_PowerDown;
\r
462 /* Disable The ADC power-down during Delay and/or Idle phase */
\r
463 ADCx->CR1 &= (uint32_t)~ADC_PowerDown;
\r
468 * @brief Defines the length of the delay which is applied after a conversion
\r
469 * or a sequence of conversion.
\r
470 * @note When the CPU clock is not fast enough to manage the data rate, a
\r
471 * Hardware delay can be introduced between ADC conversions to reduce
\r
473 * @note The Hardware delay is inserted after :
\r
474 * - each regular conversion.
\r
475 * - after each sequence of injected conversions.
\r
476 * @note No Hardware delay is inserted between conversions of different groups.
\r
477 * @note When the hardware delay is not enough, the Freeze Delay Mode can be
\r
478 * selected and a new conversion can start only if all the previous data
\r
479 * of the same group have been treated:
\r
480 * - for a regular conversion: once the ADC conversion data register has
\r
481 * been read (using ADC_GetConversionValue() function) or if the EOC
\r
482 * Flag has been cleared (using ADC_ClearFlag() function).
\r
483 * - for an injected conversion: when the JEOC bit has been cleared
\r
484 * (using ADC_ClearFlag() function).
\r
485 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
486 * @param ADC_DelayLength: The length of delay which is applied after a
\r
487 * conversion or a sequence of conversion.
\r
488 * This parameter can be one of the following values:
\r
489 * @arg ADC_DelayLength_None: No delay.
\r
490 * @arg ADC_DelayLength_Freeze: Delay until the converted data has been read.
\r
491 * @arg ADC_DelayLength_7Cycles: Delay length equal to 7 APB clock cycles.
\r
492 * @arg ADC_DelayLength_15Cycles: Delay length equal to 15 APB clock cycles
\r
493 * @arg ADC_DelayLength_31Cycles: Delay length equal to 31 APB clock cycles
\r
494 * @arg ADC_DelayLength_63Cycles: Delay length equal to 63 APB clock cycles
\r
495 * @arg ADC_DelayLength_127Cycles: Delay length equal to 127 APB clock cycles
\r
496 * @arg ADC_DelayLength_255Cycles: Delay length equal to 255 APB clock cycles
\r
499 void ADC_DelaySelectionConfig(ADC_TypeDef* ADCx, uint8_t ADC_DelayLength)
\r
501 uint32_t tmpreg = 0;
\r
503 /* Check the parameters */
\r
504 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
505 assert_param(IS_ADC_DELAY_LENGTH(ADC_DelayLength));
\r
507 /* Get the old register value */
\r
508 tmpreg = ADCx->CR2;
\r
509 /* Clear the old delay length */
\r
510 tmpreg &= CR2_DELS_RESET;
\r
511 /* Set the delay length */
\r
512 tmpreg |= ADC_DelayLength;
\r
513 /* Store the new register value */
\r
514 ADCx->CR2 = tmpreg;
\r
522 /** @defgroup ADC_Group3 Analog Watchdog configuration functions
\r
523 * @brief Analog Watchdog configuration functions.
\r
526 ===============================================================================
\r
527 ##### Analog Watchdog configuration functions #####
\r
528 ===============================================================================
\r
529 [..] This section provides functions allowing to configure the Analog Watchdog
\r
530 (AWD) feature in the ADC.
\r
531 [..] A typical configuration Analog Watchdog is done following these steps :
\r
532 (#) the ADC guarded channel(s) is (are) selected using the
\r
533 ADC_AnalogWatchdogSingleChannelConfig() function.
\r
534 (#) The Analog watchdog lower and higher threshold are configured using
\r
535 the ADC_AnalogWatchdogThresholdsConfig() function.
\r
536 (#) The Analog watchdog is enabled and configured to enable the check,
\r
537 on one or more channels, using the ADC_AnalogWatchdogCmd() function.
\r
544 * @brief Enables or disables the analog watchdog on single/all regular
\r
545 * or injected channels.
\r
546 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
547 * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration.
\r
548 * This parameter can be one of the following values:
\r
549 * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single
\r
551 * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single
\r
552 * injected channel.
\r
553 * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a
\r
554 * single regular or injected channel.
\r
555 * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular
\r
557 * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected
\r
559 * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all
\r
560 * regular and injected channels.
\r
561 * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog.
\r
564 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog)
\r
566 uint32_t tmpreg = 0;
\r
568 /* Check the parameters */
\r
569 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
570 assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog));
\r
572 /* Get the old register value */
\r
573 tmpreg = ADCx->CR1;
\r
574 /* Clear AWDEN, JAWDEN and AWDSGL bits */
\r
575 tmpreg &= CR1_AWDMODE_RESET;
\r
576 /* Set the analog watchdog enable mode */
\r
577 tmpreg |= ADC_AnalogWatchdog;
\r
578 /* Store the new register value */
\r
579 ADCx->CR1 = tmpreg;
\r
583 * @brief Configures the high and low thresholds of the analog watchdog.
\r
584 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
585 * @param HighThreshold: the ADC analog watchdog High threshold value.
\r
586 * This parameter must be a 12bit value.
\r
587 * @param LowThreshold: the ADC analog watchdog Low threshold value.
\r
588 * This parameter must be a 12bit value.
\r
591 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,
\r
592 uint16_t LowThreshold)
\r
594 /* Check the parameters */
\r
595 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
596 assert_param(IS_ADC_THRESHOLD(HighThreshold));
\r
597 assert_param(IS_ADC_THRESHOLD(LowThreshold));
\r
599 /* Set the ADCx high threshold */
\r
600 ADCx->HTR = HighThreshold;
\r
601 /* Set the ADCx low threshold */
\r
602 ADCx->LTR = LowThreshold;
\r
606 * @brief Configures the analog watchdog guarded single channel.
\r
607 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
608 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
\r
609 * This parameter can be one of the following values:
\r
610 * @arg ADC_Channel_0: ADC Channel0 selected
\r
611 * @arg ADC_Channel_1: ADC Channel1 selected
\r
612 * @arg ADC_Channel_2: ADC Channel2 selected
\r
613 * @arg ADC_Channel_3: ADC Channel3 selected
\r
614 * @arg ADC_Channel_4: ADC Channel4 selected
\r
615 * @arg ADC_Channel_5: ADC Channel5 selected
\r
616 * @arg ADC_Channel_6: ADC Channel6 selected
\r
617 * @arg ADC_Channel_7: ADC Channel7 selected
\r
618 * @arg ADC_Channel_8: ADC Channel8 selected
\r
619 * @arg ADC_Channel_9: ADC Channel9 selected
\r
620 * @arg ADC_Channel_10: ADC Channel10 selected
\r
621 * @arg ADC_Channel_11: ADC Channel11 selected
\r
622 * @arg ADC_Channel_12: ADC Channel12 selected
\r
623 * @arg ADC_Channel_13: ADC Channel13 selected
\r
624 * @arg ADC_Channel_14: ADC Channel14 selected
\r
625 * @arg ADC_Channel_15: ADC Channel15 selected
\r
626 * @arg ADC_Channel_16: ADC Channel16 selected
\r
627 * @arg ADC_Channel_17: ADC Channel17 selected
\r
628 * @arg ADC_Channel_18: ADC Channel18 selected
\r
629 * @arg ADC_Channel_19: ADC Channel19 selected
\r
630 * @arg ADC_Channel_20: ADC Channel20 selected
\r
631 * @arg ADC_Channel_21: ADC Channel21 selected
\r
632 * @arg ADC_Channel_22: ADC Channel22 selected
\r
633 * @arg ADC_Channel_23: ADC Channel23 selected
\r
634 * @arg ADC_Channel_24: ADC Channel24 selected
\r
635 * @arg ADC_Channel_25: ADC Channel25 selected
\r
636 * @arg ADC_Channel_27: ADC Channel27 selected
\r
637 * @arg ADC_Channel_28: ADC Channel28 selected
\r
638 * @arg ADC_Channel_29: ADC Channel29 selected
\r
639 * @arg ADC_Channel_30: ADC Channel30 selected
\r
640 * @arg ADC_Channel_31: ADC Channel31 selected
\r
641 * @arg ADC_Channel_0b: ADC Channel0b selected
\r
642 * @arg ADC_Channel_1b: ADC Channel1b selected
\r
643 * @arg ADC_Channel_2b: ADC Channel2b selected
\r
644 * @arg ADC_Channel_3b: ADC Channel3b selected
\r
645 * @arg ADC_Channel_6b: ADC Channel6b selected
\r
646 * @arg ADC_Channel_7b: ADC Channel7b selected
\r
647 * @arg ADC_Channel_8b: ADC Channel8b selected
\r
648 * @arg ADC_Channel_9b: ADC Channel9b selected
\r
649 * @arg ADC_Channel_10b: ADC Channel10b selected
\r
650 * @arg ADC_Channel_11b: ADC Channel11b selected
\r
651 * @arg ADC_Channel_12b: ADC Channel12b selected
\r
654 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel)
\r
656 uint32_t tmpreg = 0;
\r
658 /* Check the parameters */
\r
659 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
660 assert_param(IS_ADC_CHANNEL(ADC_Channel));
\r
662 /* Get the old register value */
\r
663 tmpreg = ADCx->CR1;
\r
664 /* Clear the Analog watchdog channel select bits */
\r
665 tmpreg &= CR1_AWDCH_RESET;
\r
666 /* Set the Analog watchdog channel */
\r
667 tmpreg |= ADC_Channel;
\r
668 /* Store the new register value */
\r
669 ADCx->CR1 = tmpreg;
\r
676 /** @defgroup ADC_Group4 Temperature Sensor & Vrefint (Voltage Reference internal) management function
\r
677 * @brief Temperature Sensor & Vrefint (Voltage Reference internal) management function.
\r
680 =========================================================================================
\r
681 ##### Temperature Sensor and Vrefint (Voltage Reference internal) management function #####
\r
682 =========================================================================================
\r
683 [..] This section provides a function allowing to enable/ disable the internal
\r
684 connections between the ADC and the Temperature Sensor and the Vrefint
\r
686 [..] A typical configuration to get the Temperature sensor and Vrefint channels
\r
687 voltages is done following these steps :
\r
688 (#) Enable the internal connection of Temperature sensor and Vrefint sources
\r
689 with the ADC channels using ADC_TempSensorVrefintCmd() function.
\r
690 (#) select the ADC_Channel_TempSensor and/or ADC_Channel_Vrefint using
\r
691 ADC_RegularChannelConfig() or ADC_InjectedChannelConfig() functions.
\r
692 (#) Get the voltage values, using ADC_GetConversionValue() or
\r
693 ADC_GetInjectedConversionValue().
\r
699 * @brief Enables or disables the temperature sensor and Vrefint channel.
\r
700 * @param NewState: new state of the temperature sensor and Vref int channels.
\r
701 * This parameter can be: ENABLE or DISABLE.
\r
704 void ADC_TempSensorVrefintCmd(FunctionalState NewState)
\r
706 /* Check the parameters */
\r
707 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
709 if (NewState != DISABLE)
\r
711 /* Enable the temperature sensor and Vrefint channel*/
\r
712 ADC->CCR |= (uint32_t)ADC_CCR_TSVREFE;
\r
716 /* Disable the temperature sensor and Vrefint channel*/
\r
717 ADC->CCR &= (uint32_t)(~ADC_CCR_TSVREFE);
\r
725 /** @defgroup ADC_Group5 Regular Channels Configuration functions
\r
726 * @brief Regular Channels Configuration functions.
\r
729 ===============================================================================
\r
730 ##### Regular Channels Configuration functions #####
\r
731 ===============================================================================
\r
732 [..] This section provides functions allowing to manage the ADC regular channels,
\r
733 it is composed of 2 sub sections :
\r
734 (#) Configuration and management functions for regular channels: This
\r
735 subsection provides functions allowing to configure the ADC regular
\r
737 (++) Configure the rank in the regular group sequencer for each channel.
\r
738 (++) Configure the sampling time for each channel.
\r
739 (++) select the conversion Trigger for regular channels.
\r
740 (++) select the desired EOC event behavior configuration.
\r
741 (++) Activate the continuous Mode (*).
\r
742 (++) Activate the Discontinuous Mode.
\r
743 -@@- Please Note that the following features for regular channels are
\r
744 configurated using the ADC_Init() function :
\r
745 (+@@) scan mode activation.
\r
746 (+@@) continuous mode activation (**).
\r
747 (+@@) External trigger source.
\r
748 (+@@) External trigger edge.
\r
749 (+@@) number of conversion in the regular channels group sequencer.
\r
750 -@@- (*) and (**) are performing the same configuration.
\r
751 (#) Get the conversion data: This subsection provides an important function
\r
752 in the ADC peripheral since it returns the converted data of the current
\r
753 regular channel. When the Conversion value is read, the EOC Flag is
\r
754 automatically cleared.
\r
760 * @brief Configures for the selected ADC regular channel its corresponding
\r
761 * rank in the sequencer and its sampling time.
\r
762 * @param ADCx: where x can be 1 to select the ADC peripheral.
\r
763 * @param ADC_Channel: the ADC channel to configure.
\r
764 * This parameter can be one of the following values:
\r
765 * @arg ADC_Channel_0: ADC Channel0 selected
\r
766 * @arg ADC_Channel_1: ADC Channel1 selected
\r
767 * @arg ADC_Channel_2: ADC Channel2 selected
\r
768 * @arg ADC_Channel_3: ADC Channel3 selected
\r
769 * @arg ADC_Channel_4: ADC Channel4 selected
\r
770 * @arg ADC_Channel_5: ADC Channel5 selected
\r
771 * @arg ADC_Channel_6: ADC Channel6 selected
\r
772 * @arg ADC_Channel_7: ADC Channel7 selected
\r
773 * @arg ADC_Channel_8: ADC Channel8 selected
\r
774 * @arg ADC_Channel_9: ADC Channel9 selected
\r
775 * @arg ADC_Channel_10: ADC Channel10 selected
\r
776 * @arg ADC_Channel_11: ADC Channel11 selected
\r
777 * @arg ADC_Channel_12: ADC Channel12 selected
\r
778 * @arg ADC_Channel_13: ADC Channel13 selected
\r
779 * @arg ADC_Channel_14: ADC Channel14 selected
\r
780 * @arg ADC_Channel_15: ADC Channel15 selected
\r
781 * @arg ADC_Channel_16: ADC Channel16 selected
\r
782 * @arg ADC_Channel_17: ADC Channel17 selected
\r
783 * @arg ADC_Channel_18: ADC Channel18 selected
\r
784 * @arg ADC_Channel_19: ADC Channel19 selected
\r
785 * @arg ADC_Channel_20: ADC Channel20 selected
\r
786 * @arg ADC_Channel_21: ADC Channel21 selected
\r
787 * @arg ADC_Channel_22: ADC Channel22 selected
\r
788 * @arg ADC_Channel_23: ADC Channel23 selected
\r
789 * @arg ADC_Channel_24: ADC Channel24 selected
\r
790 * @arg ADC_Channel_25: ADC Channel25 selected
\r
791 * @arg ADC_Channel_27: ADC Channel27 selected
\r
792 * @arg ADC_Channel_28: ADC Channel28 selected
\r
793 * @arg ADC_Channel_29: ADC Channel29 selected
\r
794 * @arg ADC_Channel_30: ADC Channel30 selected
\r
795 * @arg ADC_Channel_31: ADC Channel31 selected
\r
796 * @arg ADC_Channel_0b: ADC Channel0b selected
\r
797 * @arg ADC_Channel_1b: ADC Channel1b selected
\r
798 * @arg ADC_Channel_2b: ADC Channel2b selected
\r
799 * @arg ADC_Channel_3b: ADC Channel3b selected
\r
800 * @arg ADC_Channel_6b: ADC Channel6b selected
\r
801 * @arg ADC_Channel_7b: ADC Channel7b selected
\r
802 * @arg ADC_Channel_8b: ADC Channel8b selected
\r
803 * @arg ADC_Channel_9b: ADC Channel9b selected
\r
804 * @arg ADC_Channel_10b: ADC Channel10b selected
\r
805 * @arg ADC_Channel_11b: ADC Channel11b selected
\r
806 * @arg ADC_Channel_12b: ADC Channel12b selected
\r
807 * @param Rank: The rank in the regular group sequencer. This parameter
\r
808 * must be between 1 to 28.
\r
809 * @param ADC_SampleTime: The sample time value to be set for the selected
\r
811 * This parameter can be one of the following values:
\r
812 * @arg ADC_SampleTime_4Cycles: Sample time equal to 4 cycles
\r
813 * @arg ADC_SampleTime_9Cycles: Sample time equal to 9 cycles
\r
814 * @arg ADC_SampleTime_16Cycles: Sample time equal to 16 cycles
\r
815 * @arg ADC_SampleTime_24Cycles: Sample time equal to 24 cycles
\r
816 * @arg ADC_SampleTime_48Cycles: Sample time equal to 48 cycles
\r
817 * @arg ADC_SampleTime_96Cycles: Sample time equal to 96 cycles
\r
818 * @arg ADC_SampleTime_192Cycles: Sample time equal to 192 cycles
\r
819 * @arg ADC_SampleTime_384Cycles: Sample time equal to 384 cycles
\r
822 void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
\r
824 uint32_t tmpreg1 = 0, tmpreg2 = 0;
\r
826 /* Check the parameters */
\r
827 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
828 assert_param(IS_ADC_CHANNEL(ADC_Channel));
\r
829 assert_param(IS_ADC_REGULAR_RANK(Rank));
\r
830 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
\r
832 /* If ADC_Channel_30 or ADC_Channel_31 is selected */
\r
833 if (ADC_Channel > ADC_Channel_29)
\r
835 /* Get the old register value */
\r
836 tmpreg1 = ADCx->SMPR0;
\r
837 /* Calculate the mask to clear */
\r
838 tmpreg2 = SMPR0_SMP_SET << (3 * (ADC_Channel - 30));
\r
839 /* Clear the old sample time */
\r
840 tmpreg1 &= ~tmpreg2;
\r
841 /* Calculate the mask to set */
\r
842 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 30));
\r
843 /* Set the new sample time */
\r
844 tmpreg1 |= tmpreg2;
\r
845 /* Store the new register value */
\r
846 ADCx->SMPR0 = tmpreg1;
\r
848 /* If ADC_Channel_20 ... ADC_Channel_29 is selected */
\r
849 else if (ADC_Channel > ADC_Channel_19)
\r
851 /* Get the old register value */
\r
852 tmpreg1 = ADCx->SMPR1;
\r
853 /* Calculate the mask to clear */
\r
854 tmpreg2 = SMPR1_SMP_SET << (3 * (ADC_Channel - 20));
\r
855 /* Clear the old sample time */
\r
856 tmpreg1 &= ~tmpreg2;
\r
857 /* Calculate the mask to set */
\r
858 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 20));
\r
859 /* Set the new sample time */
\r
860 tmpreg1 |= tmpreg2;
\r
861 /* Store the new register value */
\r
862 ADCx->SMPR1 = tmpreg1;
\r
864 /* If ADC_Channel_10 ... ADC_Channel_19 is selected */
\r
865 else if (ADC_Channel > ADC_Channel_9)
\r
867 /* Get the old register value */
\r
868 tmpreg1 = ADCx->SMPR2;
\r
869 /* Calculate the mask to clear */
\r
870 tmpreg2 = SMPR2_SMP_SET << (3 * (ADC_Channel - 10));
\r
871 /* Clear the old sample time */
\r
872 tmpreg1 &= ~tmpreg2;
\r
873 /* Calculate the mask to set */
\r
874 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
\r
875 /* Set the new sample time */
\r
876 tmpreg1 |= tmpreg2;
\r
877 /* Store the new register value */
\r
878 ADCx->SMPR2 = tmpreg1;
\r
880 else /* ADC_Channel include in ADC_Channel_[0..9] */
\r
882 /* Get the old register value */
\r
883 tmpreg1 = ADCx->SMPR3;
\r
884 /* Calculate the mask to clear */
\r
885 tmpreg2 = SMPR3_SMP_SET << (3 * ADC_Channel);
\r
886 /* Clear the old sample time */
\r
887 tmpreg1 &= ~tmpreg2;
\r
888 /* Calculate the mask to set */
\r
889 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
\r
890 /* Set the new sample time */
\r
891 tmpreg1 |= tmpreg2;
\r
892 /* Store the new register value */
\r
893 ADCx->SMPR3 = tmpreg1;
\r
895 /* For Rank 1 to 6 */
\r
898 /* Get the old register value */
\r
899 tmpreg1 = ADCx->SQR5;
\r
900 /* Calculate the mask to clear */
\r
901 tmpreg2 = SQR5_SQ_SET << (5 * (Rank - 1));
\r
902 /* Clear the old SQx bits for the selected rank */
\r
903 tmpreg1 &= ~tmpreg2;
\r
904 /* Calculate the mask to set */
\r
905 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 1));
\r
906 /* Set the SQx bits for the selected rank */
\r
907 tmpreg1 |= tmpreg2;
\r
908 /* Store the new register value */
\r
909 ADCx->SQR5 = tmpreg1;
\r
911 /* For Rank 7 to 12 */
\r
912 else if (Rank < 13)
\r
914 /* Get the old register value */
\r
915 tmpreg1 = ADCx->SQR4;
\r
916 /* Calculate the mask to clear */
\r
917 tmpreg2 = SQR4_SQ_SET << (5 * (Rank - 7));
\r
918 /* Clear the old SQx bits for the selected rank */
\r
919 tmpreg1 &= ~tmpreg2;
\r
920 /* Calculate the mask to set */
\r
921 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 7));
\r
922 /* Set the SQx bits for the selected rank */
\r
923 tmpreg1 |= tmpreg2;
\r
924 /* Store the new register value */
\r
925 ADCx->SQR4 = tmpreg1;
\r
927 /* For Rank 13 to 18 */
\r
928 else if (Rank < 19)
\r
930 /* Get the old register value */
\r
931 tmpreg1 = ADCx->SQR3;
\r
932 /* Calculate the mask to clear */
\r
933 tmpreg2 = SQR3_SQ_SET << (5 * (Rank - 13));
\r
934 /* Clear the old SQx bits for the selected rank */
\r
935 tmpreg1 &= ~tmpreg2;
\r
936 /* Calculate the mask to set */
\r
937 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 13));
\r
938 /* Set the SQx bits for the selected rank */
\r
939 tmpreg1 |= tmpreg2;
\r
940 /* Store the new register value */
\r
941 ADCx->SQR3 = tmpreg1;
\r
944 /* For Rank 19 to 24 */
\r
945 else if (Rank < 25)
\r
947 /* Get the old register value */
\r
948 tmpreg1 = ADCx->SQR2;
\r
949 /* Calculate the mask to clear */
\r
950 tmpreg2 = SQR2_SQ_SET << (5 * (Rank - 19));
\r
951 /* Clear the old SQx bits for the selected rank */
\r
952 tmpreg1 &= ~tmpreg2;
\r
953 /* Calculate the mask to set */
\r
954 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 19));
\r
955 /* Set the SQx bits for the selected rank */
\r
956 tmpreg1 |= tmpreg2;
\r
957 /* Store the new register value */
\r
958 ADCx->SQR2 = tmpreg1;
\r
961 /* For Rank 25 to 28 */
\r
964 /* Get the old register value */
\r
965 tmpreg1 = ADCx->SQR1;
\r
966 /* Calculate the mask to clear */
\r
967 tmpreg2 = SQR1_SQ_SET << (5 * (Rank - 25));
\r
968 /* Clear the old SQx bits for the selected rank */
\r
969 tmpreg1 &= ~tmpreg2;
\r
970 /* Calculate the mask to set */
\r
971 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 25));
\r
972 /* Set the SQx bits for the selected rank */
\r
973 tmpreg1 |= tmpreg2;
\r
974 /* Store the new register value */
\r
975 ADCx->SQR1 = tmpreg1;
\r
980 * @brief Enables the selected ADC software start conversion of the regular channels.
\r
981 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
984 void ADC_SoftwareStartConv(ADC_TypeDef* ADCx)
\r
986 /* Check the parameters */
\r
987 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
989 /* Enable the selected ADC conversion for regular group */
\r
990 ADCx->CR2 |= (uint32_t)ADC_CR2_SWSTART;
\r
994 * @brief Gets the selected ADC Software start regular conversion Status.
\r
995 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
996 * @retval The new state of ADC software start conversion (SET or RESET).
\r
998 FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx)
\r
1000 FlagStatus bitstatus = RESET;
\r
1002 /* Check the parameters */
\r
1003 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1005 /* Check the status of SWSTART bit */
\r
1006 if ((ADCx->CR2 & ADC_CR2_SWSTART) != (uint32_t)RESET)
\r
1008 /* SWSTART bit is set */
\r
1013 /* SWSTART bit is reset */
\r
1014 bitstatus = RESET;
\r
1016 /* Return the SWSTART bit status */
\r
1021 * @brief Enables or disables the EOC on each regular channel conversion.
\r
1022 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1023 * @param NewState: new state of the selected ADC EOC flag rising
\r
1024 * This parameter can be: ENABLE or DISABLE.
\r
1027 void ADC_EOCOnEachRegularChannelCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
1029 /* Check the parameters */
\r
1030 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1031 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1033 if (NewState != DISABLE)
\r
1035 /* Enable the selected ADC EOC rising on each regular channel conversion */
\r
1036 ADCx->CR2 |= ADC_CR2_EOCS;
\r
1040 /* Disable the selected ADC EOC rising on each regular channel conversion */
\r
1041 ADCx->CR2 &= (uint32_t)~ADC_CR2_EOCS;
\r
1046 * @brief Enables or disables the ADC continuous conversion mode.
\r
1047 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1048 * @param NewState: new state of the selected ADC continuous conversion mode.
\r
1049 * This parameter can be: ENABLE or DISABLE.
\r
1052 void ADC_ContinuousModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
1054 /* Check the parameters */
\r
1055 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1056 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1058 if (NewState != DISABLE)
\r
1060 /* Enable the selected ADC continuous conversion mode */
\r
1061 ADCx->CR2 |= (uint32_t)ADC_CR2_CONT;
\r
1065 /* Disable the selected ADC continuous conversion mode */
\r
1066 ADCx->CR2 &= (uint32_t)(~ADC_CR2_CONT);
\r
1071 * @brief Configures the discontinuous mode for the selected ADC regular
\r
1073 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1074 * @param Number: specifies the discontinuous mode regular channel count value.
\r
1075 * This number must be between 1 and 8.
\r
1078 void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number)
\r
1080 uint32_t tmpreg1 = 0;
\r
1081 uint32_t tmpreg2 = 0;
\r
1083 /* Check the parameters */
\r
1084 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1085 assert_param(IS_ADC_REGULAR_DISC_NUMBER(Number));
\r
1087 /* Get the old register value */
\r
1088 tmpreg1 = ADCx->CR1;
\r
1089 /* Clear the old discontinuous mode channel count */
\r
1090 tmpreg1 &= CR1_DISCNUM_RESET;
\r
1091 /* Set the discontinuous mode channel count */
\r
1092 tmpreg2 = Number - 1;
\r
1093 tmpreg1 |= tmpreg2 << 13;
\r
1094 /* Store the new register value */
\r
1095 ADCx->CR1 = tmpreg1;
\r
1099 * @brief Enables or disables the discontinuous mode on regular group
\r
1100 * channel for the specified ADC.
\r
1101 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1102 * @param NewState: new state of the selected ADC discontinuous mode on regular
\r
1104 * This parameter can be: ENABLE or DISABLE.
\r
1107 void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
1109 /* Check the parameters */
\r
1110 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1111 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1113 if (NewState != DISABLE)
\r
1115 /* Enable the selected ADC regular discontinuous mode */
\r
1116 ADCx->CR1 |= (uint32_t)ADC_CR1_DISCEN;
\r
1120 /* Disable the selected ADC regular discontinuous mode */
\r
1121 ADCx->CR1 &= (uint32_t)(~ADC_CR1_DISCEN);
\r
1126 * @brief Returns the last ADCx conversion result data for regular channel.
\r
1127 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1128 * @retval The Data conversion value.
\r
1130 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)
\r
1132 /* Check the parameters */
\r
1133 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1135 /* Return the selected ADC conversion value */
\r
1136 return (uint16_t) ADCx->DR;
\r
1143 /** @defgroup ADC_Group6 Regular Channels DMA Configuration functions
\r
1144 * @brief Regular Channels DMA Configuration functions.
\r
1147 ===============================================================================
\r
1148 ##### Regular Channels DMA Configuration functions #####
\r
1149 ===============================================================================
\r
1150 [..] This section provides functions allowing to configure the DMA for ADC regular
\r
1151 channels.Since converted regular channel values are stored into a unique
\r
1152 data register, it is useful to use DMA for conversion of more than one
\r
1153 regular channel. This avoids the loss of the data already stored in the
\r
1154 ADC Data register.
\r
1155 When the DMA mode is enabled (using the ADC_DMACmd() function), after each
\r
1156 conversion of a regular channel, a DMA request is generated.
\r
1157 [..] Depending on the "DMA disable selection" configuration (using the
\r
1158 ADC_DMARequestAfterLastTransferCmd() function), at the end of the last DMA
\r
1159 transfer, two possibilities are allowed:
\r
1160 (+) No new DMA request is issued to the DMA controller (feature DISABLED).
\r
1161 (+) Requests can continue to be generated (feature ENABLED).
\r
1168 * @brief Enables or disables the specified ADC DMA request.
\r
1169 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1170 * @param NewState: new state of the selected ADC DMA transfer.
\r
1171 * This parameter can be: ENABLE or DISABLE.
\r
1174 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
1176 /* Check the parameters */
\r
1177 assert_param(IS_ADC_DMA_PERIPH(ADCx));
\r
1178 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1180 if (NewState != DISABLE)
\r
1182 /* Enable the selected ADC DMA request */
\r
1183 ADCx->CR2 |= (uint32_t)ADC_CR2_DMA;
\r
1187 /* Disable the selected ADC DMA request */
\r
1188 ADCx->CR2 &= (uint32_t)(~ADC_CR2_DMA);
\r
1194 * @brief Enables or disables the ADC DMA request after last transfer (Single-ADC mode).
\r
1195 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1196 * @param NewState: new state of the selected ADC EOC flag rising
\r
1197 * This parameter can be: ENABLE or DISABLE.
\r
1200 void ADC_DMARequestAfterLastTransferCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
1202 /* Check the parameters */
\r
1203 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1204 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1206 if (NewState != DISABLE)
\r
1208 /* Enable the selected ADC DMA request after last transfer */
\r
1209 ADCx->CR2 |= ADC_CR2_DDS;
\r
1213 /* Disable the selected ADC DMA request after last transfer */
\r
1214 ADCx->CR2 &= (uint32_t)~ADC_CR2_DDS;
\r
1222 /** @defgroup ADC_Group7 Injected channels Configuration functions
\r
1223 * @brief Injected channels Configuration functions.
\r
1226 ===============================================================================
\r
1227 ##### Injected channels Configuration functions #####
\r
1228 ===============================================================================
\r
1229 [..] This section provide functions allowing to configure the ADC Injected channels,
\r
1230 it is composed of 2 sub sections :
\r
1231 (#) Configuration functions for Injected channels: This subsection provides
\r
1232 functions allowing to configure the ADC injected channels :
\r
1233 (++) Configure the rank in the injected group sequencer for each channel.
\r
1234 (++) Configure the sampling time for each channel.
\r
1235 (++) Activate the Auto injected Mode.
\r
1236 (++) Activate the Discontinuous Mode.
\r
1237 (++) scan mode activation.
\r
1238 (++) External/software trigger source.
\r
1239 (++) External trigger edge.
\r
1240 (++) injected channels sequencer.
\r
1242 (#) Get the Specified Injected channel conversion data: This subsection
\r
1243 provides an important function in the ADC peripheral since it returns
\r
1244 the converted data of the specific injected channel.
\r
1251 * @brief Configures for the selected ADC injected channel its corresponding
\r
1252 * rank in the sequencer and its sample time.
\r
1253 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1254 * @param ADC_Channel: the ADC channel to configure.
\r
1255 * This parameter can be one of the following values:
\r
1256 * @arg ADC_Channel_0: ADC Channel0 selected
\r
1257 * @arg ADC_Channel_1: ADC Channel1 selected
\r
1258 * @arg ADC_Channel_2: ADC Channel2 selected
\r
1259 * @arg ADC_Channel_3: ADC Channel3 selected
\r
1260 * @arg ADC_Channel_4: ADC Channel4 selected
\r
1261 * @arg ADC_Channel_5: ADC Channel5 selected
\r
1262 * @arg ADC_Channel_6: ADC Channel6 selected
\r
1263 * @arg ADC_Channel_7: ADC Channel7 selected
\r
1264 * @arg ADC_Channel_8: ADC Channel8 selected
\r
1265 * @arg ADC_Channel_9: ADC Channel9 selected
\r
1266 * @arg ADC_Channel_10: ADC Channel10 selected
\r
1267 * @arg ADC_Channel_11: ADC Channel11 selected
\r
1268 * @arg ADC_Channel_12: ADC Channel12 selected
\r
1269 * @arg ADC_Channel_13: ADC Channel13 selected
\r
1270 * @arg ADC_Channel_14: ADC Channel14 selected
\r
1271 * @arg ADC_Channel_15: ADC Channel15 selected
\r
1272 * @arg ADC_Channel_16: ADC Channel16 selected
\r
1273 * @arg ADC_Channel_17: ADC Channel17 selected
\r
1274 * @arg ADC_Channel_18: ADC Channel18 selected
\r
1275 * @arg ADC_Channel_19: ADC Channel19 selected
\r
1276 * @arg ADC_Channel_20: ADC Channel20 selected
\r
1277 * @arg ADC_Channel_21: ADC Channel21 selected
\r
1278 * @arg ADC_Channel_22: ADC Channel22 selected
\r
1279 * @arg ADC_Channel_23: ADC Channel23 selected
\r
1280 * @arg ADC_Channel_24: ADC Channel24 selected
\r
1281 * @arg ADC_Channel_25: ADC Channel25 selected
\r
1282 * @arg ADC_Channel_27: ADC Channel27 selected
\r
1283 * @arg ADC_Channel_28: ADC Channel28 selected
\r
1284 * @arg ADC_Channel_29: ADC Channel29 selected
\r
1285 * @arg ADC_Channel_30: ADC Channel30 selected
\r
1286 * @arg ADC_Channel_31: ADC Channel31 selected
\r
1287 * @arg ADC_Channel_0b: ADC Channel0b selected
\r
1288 * @arg ADC_Channel_1b: ADC Channel1b selected
\r
1289 * @arg ADC_Channel_2b: ADC Channel2b selected
\r
1290 * @arg ADC_Channel_3b: ADC Channel3b selected
\r
1291 * @arg ADC_Channel_6b: ADC Channel6b selected
\r
1292 * @arg ADC_Channel_7b: ADC Channel7b selected
\r
1293 * @arg ADC_Channel_8b: ADC Channel8b selected
\r
1294 * @arg ADC_Channel_9b: ADC Channel9b selected
\r
1295 * @arg ADC_Channel_10b: ADC Channel10b selected
\r
1296 * @arg ADC_Channel_11b: ADC Channel11b selected
\r
1297 * @arg ADC_Channel_12b: ADC Channel12b selected
\r
1298 * @param Rank: The rank in the injected group sequencer. This parameter
\r
1299 * must be between 1 to 4.
\r
1300 * @param ADC_SampleTime: The sample time value to be set for the selected
\r
1301 * channel. This parameter can be one of the following values:
\r
1302 * @arg ADC_SampleTime_4Cycles: Sample time equal to 4 cycles
\r
1303 * @arg ADC_SampleTime_9Cycles: Sample time equal to 9 cycles
\r
1304 * @arg ADC_SampleTime_16Cycles: Sample time equal to 16 cycles
\r
1305 * @arg ADC_SampleTime_24Cycles: Sample time equal to 24 cycles
\r
1306 * @arg ADC_SampleTime_48Cycles: Sample time equal to 48 cycles
\r
1307 * @arg ADC_SampleTime_96Cycles: Sample time equal to 96 cycles
\r
1308 * @arg ADC_SampleTime_192Cycles: Sample time equal to 192 cycles
\r
1309 * @arg ADC_SampleTime_384Cycles: Sample time equal to 384 cycles
\r
1312 void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
\r
1314 uint32_t tmpreg1 = 0, tmpreg2 = 0, tmpreg3 = 0;
\r
1316 /* Check the parameters */
\r
1317 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1318 assert_param(IS_ADC_CHANNEL(ADC_Channel));
\r
1319 assert_param(IS_ADC_INJECTED_RANK(Rank));
\r
1320 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
\r
1322 /* If ADC_Channel_30 or ADC_Channel_31 is selected */
\r
1323 if (ADC_Channel > ADC_Channel_29)
\r
1325 /* Get the old register value */
\r
1326 tmpreg1 = ADCx->SMPR0;
\r
1327 /* Calculate the mask to clear */
\r
1328 tmpreg2 = SMPR0_SMP_SET << (3 * (ADC_Channel - 30));
\r
1329 /* Clear the old sample time */
\r
1330 tmpreg1 &= ~tmpreg2;
\r
1331 /* Calculate the mask to set */
\r
1332 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 30));
\r
1333 /* Set the new sample time */
\r
1334 tmpreg1 |= tmpreg2;
\r
1335 /* Store the new register value */
\r
1336 ADCx->SMPR0 = tmpreg1;
\r
1338 /* If ADC_Channel_20 ... ADC_Channel_29 is selected */
\r
1339 else if (ADC_Channel > ADC_Channel_19)
\r
1341 /* Get the old register value */
\r
1342 tmpreg1 = ADCx->SMPR1;
\r
1343 /* Calculate the mask to clear */
\r
1344 tmpreg2 = SMPR1_SMP_SET << (3 * (ADC_Channel - 20));
\r
1345 /* Clear the old sample time */
\r
1346 tmpreg1 &= ~tmpreg2;
\r
1347 /* Calculate the mask to set */
\r
1348 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 20));
\r
1349 /* Set the new sample time */
\r
1350 tmpreg1 |= tmpreg2;
\r
1351 /* Store the new register value */
\r
1352 ADCx->SMPR1 = tmpreg1;
\r
1354 /* If ADC_Channel_10 ... ADC_Channel_19 is selected */
\r
1355 else if (ADC_Channel > ADC_Channel_9)
\r
1357 /* Get the old register value */
\r
1358 tmpreg1 = ADCx->SMPR2;
\r
1359 /* Calculate the mask to clear */
\r
1360 tmpreg2 = SMPR2_SMP_SET << (3 * (ADC_Channel - 10));
\r
1361 /* Clear the old sample time */
\r
1362 tmpreg1 &= ~tmpreg2;
\r
1363 /* Calculate the mask to set */
\r
1364 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
\r
1365 /* Set the new sample time */
\r
1366 tmpreg1 |= tmpreg2;
\r
1367 /* Store the new register value */
\r
1368 ADCx->SMPR2 = tmpreg1;
\r
1370 else /* ADC_Channel include in ADC_Channel_[0..9] */
\r
1372 /* Get the old register value */
\r
1373 tmpreg1 = ADCx->SMPR3;
\r
1374 /* Calculate the mask to clear */
\r
1375 tmpreg2 = SMPR3_SMP_SET << (3 * ADC_Channel);
\r
1376 /* Clear the old sample time */
\r
1377 tmpreg1 &= ~tmpreg2;
\r
1378 /* Calculate the mask to set */
\r
1379 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
\r
1380 /* Set the new sample time */
\r
1381 tmpreg1 |= tmpreg2;
\r
1382 /* Store the new register value */
\r
1383 ADCx->SMPR3 = tmpreg1;
\r
1386 /* Rank configuration */
\r
1387 /* Get the old register value */
\r
1388 tmpreg1 = ADCx->JSQR;
\r
1389 /* Get JL value: Number = JL+1 */
\r
1390 tmpreg3 = (tmpreg1 & JSQR_JL_SET)>> 20;
\r
1391 /* Calculate the mask to clear: ((Rank-1)+(4- (JL+1))) */
\r
1392 tmpreg2 = (uint32_t)(JSQR_JSQ_SET << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1))));
\r
1393 /* Clear the old JSQx bits for the selected rank */
\r
1394 tmpreg1 &= ~tmpreg2;
\r
1395 /* Calculate the mask to set: ((Rank-1)+(4- (JL+1))) */
\r
1396 tmpreg2 = (uint32_t)(((uint32_t)(ADC_Channel)) << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1))));
\r
1397 /* Set the JSQx bits for the selected rank */
\r
1398 tmpreg1 |= tmpreg2;
\r
1399 /* Store the new register value */
\r
1400 ADCx->JSQR = tmpreg1;
\r
1404 * @brief Configures the sequencer length for injected channels.
\r
1405 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1406 * @param Length: The sequencer length.
\r
1407 * This parameter must be a number between 1 to 4.
\r
1410 void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length)
\r
1412 uint32_t tmpreg1 = 0;
\r
1413 uint32_t tmpreg2 = 0;
\r
1415 /* Check the parameters */
\r
1416 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1417 assert_param(IS_ADC_INJECTED_LENGTH(Length));
\r
1419 /* Get the old register value */
\r
1420 tmpreg1 = ADCx->JSQR;
\r
1421 /* Clear the old injected sequence length JL bits */
\r
1422 tmpreg1 &= JSQR_JL_RESET;
\r
1423 /* Set the injected sequence length JL bits */
\r
1424 tmpreg2 = Length - 1;
\r
1425 tmpreg1 |= tmpreg2 << 20;
\r
1426 /* Store the new register value */
\r
1427 ADCx->JSQR = tmpreg1;
\r
1431 * @brief Set the injected channels conversion value offset.
\r
1432 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1433 * @param ADC_InjectedChannel: the ADC injected channel to set its offset.
\r
1434 * This parameter can be one of the following values:
\r
1435 * @arg ADC_InjectedChannel_1: Injected Channel1 selected.
\r
1436 * @arg ADC_InjectedChannel_2: Injected Channel2 selected.
\r
1437 * @arg ADC_InjectedChannel_3: Injected Channel3 selected.
\r
1438 * @arg ADC_InjectedChannel_4: Injected Channel4 selected.
\r
1439 * @param Offset: the offset value for the selected ADC injected channel
\r
1440 * This parameter must be a 12bit value.
\r
1443 void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset)
\r
1445 __IO uint32_t tmp = 0;
\r
1447 /* Check the parameters */
\r
1448 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1449 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
\r
1450 assert_param(IS_ADC_OFFSET(Offset));
\r
1452 tmp = (uint32_t)ADCx;
\r
1453 tmp += ADC_InjectedChannel;
\r
1455 /* Set the selected injected channel data offset */
\r
1456 *(__IO uint32_t *) tmp = (uint32_t)Offset;
\r
1460 * @brief Configures the ADCx external trigger for injected channels conversion.
\r
1461 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1462 * @param ADC_ExternalTrigInjecConv: specifies the ADC trigger to start injected
\r
1463 * conversion. This parameter can be one of the following values:
\r
1464 * @arg ADC_ExternalTrigInjecConv_T9_CC1: Timer9 capture compare1 selected
\r
1465 * @arg ADC_ExternalTrigInjecConv_T9_TRGO: Timer9 TRGO event selected
\r
1466 * @arg ADC_ExternalTrigInjecConv_T2_TRGO: Timer2 TRGO event selected
\r
1467 * @arg ADC_ExternalTrigInjecConv_T2_CC1: Timer2 capture compare1 selected
\r
1468 * @arg ADC_ExternalTrigInjecConv_T3_CC4: Timer3 capture compare4 selected
\r
1469 * @arg ADC_ExternalTrigInjecConv_T4_TRGO: Timer4 TRGO event selected
\r
1470 * @arg ADC_ExternalTrigInjecConv_T4_CC1: Timer4 capture compare1 selected
\r
1471 * @arg ADC_ExternalTrigInjecConv_T4_CC2: Timer4 capture compare2 selected
\r
1472 * @arg ADC_ExternalTrigInjecConv_T4_CC3: Timer4 capture compare3 selected
\r
1473 * @arg ADC_ExternalTrigInjecConv_T10_CC1: Timer10 capture compare1 selected
\r
1474 * @arg ADC_ExternalTrigInjecConv_T7_TRGO: Timer7 TRGO event selected
\r
1475 * @arg ADC_ExternalTrigInjecConv_Ext_IT15: External interrupt line 15 event selected
\r
1478 void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv)
\r
1480 uint32_t tmpreg = 0;
\r
1482 /* Check the parameters */
\r
1483 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1484 assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv));
\r
1486 /* Get the old register value */
\r
1487 tmpreg = ADCx->CR2;
\r
1488 /* Clear the old external event selection for injected group */
\r
1489 tmpreg &= CR2_JEXTSEL_RESET;
\r
1490 /* Set the external event selection for injected group */
\r
1491 tmpreg |= ADC_ExternalTrigInjecConv;
\r
1492 /* Store the new register value */
\r
1493 ADCx->CR2 = tmpreg;
\r
1497 * @brief Configures the ADCx external trigger edge for injected channels conversion.
\r
1498 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1499 * @param ADC_ExternalTrigInjecConvEdge: specifies the ADC external trigger
\r
1500 * edge to start injected conversion.
\r
1501 * This parameter can be one of the following values:
\r
1502 * @arg ADC_ExternalTrigConvEdge_None: external trigger disabled for
\r
1503 * injected conversion.
\r
1504 * @arg ADC_ExternalTrigConvEdge_Rising: detection on rising edge
\r
1505 * @arg ADC_ExternalTrigConvEdge_Falling: detection on falling edge
\r
1506 * @arg ADC_ExternalTrigConvEdge_RisingFalling: detection on
\r
1507 * both rising and falling edge
\r
1510 void ADC_ExternalTrigInjectedConvEdgeConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConvEdge)
\r
1512 uint32_t tmpreg = 0;
\r
1514 /* Check the parameters */
\r
1515 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1516 assert_param(IS_ADC_EXT_INJEC_TRIG_EDGE(ADC_ExternalTrigInjecConvEdge));
\r
1518 /* Get the old register value */
\r
1519 tmpreg = ADCx->CR2;
\r
1520 /* Clear the old external trigger edge for injected group */
\r
1521 tmpreg &= CR2_JEXTEN_RESET;
\r
1522 /* Set the new external trigger edge for injected group */
\r
1523 tmpreg |= ADC_ExternalTrigInjecConvEdge;
\r
1524 /* Store the new register value */
\r
1525 ADCx->CR2 = tmpreg;
\r
1529 * @brief Enables the selected ADC software start conversion of the injected
\r
1531 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1534 void ADC_SoftwareStartInjectedConv(ADC_TypeDef* ADCx)
\r
1536 /* Check the parameters */
\r
1537 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1538 /* Enable the selected ADC conversion for injected group */
\r
1539 ADCx->CR2 |= (uint32_t)ADC_CR2_JSWSTART;
\r
1543 * @brief Gets the selected ADC Software start injected conversion Status.
\r
1544 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1545 * @retval The new state of ADC software start injected conversion (SET or RESET).
\r
1547 FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx)
\r
1549 FlagStatus bitstatus = RESET;
\r
1551 /* Check the parameters */
\r
1552 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1554 /* Check the status of JSWSTART bit */
\r
1555 if ((ADCx->CR2 & ADC_CR2_JSWSTART) != (uint32_t)RESET)
\r
1557 /* JSWSTART bit is set */
\r
1562 /* JSWSTART bit is reset */
\r
1563 bitstatus = RESET;
\r
1565 /* Return the JSWSTART bit status */
\r
1570 * @brief Enables or disables the selected ADC automatic injected group
\r
1571 * conversion after regular one.
\r
1572 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1573 * @param NewState: new state of the selected ADC auto injected
\r
1575 * This parameter can be: ENABLE or DISABLE.
\r
1578 void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
1580 /* Check the parameters */
\r
1581 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1582 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1584 if (NewState != DISABLE)
\r
1586 /* Enable the selected ADC automatic injected group conversion */
\r
1587 ADCx->CR1 |= (uint32_t)ADC_CR1_JAUTO;
\r
1591 /* Disable the selected ADC automatic injected group conversion */
\r
1592 ADCx->CR1 &= (uint32_t)(~ADC_CR1_JAUTO);
\r
1597 * @brief Enables or disables the discontinuous mode for injected group
\r
1598 * channel for the specified ADC.
\r
1599 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1600 * @param NewState: new state of the selected ADC discontinuous mode
\r
1601 * on injected group channel. This parameter can be: ENABLE or DISABLE.
\r
1604 void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
\r
1606 /* Check the parameters */
\r
1607 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1608 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1610 if (NewState != DISABLE)
\r
1612 /* Enable the selected ADC injected discontinuous mode */
\r
1613 ADCx->CR1 |= (uint32_t)ADC_CR1_JDISCEN;
\r
1617 /* Disable the selected ADC injected discontinuous mode */
\r
1618 ADCx->CR1 &= (uint32_t)(~ADC_CR1_JDISCEN);
\r
1623 * @brief Returns the ADC injected channel conversion result.
\r
1624 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1625 * @param ADC_InjectedChannel: the converted ADC injected channel.
\r
1626 * This parameter can be one of the following values:
\r
1627 * @arg ADC_InjectedChannel_1: Injected Channel1 selected
\r
1628 * @arg ADC_InjectedChannel_2: Injected Channel2 selected
\r
1629 * @arg ADC_InjectedChannel_3: Injected Channel3 selected
\r
1630 * @arg ADC_InjectedChannel_4: Injected Channel4 selected
\r
1631 * @retval The Data conversion value.
\r
1633 uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel)
\r
1635 __IO uint32_t tmp = 0;
\r
1637 /* Check the parameters */
\r
1638 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1639 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
\r
1641 tmp = (uint32_t)ADCx;
\r
1642 tmp += ADC_InjectedChannel + JDR_OFFSET;
\r
1644 /* Returns the selected injected channel conversion data value */
\r
1645 return (uint16_t) (*(__IO uint32_t*) tmp);
\r
1652 /** @defgroup ADC_Group8 Interrupts and flags management functions
\r
1653 * @brief Interrupts and flags management functions.
\r
1656 ===============================================================================
\r
1657 ##### Interrupts and flags management functions #####
\r
1658 ===============================================================================
\r
1659 [..] This section provides functions allowing to configure the ADC Interrupts
\r
1660 and get the status and clear flags and Interrupts pending bits.
\r
1662 [..] The ADC provide 4 Interrupts sources and 9 Flags which can be divided into
\r
1664 *** Flags and Interrupts for ADC regular channels ***
\r
1665 =====================================================
\r
1668 (##) ADC_FLAG_OVR : Overrun detection when regular converted data are
\r
1670 (##) ADC_FLAG_EOC : Regular channel end of conversion + to indicate
\r
1671 (depending on EOCS bit, managed by ADC_EOCOnEachRegularChannelCmd() )
\r
1673 (+++) a regular CHANNEL conversion.
\r
1674 (+++) sequence of regular GROUP conversions.
\r
1677 (##) ADC_FLAG_STRT: Regular channel start + to indicate when regular
\r
1678 CHANNEL conversion starts.
\r
1679 (##) ADC_FLAG_RCNR: Regular channel not ready + to indicate if a new
\r
1680 regular conversion can be launched.
\r
1682 (##) ADC_IT_OVR : specifies the interrupt source for Overrun detection
\r
1684 (##) ADC_IT_EOC : specifies the interrupt source for Regular channel
\r
1685 end of conversion event.
\r
1687 *** Flags and Interrupts for ADC Injected channels ***
\r
1688 ======================================================
\r
1690 (##) ADC_FLAG_JEOC : Injected channel end of conversion+ to indicate at
\r
1691 the end of injected GROUP conversion.
\r
1692 (##) ADC_FLAG_JSTRT: Injected channel start + to indicate hardware when
\r
1693 injected GROUP conversion starts.
\r
1694 (##) ADC_FLAG_JCNR: Injected channel not ready + to indicate if a new
\r
1695 injected conversion can be launched.
\r
1697 (##) ADC_IT_JEOC : specifies the interrupt source for Injected channel
\r
1698 end of conversion event.
\r
1699 *** General Flags and Interrupts for the ADC ***
\r
1700 ================================================
\r
1702 (##) ADC_FLAG_AWD: Analog watchdog + to indicate if the converted voltage
\r
1703 crosses the programmed thresholds values.
\r
1704 (##) ADC_FLAG_ADONS: ADC ON status + to indicate if the ADC is ready
\r
1707 (##) ADC_IT_AWD : specifies the interrupt source for Analog watchdog
\r
1710 [..] The user should identify which mode will be used in his application to
\r
1711 manage the ADC controller events: Polling mode or Interrupt mode.
\r
1713 [..] In the Polling Mode it is advised to use the following functions:
\r
1714 (+) ADC_GetFlagStatus() : to check if flags events occur.
\r
1715 (+) ADC_ClearFlag() : to clear the flags events.
\r
1717 [..] In the Interrupt Mode it is advised to use the following functions:
\r
1718 (+) ADC_ITConfig() : to enable or disable the interrupt source.
\r
1719 (+) ADC_GetITStatus() : to check if Interrupt occurs.
\r
1720 (+) ADC_ClearITPendingBit() : to clear the Interrupt pending Bit
\r
1721 (corresponding Flag).
\r
1727 * @brief Enables or disables the specified ADC interrupts.
\r
1728 * @param ADCx: where x can be 1 to select the ADC peripheral.
\r
1729 * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
\r
1730 * This parameter can be one of the following values:
\r
1731 * @arg ADC_IT_EOC: End of conversion interrupt
\r
1732 * @arg ADC_IT_AWD: Analog watchdog interrupt
\r
1733 * @arg ADC_IT_JEOC: End of injected conversion interrupt
\r
1734 * @arg ADC_IT_OVR: overrun interrupt
\r
1735 * @param NewState: new state of the specified ADC interrupts.
\r
1736 * This parameter can be: ENABLE or DISABLE.
\r
1739 void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState)
\r
1741 uint32_t itmask = 0;
\r
1743 /* Check the parameters */
\r
1744 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1745 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
1746 assert_param(IS_ADC_IT(ADC_IT));
\r
1748 /* Get the ADC IT index */
\r
1749 itmask = (uint8_t)ADC_IT;
\r
1750 itmask = (uint32_t)0x01 << itmask;
\r
1752 if (NewState != DISABLE)
\r
1754 /* Enable the selected ADC interrupts */
\r
1755 ADCx->CR1 |= itmask;
\r
1759 /* Disable the selected ADC interrupts */
\r
1760 ADCx->CR1 &= (~(uint32_t)itmask);
\r
1765 * @brief Checks whether the specified ADC flag is set or not.
\r
1766 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1767 * @param ADC_FLAG: specifies the flag to check.
\r
1768 * This parameter can be one of the following values:
\r
1769 * @arg ADC_FLAG_AWD: Analog watchdog flag
\r
1770 * @arg ADC_FLAG_EOC: End of conversion flag
\r
1771 * @arg ADC_FLAG_JEOC: End of injected group conversion flag
\r
1772 * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
\r
1773 * @arg ADC_FLAG_STRT: Start of regular group conversion flag
\r
1774 * @arg ADC_FLAG_OVR: Overrun flag
\r
1775 * @arg ADC_FLAG_ADONS: ADC ON status
\r
1776 * @arg ADC_FLAG_RCNR: Regular channel not ready
\r
1777 * @arg ADC_FLAG_JCNR: Injected channel not ready
\r
1778 * @retval The new state of ADC_FLAG (SET or RESET).
\r
1780 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint16_t ADC_FLAG)
\r
1782 FlagStatus bitstatus = RESET;
\r
1784 /* Check the parameters */
\r
1785 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1786 assert_param(IS_ADC_GET_FLAG(ADC_FLAG));
\r
1788 /* Check the status of the specified ADC flag */
\r
1789 if ((ADCx->SR & ADC_FLAG) != (uint8_t)RESET)
\r
1791 /* ADC_FLAG is set */
\r
1796 /* ADC_FLAG is reset */
\r
1797 bitstatus = RESET;
\r
1799 /* Return the ADC_FLAG status */
\r
1804 * @brief Clears the ADCx's pending flags.
\r
1805 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1806 * @param ADC_FLAG: specifies the flag to clear.
\r
1807 * This parameter can be any combination of the following values:
\r
1808 * @arg ADC_FLAG_AWD: Analog watchdog flag
\r
1809 * @arg ADC_FLAG_EOC: End of conversion flag
\r
1810 * @arg ADC_FLAG_JEOC: End of injected group conversion flag
\r
1811 * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
\r
1812 * @arg ADC_FLAG_STRT: Start of regular group conversion flag
\r
1813 * @arg ADC_FLAG_OVR: overrun flag
\r
1816 void ADC_ClearFlag(ADC_TypeDef* ADCx, uint16_t ADC_FLAG)
\r
1818 /* Check the parameters */
\r
1819 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1820 assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG));
\r
1822 /* Clear the selected ADC flags */
\r
1823 ADCx->SR = ~(uint32_t)ADC_FLAG;
\r
1827 * @brief Checks whether the specified ADC interrupt has occurred or not.
\r
1828 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1829 * @param ADC_IT: specifies the ADC interrupt source to check.
\r
1830 * This parameter can be one of the following values:
\r
1831 * @arg ADC_IT_EOC: End of conversion interrupt
\r
1832 * @arg ADC_IT_AWD: Analog watchdog interrupt
\r
1833 * @arg ADC_IT_JEOC: End of injected conversion interrupt
\r
1834 * @arg ADC_IT_OVR: Overrun interrupt
\r
1835 * @retval The new state of ADC_IT (SET or RESET).
\r
1837 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT)
\r
1839 ITStatus bitstatus = RESET;
\r
1840 uint32_t itmask = 0, enablestatus = 0;
\r
1842 /* Check the parameters */
\r
1843 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1844 assert_param(IS_ADC_IT(ADC_IT));
\r
1846 /* Get the ADC IT index */
\r
1847 itmask = (uint32_t)((uint32_t)ADC_IT >> 8);
\r
1849 /* Get the ADC_IT enable bit status */
\r
1850 enablestatus = (ADCx->CR1 & ((uint32_t)0x01 << (uint8_t)ADC_IT));
\r
1852 /* Check the status of the specified ADC interrupt */
\r
1853 if (((uint32_t)(ADCx->SR & (uint32_t)itmask) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
\r
1855 /* ADC_IT is set */
\r
1860 /* ADC_IT is reset */
\r
1861 bitstatus = RESET;
\r
1863 /* Return the ADC_IT status */
\r
1868 * @brief Clears the ADCx's interrupt pending bits.
\r
1869 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
\r
1870 * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
\r
1871 * This parameter can be one of the following values:
\r
1872 * @arg ADC_IT_EOC: End of conversion interrupt
\r
1873 * @arg ADC_IT_AWD: Analog watchdog interrupt
\r
1874 * @arg ADC_IT_JEOC: End of injected conversion interrupt
\r
1875 * @arg ADC_IT_OVR: Overrun interrupt
\r
1878 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT)
\r
1880 uint8_t itmask = 0;
\r
1882 /* Check the parameters */
\r
1883 assert_param(IS_ADC_ALL_PERIPH(ADCx));
\r
1884 assert_param(IS_ADC_IT(ADC_IT));
\r
1886 /* Get the ADC IT index */
\r
1887 itmask = (uint8_t)(ADC_IT >> 8);
\r
1889 /* Clear the selected ADC interrupt pending bits */
\r
1890 ADCx->SR = ~(uint32_t)itmask;
\r
1909 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r