1 /******************** (C) COPYRIGHT 2006 STMicroelectronics ********************
2 * File Name : 75x_adc.c
3 * Author : MCD Application Team
4 * Date First Issued : 03/10/2006
5 * Description : This file provides all the ADC software functions.
6 ********************************************************************************
10 ********************************************************************************
11 * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
13 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
14 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
15 * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
16 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *******************************************************************************/
19 /* Includes ------------------------------------------------------------------*/
23 /* Private typedef -----------------------------------------------------------*/
24 /* Private define ------------------------------------------------------------*/
25 /* Private macro -------------------------------------------------------------*/
26 /* Private variables ---------------------------------------------------------*/
28 /* Mask for Power Down Mode */
29 #define ADC_PowerDown_Enable 0x8000
30 #define ADC_PowerDown_Disable 0x7FFF
32 /* Mask for Watchdog Thresholds Enable */
33 #define ADC_AnalogWatchdog_Enable 0x8000
34 #define ADC_AnalogWatchdog_Disable 0x7FFF
36 /* Mask for Injected conversion start */
37 #define ADC_Injec_ConversionStart 0x8000
40 #define ADC_DMA_ExtEnable_Mask 0x4000
42 /* Injected start trigger enable */
43 #define ADC_Injec_ExtTrigger_Enable 0x4000
46 #define ADC_DMAFirstEnabledChannel_Mask 0x000F
47 #define ADC_DataRegisterOffset 0x0050
48 #define ADC_FirstChannel_Mask 0xFFF0
49 #define ADC_ChannelNumber_Mask 0xFC3F
50 #define ADC_Threshold_Mask 0xFC00
51 #define ADC_AnalogWatchdogChannel_Mask 0xC3FF
52 #define ADC_Prescalers_Mask 0x7F18
53 #define ADC_SPEN_Mask 0x8000
54 #define ADC_FallingEdge_Mask 0xEFFF
55 #define ADC_LowLevel_Mask 0x4000
56 #define ADC_HighLevel_Mask 0xDFFF
57 #define ADC_Calibration_Mask 0x0002
59 /* Private function prototypes -----------------------------------------------*/
60 /* Private functions ---------------------------------------------------------*/
62 /*******************************************************************************
63 * Function Name : ADC_DeInit
64 * Description : Deinitializes the ADC peripheral registers to their default
69 *******************************************************************************/
72 /* Reset the ADC registers values*/
73 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_ADC,ENABLE);
74 MRCC_PeripheralSWResetConfig(MRCC_Peripheral_ADC,DISABLE);
77 /*******************************************************************************
78 * Function Name : ADC_Init
79 * Description : Initializes the ADC peripheral according to the specified
80 * parameters in the ADC_InitStruct.
81 * Input : - ADC_InitStruct: pointer to an ADC_InitTypeDef structure that
82 contains the configuration information for the ADC peripheral.
85 *******************************************************************************/
86 void ADC_Init(ADC_InitTypeDef* ADC_InitStruct)
88 /* Configure the conversion mode */
89 if(ADC_InitStruct->ADC_ConversionMode == ADC_ConversionMode_Scan)
91 /* Set the scan conversion mode */
92 ADC->CLR2 |= ADC_ConversionMode_Scan;
96 /* Set the one-shot conversion mode */
97 ADC->CLR2 &= ADC_ConversionMode_OneShot;
100 /* Configure the external start conversion trigger */
101 switch(ADC_InitStruct->ADC_ExtTrigger)
103 case ADC_ExtTrigger_HighLevel:
104 /* Start conversion on High level of the external trigger (TIM0) */
105 ADC->CLR0 &= ADC_HighLevel_Mask;
106 ADC->CLR0 |= ADC_ExtTrigger_HighLevel;
109 case ADC_ExtTrigger_LowLevel:
110 /* Start conversion on low level of the external trigger (TIM0) */
111 ADC->CLR0 &= ADC_ExtTrigger_LowLevel;
112 ADC->CLR0 |= ADC_LowLevel_Mask;
115 case ADC_ExtTrigger_RisingEdge:
116 /* Start conversion on rising edge of the external trigger (TIM0) */
117 ADC->CLR0 |= ADC_ExtTrigger_RisingEdge;
120 case ADC_ExtTrigger_FallingEdge:
121 /* Start conversion on falling edge of the external trigger (TIM0) */
122 ADC->CLR0 &= ADC_FallingEdge_Mask;
123 ADC->CLR0 |= ADC_ExtTrigger_FallingEdge;
126 case ADC_ExtTrigger_Disable:
127 /* Disable the external trigger and start the conversion by software */
128 ADC->CLR0 &= ADC_ExtTrigger_Disable;
135 /* Configure the auto clock off feature */
136 if (ADC_InitStruct->ADC_AutoClockOff == ADC_AutoClockOff_Enable)
138 /* Enable the auto clock off feature */
139 ADC->CLR4 |= ADC_AutoClockOff_Enable;
143 /* Disable the auto clock off feature */
144 ADC->CLR4 &= ADC_AutoClockOff_Disable;
147 /* Clear conversion prescaler CNVP[2:0], sampling prescaler SMPP[2:0] bits
148 and Sample prescaler enable SPEN bit */
149 ADC->CLR1 &= ADC_Prescalers_Mask;
150 /* Set conversion prescaler value (sampling and conversion prescalers are equal
151 while SPEN bit is reset */
152 ADC->CLR1 |= (ADC_InitStruct->ADC_ConversionPrescaler<<5);
154 /* In case ADC_SamplingPrescaler member is different from the conversion one */
155 if(ADC_InitStruct->ADC_SamplingPrescaler != ADC_InitStruct->ADC_ConversionPrescaler)
157 /* Set the sampling prescaler value */
158 ADC->CLR1 |= ADC_InitStruct->ADC_SamplingPrescaler;
159 /* Set SPEN bit (sampling and conversion prescalers are different */
160 ADC->CLR1 = (ADC->CLR1 | ADC_SPEN_Mask);
163 /* Clear first channel to be converted FCH[3:0] bits */
164 ADC->CLR2 &= ADC_FirstChannel_Mask;
165 /* Set the first channel to be converted */
166 ADC->CLR2 |= ADC_InitStruct->ADC_FirstChannel;
167 /* Clear number of channels to be converted NCH[3:0] bits */
168 ADC->CLR2 &= ADC_ChannelNumber_Mask;
169 /* Set the number of channels to be converted */
170 ADC->CLR2 |= ((ADC_InitStruct->ADC_ChannelNumber)-1<<6);
173 /*******************************************************************************
174 * Function Name : ADC_StructInit
175 * Description : Fills each ADC_InitStruct member with its default value.
176 * Input : - ADC_InitStruct: pointer to an ADC_InitTypeDef structure
177 which will be initialized.
180 *******************************************************************************/
181 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
183 /* Initialize the ADC_ConversionMode member */
184 ADC_InitStruct->ADC_ConversionMode = ADC_ConversionMode_OneShot;
186 /* Initialize the ADC_ExtTrigger member */
187 ADC_InitStruct->ADC_ExtTrigger = ADC_ExtTrigger_Disable;
189 /* Initialize the ADC_AutoClockOff member */
190 ADC_InitStruct->ADC_AutoClockOff = ADC_AutoClockOff_Disable;
192 /* Initialize the ADC_SamplingPrescaler member */
193 ADC_InitStruct->ADC_SamplingPrescaler = 0;
195 /* Initialize the ADC_ConversionPrescaler member */
196 ADC_InitStruct->ADC_ConversionPrescaler = 0;
198 /* Initialize the ADC_FirstChannel member */
199 ADC_InitStruct->ADC_FirstChannel = ADC_CHANNEL0;
201 /* Initialize the ADC_ChannelNumber member */
202 ADC_InitStruct->ADC_ChannelNumber = 1;
205 /*******************************************************************************
206 * Function Name : ADC_StartCalibration
207 * Description : Starts the ADC Calibration. Calibration average enabled/disabled.
208 * Input : - ADC_CalibAverage: Enables or disables ADC calibration average.
209 * This parameter can be one of the following values:
210 * - ADC_CalibAverage_Enable: enable calibration average
211 * - ADC_CalibAverage_Disable: disable calibration average
214 *******************************************************************************/
215 void ADC_StartCalibration(u16 ADC_CalibAverage)
217 if (ADC_CalibAverage == ADC_CalibAverage_Enable)
219 /* Enable ADC Calibration Average */
220 ADC->CLR4 &= ADC_CalibAverage_Enable;
224 /* Disable ADC Calibration Average */
225 ADC->CLR4 |= ADC_CalibAverage_Disable;
228 /* Start Calibration */
229 ADC->CLR0 |= ADC_Calibration_ON;
232 /*******************************************************************************
233 * Function Name : ADC_GetCalibrationStatus
234 * Description : Get the ADC Calibration Status.
237 * Return : The NewState of the ADC calibration (SET or RESET).
238 *******************************************************************************/
239 FlagStatus ADC_GetCalibrationStatus(void)
241 /* Check the status of the ADC calibration */
242 if((ADC->CLR0 & ADC_Calibration_Mask) != RESET)
244 /* Return SET if ADC Calibration is on going */
249 /* Return RESET if ADC Calibration is finished */
254 /*******************************************************************************
255 * Function Name : ADC_ConversionCmd
256 * Description : Starts or stops the ADC conversion.
257 * Input : - ADC_Conversion: specifies the ADC command to apply.
258 * This parameter can be one of the following values:
259 * - ADC_Conversion_Start: start conversion
260 * - ADC_Conversion_Stop: stop conversion
263 *******************************************************************************/
264 void ADC_ConversionCmd (u16 ADC_Conversion)
266 if (ADC_Conversion == ADC_Conversion_Start)
268 /* Start the ADC Conversion */
269 ADC->CLR0 |= ADC_Conversion_Start;
273 /* Stop the ADC Conversion */
274 ADC->CLR0 &= ADC_Conversion_Stop;
278 /*******************************************************************************
279 * Function Name : ADC_GetSTARTBitStatus
280 * Description : Gets the ADC START/STOP bit Status.
283 * Return : The NewState of the ADC START/STOP bit (SET or RESET).
284 *******************************************************************************/
285 FlagStatus ADC_GetSTARTBitStatus(void)
287 /* Check the status of the ADC START/STOP bit */
288 if((ADC->CLR0 & ADC_Conversion_Start) != RESET)
290 /* Return SET if ADC Conversion is started */
295 /* Return RESET if ADC Conversion is stopped */
300 /*******************************************************************************
301 * Function Name : ADC_Cmd
302 * Description : Enables the ADC peripheral or puts it in power down mode.
303 * - NewState: new state of the ADC peripheral.
304 * This parameter can be: ENABLE or DISABLE.
307 *******************************************************************************/
308 void ADC_Cmd(FunctionalState NewState)
310 if (NewState == DISABLE)
312 /* Enable ADC Power Down Mode */
313 ADC->CLR4 |= ADC_PowerDown_Enable;
317 /* Disable ADC Power Down Mode */
318 ADC->CLR4 &= ADC_PowerDown_Disable;
322 /*******************************************************************************
323 * Function Name : ADC_AutoClockOffConfig
324 * Description : Enables or disables the Auto clock off feature.
325 * - NewState: new state of the Auto clock off feature. This
326 * parameter can be: ENABLE or DISABLE.
329 *******************************************************************************/
330 void ADC_AutoClockOffConfig(FunctionalState NewState)
332 if (NewState == ENABLE)
334 /* Enable ADC Auto Clock Off */
335 ADC->CLR4 |= ADC_AutoClockOff_Enable;
339 /* Disable ADC Auto Clock Off */
340 ADC->CLR4 &= ADC_AutoClockOff_Disable;
344 /*******************************************************************************
345 * Function Name : ADC_AnalogWatchdogConfig
346 * Description : Configures the analog input channel to be used for the selected
347 * Analog Watchdog and defines its corresponding High and Low
349 * Input : - ADC_AnalogWatchdog: specifies the analog watchdog which will
350 * be affected to the desired converted channel. This parameter
351 * can be one of the following values:
352 * - ADC_AnalogWatchdog0: select analog watchdog 0
353 * - ADC_AnalogWatchdog1: select analog watchdog 1
354 * - ADC_AnalogWatchdog2: select analog watchdog 2
355 * - ADC_AnalogWatchdog3: select analog watchdog 3
356 * - ADC_CHANNEL: specifies the channel linked to the selected
357 * analog watchdog. This parameter can be ADC_CHANNELx where x
359 * - LowThreshold: Low Threshold for the selected Analog watchdog
360 * - HighThreshold: High Threshold for the selected Analog watchdog
363 *******************************************************************************/
364 void ADC_AnalogWatchdogConfig(u16 ADC_AnalogWatchdog, u8 ADC_CHANNEL,
365 u16 LowThreshold, u16 HighThreshold)
367 switch (ADC_AnalogWatchdog)
369 /* Set the selected channel and their corresponding High and Low thresholds */
370 case ADC_AnalogWatchdog0 :
371 ADC->TRA0 = (ADC->TRA0 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
372 ADC->TRA0 = (ADC->TRA0 & ADC_Threshold_Mask) | HighThreshold;
373 ADC->TRB0 = (ADC->TRB0 & ADC_Threshold_Mask) | LowThreshold;
376 case ADC_AnalogWatchdog1 :
377 ADC->TRA1 = (ADC->TRA1 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
378 ADC->TRA1 = (ADC->TRA1 & ADC_Threshold_Mask) | HighThreshold;
379 ADC->TRB1 = (ADC->TRB1 & ADC_Threshold_Mask) | LowThreshold;
382 case ADC_AnalogWatchdog2 :
383 ADC->TRA2 = (ADC->TRA2 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
384 ADC->TRA2 = (ADC->TRA2 & ADC_Threshold_Mask) | HighThreshold;
385 ADC->TRB2 = (ADC->TRB2 & ADC_Threshold_Mask) | LowThreshold;
388 case ADC_AnalogWatchdog3 :
389 ADC->TRA3 = (ADC->TRA3 & ADC_AnalogWatchdogChannel_Mask) | ((u16) ADC_CHANNEL<<10);
390 ADC->TRA3 = (ADC->TRA3 & ADC_Threshold_Mask) | HighThreshold;
391 ADC->TRB3 = (ADC->TRB3 & ADC_Threshold_Mask) | LowThreshold;
399 /*******************************************************************************
400 * Function Name : ADC_AnalogWatchdogCmd
401 * Description : Enables or disables the selected analog Watchdog.
402 * Input : - ADC_AnalogWatchdog: specifies the analog watchdog to be
403 * enabled or disabled. This parameter can be one of the
405 * - ADC_AnalogWatchdog0: select analog watchdog 0
406 * - ADC_AnalogWatchdog1: select analog watchdog 1
407 * - ADC_AnalogWatchdog2: select analog watchdog 2
408 * - ADC_AnalogWatchdog3: select analog watchdog 3
409 * - NewState: new state of the specified analog watchdog.
410 * This parameter can be: ENABLE or DISABLE.
413 *******************************************************************************/
414 void ADC_AnalogWatchdogCmd(u16 ADC_AnalogWatchdog, FunctionalState NewState)
416 if (NewState == ENABLE)
418 /* Enable the selected ADC AnalogWatchdogx */
419 switch (ADC_AnalogWatchdog)
421 case ADC_AnalogWatchdog0 :
422 ADC->TRB0 |= ADC_AnalogWatchdog_Enable;
425 case ADC_AnalogWatchdog1 :
426 ADC->TRB1 |= ADC_AnalogWatchdog_Enable;
429 case ADC_AnalogWatchdog2 :
430 ADC->TRB2 |= ADC_AnalogWatchdog_Enable;
433 case ADC_AnalogWatchdog3 :
434 ADC->TRB3 |= ADC_AnalogWatchdog_Enable;
443 /* Disable the selected ADC AnalogWatchdogx */
444 switch (ADC_AnalogWatchdog)
446 case ADC_AnalogWatchdog0 :
447 ADC->TRB0 &= ADC_AnalogWatchdog_Disable;
450 case ADC_AnalogWatchdog1 :
451 ADC->TRB1 &= ADC_AnalogWatchdog_Disable;
454 case ADC_AnalogWatchdog2 :
455 ADC->TRB2 &= ADC_AnalogWatchdog_Disable;
458 case ADC_AnalogWatchdog3 :
459 ADC->TRB3 &= ADC_AnalogWatchdog_Disable;
468 /*******************************************************************************
469 * Function Name : ADC_GetAnalogWatchdogResult
470 * Description : Returns the comparison result of the selected analog watchdog.
471 * Input : - ADC_AnalogWatchdog: specifies the analog watchdog channel
472 * which its comparison result will be returned. This parameter
473 * can be one of the following values:
474 * - ADC_AnalogWatchdog0: select analog watchdog 0
475 * - ADC_AnalogWatchdog1: select analog watchdog 1
476 * - ADC_AnalogWatchdog2: select analog watchdog 2
477 * - ADC_AnalogWatchdog3: select analog watchdog 3
479 * Return : The analog watchdog comparaison result value
480 *******************************************************************************/
481 u16 ADC_GetAnalogWatchdogResult(u16 ADC_AnalogWatchdog)
483 /* Return the selected ADC AnalogWatchdogx comparaison result */
484 switch(ADC_AnalogWatchdog)
486 case ADC_AnalogWatchdog0 :
487 return ((ADC->PBR & ADC_AnalogWatchdog)>>4);
489 case ADC_AnalogWatchdog1 :
490 return ((ADC->PBR & ADC_AnalogWatchdog)>>6);
492 case ADC_AnalogWatchdog2 :
493 return ((ADC->PBR & ADC_AnalogWatchdog)>>8);
495 case ADC_AnalogWatchdog3 :
496 return ((ADC->PBR & ADC_AnalogWatchdog)>>10);
498 default : return (0xFF); /* if a wrong value of ADC_AnalogWatchdog is selected */
502 /*******************************************************************************
503 * Function Name : ADC_InjectedConversionConfig
504 * Description : Configures the start trigger level for the injected channels
505 * and the injected analog input channels to be converted.
506 * Input : - ADC_Injec_ExtTrigger: specifies the start trigger level.
507 * This parameter can be one of the following values:
508 * - ADC_Injec_ExtTrigger_Disable : external trigger disabled
509 * - ADC_Injec_ExtTrigger_RisingEdge: external trigger
510 * configured as rising edge of PWM Timer TRGO signal
511 * - ADC_Injec_ExtTrigger_FallingEdge: external trigger
512 * configured as falling edge of PWM Timer TRGO signal
513 * - FirstChannel: specifies the first injected channel to be
515 * This parameter can be ADC_CHANNELx where x can be (0..15).
516 * - ChannelNumber: specifies the Number of the injected channels
517 * to be converted. This parameter can be a value from 1 to 16.
520 *******************************************************************************/
521 void ADC_InjectedConversionConfig(u16 ADC_Injec_ExtTrigger, u8 FirstChannel, u8 ChannelNumber)
523 /* Configure the external start injected conversion trigger */
524 switch (ADC_Injec_ExtTrigger)
526 case ADC_Injec_ExtTrigger_Disable :
527 /* Disable the external trigger and start the injected conversion by software */
528 ADC->CLR3 &= ADC_Injec_ExtTrigger_Disable ;
530 case ADC_Injec_ExtTrigger_RisingEdge :
531 /* Start injected conversion on rising edge of the external trigger (PWM) */
532 ADC->CLR3 |= ADC_Injec_ExtTrigger_RisingEdge;
534 case ADC_Injec_ExtTrigger_FallingEdge :
535 /* Start injected conversion on falling edge of the external trigger (PWM) */
536 ADC->CLR3 |= ADC_Injec_ExtTrigger_Enable;
537 ADC->CLR3 &= ADC_Injec_ExtTrigger_FallingEdge;
544 /* Clear first injected channel to be converted JFCH[3:0] bits */
545 ADC->CLR3 &= ADC_FirstChannel_Mask;
546 /* Set the first injected channel to be converted */
547 ADC->CLR3 |= FirstChannel;
548 /* Clear number of injected channels to be converted JNCH[3:0] bits */
549 ADC->CLR3 &= ADC_ChannelNumber_Mask;
550 /* Set the number of injected channels to be converted */
551 ADC->CLR3 |= ((ChannelNumber-1)<<6);
554 /*******************************************************************************
555 * Function Name : ADC_StartInjectedConversion
556 * Description : Starts by software the conversion of the injected input channels.
560 *******************************************************************************/
561 void ADC_StartInjectedConversion(void)
563 /* Start the injected ADC Conversion */
564 ADC->CLR3 |= ADC_Injec_ConversionStart;
567 /*******************************************************************************
568 * Function Name : ADC_GetConversionValue
569 * Description : Reads the conversion result from the appropriate data register.
570 * Input : - ADC_CHANNEL :specifies the ADC channel which its conversion
571 * value have to be returned. This parameter can be ADC_CHANNELx
572 * where x can be (0..15) to select channelx
574 * Return : The returned value holds the conversion result of the selected
576 *******************************************************************************/
577 u16 ADC_GetConversionValue(u8 ADC_CHANNEL)
579 /* Return the conversion result of the selected channel */
580 return *((u16 *)(ADC_BASE + ((ADC_CHANNEL<<2) + ADC_DataRegisterOffset)));
583 /*******************************************************************************
584 * Function Name : ADC_ITConfig
585 * Description : Enables or disables the specified ADC interrupts.
586 * Input : - ADC_IT: specifies the ADC interrupts to be enabled or disabled.
587 * This parameter can be any combination of the following values:
588 * - ADC_IT_ECH: End of chain conversion interrupt
589 * - ADC_IT_EOC: End of channel conversion interrupt
590 * - ADC_IT_JECH: Injected end of chain conversion interrupt
591 * - ADC_IT_JEOC: Injected end of channel conversion interrupt
592 * - ADC_IT_AnalogWatchdog0_LowThreshold:
593 * Analog Watchdog 0 LowThreshold interrupt
594 * - ADC_IT_AnalogWatchdog0_HighThreshold:
595 * Analog Watchdog 0 HighThreshold interrupt
596 * - ADC_IT_AnalogWatchdog1_LowThreshold:
597 * Analog Watchdog 1 LowThreshold interrupt
598 * - ADC_IT_AnalogWatchdog1_HighThreshold:
599 * Analog Watchdog 1 HighThreshold interrupt
600 * - ADC_IT_AnalogWatchdog2_LowThreshold:
601 * Analog Watchdog 2 LowThreshold interrupt
602 * - ADC_IT_AnalogWatchdog2_HighThreshold:
603 * Analog Watchdog 2 HighThreshold interrupt
604 * - ADC_IT_AnalogWatchdog3_LowThreshold:
605 * Analog Watchdog 3 LowThreshold interrupt
606 * - ADC_IT_AnalogWatchdog3_HighThreshold:
607 * Analog Watchdog 5 HighThreshold interrupt
608 * - ADC_IT_ALL: All interrupts
609 * - NewState: new state of the specified ADC interrupts.
610 * This parameter can be: ENABLE or DISABLE.
613 *******************************************************************************/
614 void ADC_ITConfig(u16 ADC_IT, FunctionalState NewState)
616 if (NewState == ENABLE)
618 /* Enable the selected ADC interrupts */
623 /* Disable the selected ADC interrupts */
628 /*******************************************************************************
629 * Function Name : ADC_DMAConfig
630 * Description : Configures the ADC
\92s DMA interface.
631 * Input : - ADC_DMA_CHANNEL: specifies the channels to be enabled or
632 * disabled for DMA transfer. This parameter can be any
633 * combination of ADC_DMA_CHANNELx where x can be (0..15).
634 * - NewState: new state of the specified ADC DMA channels.
635 * This parameter can be: ENABLE or DISABLE.
638 *******************************************************************************/
639 void ADC_DMAConfig(u16 ADC_DMA_CHANNEL, FunctionalState NewState)
641 if(NewState == ENABLE)
643 /* Enable DMA for the selected channels */
644 ADC->DMAR |= ADC_DMA_CHANNEL ;
648 /* Disable DMA for the selected channels */
649 ADC->DMAR &= ~ADC_DMA_CHANNEL;
653 /*******************************************************************************
654 * Function Name : ADC_DMACmd
655 * Description : Enable or disable the DMA transfer for the ADC.
656 * Input : - ADC_DMA: specifies the DMA command. This parameter can be
657 * one of the following values:
658 * - ADC_DMA_Disable: disable the DMA capability
659 * - ADC_DMA_Enable: enabled by setting the global
661 * - ADC_DMA_ExtTrigger_HighLevel: enabled by detection of
662 * high level of TIM2 OC2 signal
663 * - ADC_DMA_ExtTrigger_LowLevel: enabled by detection of
664 * low level of TIM2 OC2 signal
667 *******************************************************************************/
668 void ADC_DMACmd(u16 ADC_DMA)
670 /* Configure the DMA external trigger enable */
673 case ADC_DMA_Disable :
674 /* Disable DMA transfer */
675 ADC->DMAE &= ADC_DMA_Disable;
678 case ADC_DMA_Enable :
679 /* Enable DMA transfer */
680 ADC->DMAE |= ADC_DMA_Enable;
683 case ADC_DMA_ExtTrigger_HighLevel :
684 /* Enable DMA transfer on high level of the external trigger (TIM2) */
685 ADC->DMAE &= ADC_DMA_Disable;
686 ADC->DMAE |= ADC_DMA_ExtTrigger_HighLevel;
689 case ADC_DMA_ExtTrigger_LowLevel :
690 /* Enable DMA transfer on low level of the external trigger (TIM2) */
691 ADC->DMAE |= ADC_DMA_ExtEnable_Mask;
692 ADC->DMAE &= ADC_DMA_ExtTrigger_LowLevel;
700 /*******************************************************************************
701 * Function Name : ADC_GetDMAFirstEnabledChannel
702 * Description : Gets the first DMA-enabled channel configured at the time that
703 * DMA was last globally enabled.
706 * Return : The first DMA enabled channel
707 *******************************************************************************/
708 u16 ADC_GetDMAFirstEnabledChannel(void)
710 /* Return the DMA first enabled channel */
711 return (ADC->DMAE & ADC_DMAFirstEnabledChannel_Mask);
714 /*******************************************************************************
715 * Function Name : ADC_GetFlagStatus
716 * Description : Checks whether the specified ADC flag is set or not.
717 * Input : - ADC_FLAG: specifies the ADC flag to check. This parameter
718 * can be one of the following values:
719 * - ADC_FLAG_ECH: End of chain conversion Flag
720 * - ADC_FLAG_EOC: End of channel conversion Flag
721 * - ADC_FLAG_JECH: End of injected chain conversion Flag
722 * - ADC_FLAG_JEOC: End of injected channel conversion Flag
723 * - ADC_FLAG_AnalogWatchdog0_LowThreshold:
724 * Analog Watchdog 0 LowThreshold Flag
725 * - ADC_FLAG_AnalogWatchdog0_HighThreshold:
726 * Analog Watchdog 0 HighThreshold Flag
727 * - ADC_FLAG_AnalogWatchdog1_LowThreshold:
728 * Analog Watchdog 1 LowThreshold Flag
729 * - ADC_FLAG_AnalogWatchdog1_HighThreshold:
730 * Analog Watchdog 1 HighThreshold Flag
731 * - ADC_FLAG_AnalogWatchdog2_LowThreshold:
732 * Analog Watchdog 2 LowThreshold Flag
733 * - ADC_FLAG_AnalogWatchdog2_HighThreshold:
734 * Analog Watchdog 2 HighThreshold Flag
735 * - ADC_FLAG_AnalogWatchdog3_LowThreshold:
736 * Analog Watchdog 3 LowThreshold Flag
737 * - ADC_FLAG_AnalogWatchdog3_HighThreshold:
738 * Analog Watchdog 3 HighThreshold Flag
740 * Return : The new state of the ADC_FLAG (SET or RESET).
741 *******************************************************************************/
742 FlagStatus ADC_GetFlagStatus(u16 ADC_FLAG)
744 /* Check the status of the specified ADC flag */
745 if((ADC->PBR & ADC_FLAG) != RESET)
747 /* Return SET if ADC_FLAG is set */
752 /* Return RESET if ADC_FLAG is reset */
757 /*******************************************************************************
758 * Function Name : ADC_ClearFlag
759 * Description : Clears the ADC
\92s pending flags.
760 * Input : - ADC_FLAG: specifies the flag to clear. This parameter can
761 * be any combination of the following values:
762 * - ADC_FLAG_ECH: End of chain conversion flag
763 * - ADC_FLAG_EOC: End of channel conversion flag
764 * - ADC_FLAG_JECH: Injected end of chain conversion flag
765 * - ADC_FLAG_JEOC: Injected end of channel conversion flag
766 * - ADC_FLAG_AnalogWatchdog0_LowThreshold:
767 * Analog Watchdog 0 LowThreshold flag
768 * - ADC_FLAG_AnalogWatchdog0_HighThreshold:
769 * Analog Watchdog 0 HighThreshold flag
770 * - ADC_FLAG_AnalogWatchdog1_LowThreshold:
771 * Analog Watchdog 1 LowThreshold flag
772 * - ADC_FLAG_AnalogWatchdog1_HighThreshold:
773 * Analog Watchdog 1 HighThreshold flag
774 * - ADC_FLAG_AnalogWatchdog2_LowThreshold:
775 * Analog Watchdog 2 LowThreshold flag
776 * - ADC_FLAG_AnalogWatchdog2_HighThreshold:
777 * Analog Watchdog 2 HighThreshold flag
778 * - ADC_FLAG_AnalogWatchdog3_LowThreshold:
779 * Analog Watchdog 3 LowThreshold flag
780 * - ADC_FLAG_AnalogWatchdog3_HighThreshold:
781 * Analog Watchdog 3 HighThreshold flag
784 *******************************************************************************/
785 void ADC_ClearFlag(u16 ADC_FLAG)
787 /* Clear the selected ADC flag */
791 /*******************************************************************************
792 * Function Name : ADC_GetITStatus
793 * Description : Checks whether the specified ADC interrupt has occured or not.
794 * Input : - ADC_IT: specifies the ADC interrupt source to check. This
795 * parameter can be one of the following values:
796 * - ADC_IT_ECH :End of chain conversion interrupt
797 * - ADC_IT_EOC :End of channel conversion interrupt
798 * - ADC_IT_JECH :End of injected chain conversion interrupt
799 * - ADC_IT_JEOC :End of injected channel conversion interrupt
800 * - ADC_IT_AnalogWatchdog0_LowThreshold:
801 * Analog Watchdog 0 LowThreshold interrupt
802 * - ADC_IT_AnalogWatchdog0_HighThreshold:
803 * Analog Watchdog 0 HighThreshold interrupt
804 * - ADC_IT_AnalogWatchdog1_LowThreshold:
805 * Analog Watchdog 1 LowThreshold interrupt
806 * - ADC_IT_AnalogWatchdog1_HighThreshold:
807 * Analog Watchdog 1 HighThreshold interrupt
808 * - ADC_IT_AnalogWatchdog2_LowThreshold:
809 * Analog Watchdog 2 LowThreshold interrupt
810 * - ADC_IT_AnalogWatchdog2_HighThreshold:
811 * Analog Watchdog 2 HighThreshold interrupt
812 * - ADC_IT_AnalogWatchdog3_LowThreshold:
813 * Analog Watchdog 3 LowThreshold interrupt
814 * - ADC_IT_AnalogWatchdog3_HighThreshold:
815 * Analog Watchdog 3 HighThreshold interrupt
817 * Return : The new state of the ADC_IT (SET or RESET).
818 *******************************************************************************/
819 ITStatus ADC_GetITStatus(u16 ADC_IT)
821 /* Check the status of the specified ADC interrupt */
822 if((ADC->PBR & ADC_IT) != RESET)
824 /* Return SET if the ADC interrupt flag is set */
829 /* Return RESET if the ADC interrupt flag is reset */
834 /*******************************************************************************
835 * Function Name : ADC_ClearITPendingBit
836 * Description : Clears the ADC
\92s interrupt pending bits.
837 * Input : - ADC_IT: specifies the interrupt pending bit to clear. This
838 * parameter can be can be any combination of the following
840 * - ADC_IT_ECH: End of chain conversion interrupt
841 * - ADC_IT_EOC: End of channel conversion interrupt
842 * - ADC_IT_JECH: Injected end of chain conversion interrupt
843 * - ADC_IT_JEOC: Injected end of channel conversion interrupt
844 * - ADC_IT_AnalogWatchdog0_LowThreshold:
845 * Analog Watchdog 0 LowThreshold interrupt
846 * - ADC_IT_AnalogWatchdog0_HighThreshold:
847 * Analog Watchdog 0 HighThreshold interrupt
848 * - ADC_IT_AnalogWatchdog1_LowThreshold:
849 * Analog Watchdog 1 LowThreshold interrupt
850 * - ADC_IT_AnalogWatchdog1_HighThreshold:
851 * Analog Watchdog 1 HighThreshold interrupt
852 * - ADC_IT_AnalogWatchdog2_LowThreshold:
853 * Analog Watchdog 2 LowThreshold interrupt
854 * - ADC_IT_AnalogWatchdog2_HighThreshold:
855 * Analog Watchdog 2 HighThreshold interrupt
856 * - ADC_IT_AnalogWatchdog3_LowThreshold:
857 * Analog Watchdog 3 LowThreshold interrupt
858 * - ADC_IT_AnalogWatchdog3_HighThreshold:
859 * Analog Watchdog 5 HighThreshold interrupt
862 *******************************************************************************/
863 void ADC_ClearITPendingBit(u16 ADC_IT)
865 /* Clear the selected ADC interrupts pending bits */
869 /******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/