12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241 |
- /**
- ******************************************************************************
- * @file stm32f0xx_adc.c
- * @author MCD Application Team
- * @version V1.5.0
- * @date 05-December-2014
- * @brief This file provides firmware functions to manage the following
- * functionalities of the Analog to Digital Convertor (ADC) peripheral:
- * + Initialization and Configuration
- * + Power saving
- * + Analog Watchdog configuration
- * + Temperature Sensor, Vrefint (Internal Reference Voltage) and
- * Vbat (Voltage battery) management
- * + ADC Channels Configuration
- * + ADC Channels DMA Configuration
- * + Interrupts and flags management
- *
- * @verbatim
- ================================================================================
- ##### How to use this driver #####
- ================================================================================
- [..]
- (#) Enable the ADC interface clock using
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
- (#) ADC pins configuration
- (++) Enable the clock for the ADC GPIOs using the following function:
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOx, ENABLE);
- (++) Configure these ADC pins in analog mode using GPIO_Init();
- (#) Configure the ADC conversion resolution, data alignment, external
- trigger and edge, scan direction and Enable/Disable the continuous mode
- using the ADC_Init() function.
- (#) Activate the ADC peripheral using ADC_Cmd() function.
- *** ADC channels group configuration ***
- ============================================
- [..]
- (+) To configure the ADC channels features, use ADC_Init() and
- ADC_ChannelConfig() functions.
- (+) To activate the continuous mode, use the ADC_ContinuousModeCmd()
- function.
- (+) To activate the Discontinuous mode, use the ADC_DiscModeCmd() functions.
- (+) To activate the overrun mode, use the ADC_OverrunModeCmd() functions.
- (+) To activate the calibration mode, use the ADC_GetCalibrationFactor() functions.
- (+) To read the ADC converted values, use the ADC_GetConversionValue()
- function.
- *** DMA for ADC channels features configuration ***
- =============================================================
- [..]
- (+) To enable the DMA mode for ADC channels group, use the ADC_DMACmd() function.
- (+) To configure the DMA transfer request, use ADC_DMARequestModeConfig() function.
- * @endverbatim
- *
- ******************************************************************************
- * @attention
- *
- * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
- *
- * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
- * You may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.st.com/software_license_agreement_liberty_v2
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************
- */
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f0xx_adc.h"
- #include "stm32f0xx_rcc.h"
- /** @addtogroup STM32F0xx_StdPeriph_Driver
- * @{
- */
- /** @defgroup ADC
- * @brief ADC driver modules
- * @{
- */
- /* Private typedef -----------------------------------------------------------*/
- /* Private define ------------------------------------------------------------*/
- /* ADC CFGR mask */
- #define CFGR1_CLEAR_MASK ((uint32_t)0xFFFFD203)
- /* Calibration time out */
- #define CALIBRATION_TIMEOUT ((uint32_t)0x0000F000)
- /* Private macro -------------------------------------------------------------*/
- /* Private variables ---------------------------------------------------------*/
- /* Private function prototypes -----------------------------------------------*/
- /* Private functions ---------------------------------------------------------*/
- /** @defgroup ADC_Private_Functions
- * @{
- */
- /** @defgroup ADC_Group1 Initialization and Configuration functions
- * @brief Initialization and Configuration functions
- *
- @verbatim
- ===============================================================================
- ##### Initialization and Configuration functions #####
- ===============================================================================
- [..] This section provides functions allowing to:
- (+) Initialize and configure the ADC Prescaler
- (+) ADC Conversion Resolution (12bit..6bit)
- (+) ADC Continuous Conversion Mode (Continuous or Single conversion)
- (+) External trigger Edge and source
- (+) Converted data alignment (left or right)
- (+) The direction in which the channels will be scanned in the sequence
- (+) Enable or disable the ADC peripheral
-
- @endverbatim
- * @{
- */
- /**
- * @brief Deinitializes ADC1 peripheral registers to their default reset values.
- * @param ADCx: where x can be 1 to select the ADC peripheral.
- * @retval None
- */
- void ADC_DeInit(ADC_TypeDef* ADCx)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- if(ADCx == ADC1)
- {
- /* Enable ADC1 reset state */
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
- /* Release ADC1 from reset state */
- RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
- }
- }
- /**
- * @brief Initializes the ADCx peripheral according to the specified parameters
- * in the ADC_InitStruct.
- * @note This function is used to configure the global features of the ADC (
- * Resolution, Data Alignment, continuous mode activation, External
- * trigger source and edge, Sequence Scan Direction).
- * @param ADCx: where x can be 1 to select the ADC peripheral.
- * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
- * the configuration information for the specified ADC peripheral.
- * @retval None
- */
- void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
- {
- uint32_t tmpreg = 0;
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_RESOLUTION(ADC_InitStruct->ADC_Resolution));
- assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ContinuousConvMode));
- assert_param(IS_ADC_EXT_TRIG_EDGE(ADC_InitStruct->ADC_ExternalTrigConvEdge));
- assert_param(IS_ADC_EXTERNAL_TRIG_CONV(ADC_InitStruct->ADC_ExternalTrigConv));
- assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
- assert_param(IS_ADC_SCAN_DIRECTION(ADC_InitStruct->ADC_ScanDirection));
- /* Get the ADCx CFGR value */
- tmpreg = ADCx->CFGR1;
- /* Clear SCANDIR, RES[1:0], ALIGN, EXTSEL[2:0], EXTEN[1:0] and CONT bits */
- tmpreg &= CFGR1_CLEAR_MASK;
- /*---------------------------- ADCx CFGR Configuration ---------------------*/
- /* Set RES[1:0] bits according to ADC_Resolution value */
- /* Set CONT bit according to ADC_ContinuousConvMode value */
- /* Set EXTEN[1:0] bits according to ADC_ExternalTrigConvEdge value */
- /* Set EXTSEL[2:0] bits according to ADC_ExternalTrigConv value */
- /* Set ALIGN bit according to ADC_DataAlign value */
- /* Set SCANDIR bit according to ADC_ScanDirection value */
-
- tmpreg |= (uint32_t)(ADC_InitStruct->ADC_Resolution | ((uint32_t)(ADC_InitStruct->ADC_ContinuousConvMode) << 13) |
- ADC_InitStruct->ADC_ExternalTrigConvEdge | ADC_InitStruct->ADC_ExternalTrigConv |
- ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ScanDirection);
- /* Write to ADCx CFGR */
- ADCx->CFGR1 = tmpreg;
- }
- /**
- * @brief Fills each ADC_InitStruct member with its default value.
- * @note This function is used to initialize the global features of the ADC (
- * Resolution, Data Alignment, continuous mode activation, External
- * trigger source and edge, Sequence Scan Direction).
- * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure which will
- * be initialized.
- * @retval None
- */
- void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
- {
- /* Reset ADC init structure parameters values */
- /* Initialize the ADC_Resolution member */
- ADC_InitStruct->ADC_Resolution = ADC_Resolution_12b;
- /* Initialize the ADC_ContinuousConvMode member */
- ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
- /* Initialize the ADC_ExternalTrigConvEdge member */
- ADC_InitStruct->ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
- /* Initialize the ADC_ExternalTrigConv member */
- ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO;
- /* Initialize the ADC_DataAlign member */
- ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
- /* Initialize the ADC_ScanDirection member */
- ADC_InitStruct->ADC_ScanDirection = ADC_ScanDirection_Upward;
- }
- /**
- * @brief Enables or disables the specified ADC peripheral.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the ADCx peripheral.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Set the ADEN bit to Enable the ADC peripheral */
- ADCx->CR |= (uint32_t)ADC_CR_ADEN;
- }
- else
- {
- /* Set the ADDIS to Disable the ADC peripheral */
- ADCx->CR |= (uint32_t)ADC_CR_ADDIS;
- }
- }
- /**
- * @brief Configure the ADC to either be clocked by the asynchronous clock(which is
- * independent, the dedicated 14MHz clock) or the synchronous clock derived from
- * the APB clock of the ADC bus interface divided by 2 or 4
- * @note This function can be called only when ADC is disabled.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param ADC_ClockMode: This parameter can be :
- * @arg ADC_ClockMode_AsynClk: ADC clocked by the dedicated 14MHz clock
- * @arg ADC_ClockMode_SynClkDiv2: ADC clocked by PCLK/2
- * @arg ADC_ClockMode_SynClkDiv4: ADC clocked by PCLK/4
- * @retval None
- */
- void ADC_ClockModeConfig(ADC_TypeDef* ADCx, uint32_t ADC_ClockMode)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_CLOCKMODE(ADC_ClockMode));
- /* Configure the ADC Clock mode according to ADC_ClockMode */
- ADCx->CFGR2 = (uint32_t)ADC_ClockMode;
- }
- /**
- * @brief Enables or disables the jitter when the ADC is clocked by PCLK div2
- * or div4
- * @note This function is obsolete and maintained for legacy purpose only. ADC_ClockModeConfig()
- * function should be used instead.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param ADC_JitterOff: This parameter can be :
- * @arg ADC_JitterOff_PCLKDiv2: Remove jitter when ADC is clocked by PLCK divided by 2
- * @arg ADC_JitterOff_PCLKDiv4: Remove jitter when ADC is clocked by PLCK divided by 4
- * @param NewState: new state of the ADCx jitter.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_JitterCmd(ADC_TypeDef* ADCx, uint32_t ADC_JitterOff, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_JITTEROFF(ADC_JitterOff));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Disable Jitter */
- ADCx->CFGR2 |= (uint32_t)ADC_JitterOff;
- }
- else
- {
- /* Enable Jitter */
- ADCx->CFGR2 &= (uint32_t)(~ADC_JitterOff);
- }
- }
- /**
- * @}
- */
- /** @defgroup ADC_Group2 Power saving functions
- * @brief Power saving functions
- *
- @verbatim
- ===============================================================================
- ##### Power saving functions #####
- ===============================================================================
- [..] This section provides functions allowing to reduce power consumption.
- [..] The two function must be combined to get the maximal benefits:
- When the ADC frequency is higher than the CPU one, it is recommended to
- (#) Enable the Auto Delayed Conversion mode :
- ==> using ADC_WaitModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- (#) Enable the power off in Delay phases :
- ==> using ADC_AutoPowerOffCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
- @endverbatim
- * @{
- */
- /**
- * @brief Enables or disables the ADC Power Off.
- * @note ADC power-on and power-off can be managed by hardware to cut the
- * consumption when the ADC is not converting.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @note The ADC can be powered down:
- * - During the Auto delay phase: The ADC is powered on again at the end
- * of the delay (until the previous data is read from the ADC data register).
- * - During the ADC is waiting for a trigger event: The ADC is powered up
- * at the next trigger event (when the conversion is started).
- * @param NewState: new state of the ADCx power Off.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_AutoPowerOffCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the ADC Automatic Power-Off */
- ADCx->CFGR1 |= ADC_CFGR1_AUTOFF;
- }
- else
- {
- /* Disable the ADC Automatic Power-Off */
- ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_AUTOFF;
- }
- }
- /**
- * @brief Enables or disables the Wait conversion mode.
- * @note When the CPU clock is not fast enough to manage the data rate, a
- * Hardware delay can be introduced between ADC conversions to reduce
- * this data rate.
- * @note The Hardware delay is inserted after each conversions and until the
- * previous data is read from the ADC data register
- * @note This is a way to automatically adapt the speed of the ADC to the speed
- * of the system which will read the data.
- * @note Any hardware triggers wich occur while a conversion is on going or
- * while the automatic Delay is applied are ignored
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the ADCx Auto-Delay.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_WaitModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the ADC Automatic Delayed conversion */
- ADCx->CFGR1 |= ADC_CFGR1_WAIT;
- }
- else
- {
- /* Disable the ADC Automatic Delayed conversion */
- ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_WAIT;
- }
- }
- /**
- * @}
- */
- /** @defgroup ADC_Group3 Analog Watchdog configuration functions
- * @brief Analog Watchdog configuration functions
- *
- @verbatim
- ===============================================================================
- ##### Analog Watchdog configuration functions #####
- ===============================================================================
- [..] This section provides functions allowing to configure the Analog Watchdog
- (AWD) feature in the ADC.
- [..] A typical configuration Analog Watchdog is done following these steps :
- (#) the ADC guarded channel(s) is (are) selected using the
- ADC_AnalogWatchdogSingleChannelConfig() function.
- (#) The Analog watchdog lower and higher threshold are configured using the
- ADC_AnalogWatchdogThresholdsConfig() function.
- (#) The Analog watchdog is enabled and configured to enable the check, on one
- or more channels, using the ADC_AnalogWatchdogCmd() function.
- (#) Enable the analog watchdog on the selected channel using
- ADC_AnalogWatchdogSingleChannelCmd() function
- @endverbatim
- * @{
- */
- /**
- * @brief Enables or disables the analog watchdog
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the ADCx Analog Watchdog.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
-
- if (NewState != DISABLE)
- {
- /* Enable the ADC Analog Watchdog */
- ADCx->CFGR1 |= ADC_CFGR1_AWDEN;
- }
- else
- {
- /* Disable the ADC Analog Watchdog */
- ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_AWDEN;
- }
- }
- /**
- * @brief Configures the high and low thresholds of the analog watchdog.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param HighThreshold: the ADC analog watchdog High threshold value.
- * This parameter must be a 12bit value.
- * @param LowThreshold: the ADC analog watchdog Low threshold value.
- * This parameter must be a 12bit value.
- * @retval None
- */
- void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,
- uint16_t LowThreshold)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_THRESHOLD(HighThreshold));
- assert_param(IS_ADC_THRESHOLD(LowThreshold));
- /* Set the ADCx high and low threshold */
- ADCx->TR = LowThreshold | ((uint32_t)HighThreshold << 16);
- }
- /**
- * @brief Configures the analog watchdog guarded single channel
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param ADC_AnalogWatchdog_Channel: the ADC channel to configure for the analog watchdog.
- * This parameter can be one of the following values:
- * @arg ADC_AnalogWatchdog_Channel_0: ADC Channel0 selected
- * @arg ADC_AnalogWatchdog_Channel_1: ADC Channel1 selected
- * @arg ADC_AnalogWatchdog_Channel_2: ADC Channel2 selected
- * @arg ADC_AnalogWatchdog_Channel_3: ADC Channel3 selected
- * @arg ADC_AnalogWatchdog_Channel_4: ADC Channel4 selected
- * @arg ADC_AnalogWatchdog_Channel_5: ADC Channel5 selected
- * @arg ADC_AnalogWatchdog_Channel_6: ADC Channel6 selected
- * @arg ADC_AnalogWatchdog_Channel_7: ADC Channel7 selected
- * @arg ADC_AnalogWatchdog_Channel_8: ADC Channel8 selected
- * @arg ADC_AnalogWatchdog_Channel_9: ADC Channel9 selected
- * @arg ADC_AnalogWatchdog_Channel_10: ADC Channel10 selected, not available for STM32F031 devices
- * @arg ADC_AnalogWatchdog_Channel_11: ADC Channel11 selected, not available for STM32F031 devices
- * @arg ADC_AnalogWatchdog_Channel_12: ADC Channel12 selected, not available for STM32F031 devices
- * @arg ADC_AnalogWatchdog_Channel_13: ADC Channel13 selected, not available for STM32F031 devices
- * @arg ADC_AnalogWatchdog_Channel_14: ADC Channel14 selected, not available for STM32F031 devices
- * @arg ADC_AnalogWatchdog_Channel_15: ADC Channel15 selected, not available for STM32F031 devices
- * @arg ADC_AnalogWatchdog_Channel_16: ADC Channel16 selected
- * @arg ADC_AnalogWatchdog_Channel_17: ADC Channel17 selected
- * @arg ADC_AnalogWatchdog_Channel_18: ADC Channel18 selected, not available for STM32F030 devices
- * @note The channel selected on the AWDCH must be also set into the CHSELR
- * register
- * @retval None
- */
- void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog_Channel)
- {
- uint32_t tmpreg = 0;
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_ANALOG_WATCHDOG_CHANNEL(ADC_AnalogWatchdog_Channel));
- /* Get the old register value */
- tmpreg = ADCx->CFGR1;
- /* Clear the Analog watchdog channel select bits */
- tmpreg &= ~ADC_CFGR1_AWDCH;
- /* Set the Analog watchdog channel */
- tmpreg |= ADC_AnalogWatchdog_Channel;
- /* Store the new register value */
- ADCx->CFGR1 = tmpreg;
- }
- /**
- * @brief Enables or disables the ADC Analog Watchdog Single Channel.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the ADCx ADC Analog Watchdog Single Channel.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_AnalogWatchdogSingleChannelCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the ADC Analog Watchdog Single Channel */
- ADCx->CFGR1 |= ADC_CFGR1_AWDSGL;
- }
- else
- {
- /* Disable the ADC Analog Watchdog Single Channel */
- ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_AWDSGL;
- }
- }
- /**
- * @}
- */
- /** @defgroup ADC_Group4 Temperature Sensor, Vrefint and Vbat management functions
- * @brief Temperature Sensor, Vrefint and Vbat management functions
- *
- @verbatim
- ===============================================================================
- ##### Temperature Sensor, Vrefint and Vbat management function #####
- ===============================================================================
- [..] This section provides a function allowing to enable/disable the internal
- connections between the ADC and the Temperature Sensor, the Vrefint and
- Vbat source.
-
- [..] A typical configuration to get the Temperature sensor, Vrefint and Vbat channels
- voltages is done following these steps :
- (#) Enable the internal connection of Temperature sensor, Vrefint or Vbat sources
- with the ADC channels using ADC_TempSensorCmd(), ADC_VrefintCmd() or ADC_VbatCmd()
- functions.
- (#) select the ADC_Channel_16(Temperature sensor), ADC_Channel_17(Vrefint)
- or ADC_Channel_18(Voltage battery) using ADC_ChannelConfig() function
- (#) Get the voltage values, using ADC_GetConversionValue() function
- @endverbatim
- * @{
- */
- /**
- * @brief Enables or disables the temperature sensor channel.
- * @param NewState: new state of the temperature sensor input channel.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_TempSensorCmd(FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the temperature sensor channel*/
- ADC->CCR |= (uint32_t)ADC_CCR_TSEN;
- }
- else
- {
- /* Disable the temperature sensor channel*/
- ADC->CCR &= (uint32_t)(~ADC_CCR_TSEN);
- }
- }
- /**
- * @brief Enables or disables the Vrefint channel.
- * @param NewState: new state of the Vref input channel.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_VrefintCmd(FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the Vrefint channel*/
- ADC->CCR |= (uint32_t)ADC_CCR_VREFEN;
- }
- else
- {
- /* Disable the Vrefint channel*/
- ADC->CCR &= (uint32_t)(~ADC_CCR_VREFEN);
- }
- }
- /**
- * @brief Enables or disables the Vbat channel.
- * @note This feature is not applicable for STM32F030 devices.
- * @param NewState: new state of the Vbat input channel.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_VbatCmd(FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the Vbat channel*/
- ADC->CCR |= (uint32_t)ADC_CCR_VBATEN;
- }
- else
- {
- /* Disable the Vbat channel*/
- ADC->CCR &= (uint32_t)(~ADC_CCR_VBATEN);
- }
- }
- /**
- * @}
- */
- /** @defgroup ADC_Group5 Channels Configuration functions
- * @brief Channels Configuration functions
- *
- @verbatim
- ===============================================================================
- ##### Channels Configuration functions #####
- ===============================================================================
- [..] This section provides functions allowing to manage the ADC channels,
- it is composed of 3 sub sections :
- (#) Configuration and management functions for ADC channels: This subsection
- provides functions allowing to configure the ADC channels :
- (++) Select the ADC channels
- (++) Activate ADC Calibration
- (++) Activate the Overrun Mode.
- (++) Activate the Discontinuous Mode
- (++) Activate the Continuous Mode.
- (++) Configure the sampling time for each channel
- (++) Select the conversion Trigger and Edge for ADC channels
- (++) Select the scan direction.
- -@@- Please Note that the following features for ADC channels are configurated
- using the ADC_Init() function :
- (+@@) Activate the Continuous Mode (can be also activated by ADC_OverrunModeCmd().
- (+@@) Select the conversion Trigger and Edge for ADC channels
- (+@@) Select the scan direction.
- (#) Control the ADC peripheral : This subsection permits to command the ADC:
- (++) Stop or discard an on-going conversion (ADSTP command)
- (++) Start the ADC conversion .
- (#) Get the conversion data: This subsection provides an important function in
- the ADC peripheral since it returns the converted data of the current
- ADC channel. When the Conversion value is read, the EOC Flag is
- automatically cleared.
- @endverbatim
- * @{
- */
- /**
- * @brief Configures for the selected ADC and its sampling time.
- * @param ADCx: where x can be 1 to select the ADC peripheral.
- * @param ADC_Channel: the ADC channel to configure.
- * This parameter can be any combination of the following values:
- * @arg ADC_Channel_0: ADC Channel0 selected
- * @arg ADC_Channel_1: ADC Channel1 selected
- * @arg ADC_Channel_2: ADC Channel2 selected
- * @arg ADC_Channel_3: ADC Channel3 selected
- * @arg ADC_Channel_4: ADC Channel4 selected
- * @arg ADC_Channel_5: ADC Channel5 selected
- * @arg ADC_Channel_6: ADC Channel6 selected
- * @arg ADC_Channel_7: ADC Channel7 selected
- * @arg ADC_Channel_8: ADC Channel8 selected
- * @arg ADC_Channel_9: ADC Channel9 selected
- * @arg ADC_Channel_10: ADC Channel10 selected, not available for STM32F031 devices
- * @arg ADC_Channel_11: ADC Channel11 selected, not available for STM32F031 devices
- * @arg ADC_Channel_12: ADC Channel12 selected, not available for STM32F031 devices
- * @arg ADC_Channel_13: ADC Channel13 selected, not available for STM32F031 devices
- * @arg ADC_Channel_14: ADC Channel14 selected, not available for STM32F031 devices
- * @arg ADC_Channel_15: ADC Channel15 selected, not available for STM32F031 devices
- * @arg ADC_Channel_16: ADC Channel16 selected
- * @arg ADC_Channel_17: ADC Channel17 selected
- * @arg ADC_Channel_18: ADC Channel18 selected, not available for STM32F030 devices
- * @param ADC_SampleTime: The sample time value to be set for the selected channel.
- * This parameter can be one of the following values:
- * @arg ADC_SampleTime_1_5Cycles: Sample time equal to 1.5 cycles
- * @arg ADC_SampleTime_7_5Cycles: Sample time equal to 7.5 cycles
- * @arg ADC_SampleTime_13_5Cycles: Sample time equal to 13.5 cycles
- * @arg ADC_SampleTime_28_5Cycles: Sample time equal to 28.5 cycles
- * @arg ADC_SampleTime_41_5Cycles: Sample time equal to 41.5 cycles
- * @arg ADC_SampleTime_55_5Cycles: Sample time equal to 55.5 cycles
- * @arg ADC_SampleTime_71_5Cycles: Sample time equal to 71.5 cycles
- * @arg ADC_SampleTime_239_5Cycles: Sample time equal to 239.5 cycles
- * @retval None
- */
- void ADC_ChannelConfig(ADC_TypeDef* ADCx, uint32_t ADC_Channel, uint32_t ADC_SampleTime)
- {
- uint32_t tmpreg = 0;
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_CHANNEL(ADC_Channel));
- assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
- /* Configure the ADC Channel */
- ADCx->CHSELR |= (uint32_t)ADC_Channel;
- /* Clear the Sampling time Selection bits */
- tmpreg &= ~ADC_SMPR1_SMPR;
- /* Set the ADC Sampling Time register */
- tmpreg |= (uint32_t)ADC_SampleTime;
- /* Configure the ADC Sample time register */
- ADCx->SMPR = tmpreg ;
- }
- /**
- * @brief Enable the Continuous mode for the selected ADCx channels.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the Continuous mode.
- * This parameter can be: ENABLE or DISABLE.
- * @note It is not possible to have both discontinuous mode and continuous mode
- * enabled. In this case (If DISCEN and CONT are Set), the ADC behaves
- * as if continuous mode was disabled
- * @retval None
- */
- void ADC_ContinuousModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the Continuous mode*/
- ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_CONT;
- }
- else
- {
- /* Disable the Continuous mode */
- ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_CONT);
- }
- }
- /**
- * @brief Enable the discontinuous mode for the selected ADC channels.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the discontinuous mode.
- * This parameter can be: ENABLE or DISABLE.
- * @note It is not possible to have both discontinuous mode and continuous mode
- * enabled. In this case (If DISCEN and CONT are Set), the ADC behaves
- * as if continuous mode was disabled
- * @retval None
- */
- void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the Discontinuous mode */
- ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_DISCEN;
- }
- else
- {
- /* Disable the Discontinuous mode */
- ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_DISCEN);
- }
- }
- /**
- * @brief Enable the Overrun mode for the selected ADC channels.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the Overrun mode.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_OverrunModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the Overrun mode */
- ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_OVRMOD;
- }
- else
- {
- /* Disable the Overrun mode */
- ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_OVRMOD);
- }
- }
- /**
- * @brief Active the Calibration operation for the selected ADC.
- * @note The Calibration can be initiated only when ADC is still in the
- * reset configuration (ADEN must be equal to 0).
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @retval ADC Calibration factor
- */
- uint32_t ADC_GetCalibrationFactor(ADC_TypeDef* ADCx)
- {
- uint32_t tmpreg = 0, calibrationcounter = 0, calibrationstatus = 0;
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
-
- /* Set the ADC calibartion */
- ADCx->CR |= (uint32_t)ADC_CR_ADCAL;
-
- /* Wait until no ADC calibration is completed */
- do
- {
- calibrationstatus = ADCx->CR & ADC_CR_ADCAL;
- calibrationcounter++;
- } while((calibrationcounter != CALIBRATION_TIMEOUT) && (calibrationstatus != 0x00));
-
- if((uint32_t)(ADCx->CR & ADC_CR_ADCAL) == RESET)
- {
- /*Get the calibration factor from the ADC data register */
- tmpreg = ADCx->DR;
- }
- else
- {
- /* Error factor */
- tmpreg = 0x00000000;
- }
- return tmpreg;
- }
- /**
- * @brief Stop the on going conversions for the selected ADC.
- * @note When ADSTP is set, any on going conversion is aborted, and the ADC
- * data register is not updated with current conversion.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @retval None
- */
- void ADC_StopOfConversion(ADC_TypeDef* ADCx)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
-
- ADCx->CR |= (uint32_t)ADC_CR_ADSTP;
- }
- /**
- * @brief Start Conversion for the selected ADC channels.
- * @note In continuous mode, ADSTART is not cleared by hardware with the
- * assertion of EOSEQ because the sequence is automatic relaunched
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @retval None
- */
- void ADC_StartOfConversion(ADC_TypeDef* ADCx)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
-
- ADCx->CR |= (uint32_t)ADC_CR_ADSTART;
- }
- /**
- * @brief Returns the last ADCx conversion result data for ADC channel.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @retval The Data conversion value.
- */
- uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- /* Return the selected ADC conversion value */
- return (uint16_t) ADCx->DR;
- }
- /**
- * @}
- */
- /** @defgroup ADC_Group6 DMA Configuration functions
- * @brief Regular Channels DMA Configuration functions
- *
- @verbatim
- ===============================================================================
- ##### DMA Configuration functions #####
- ===============================================================================
- [..] This section provides functions allowing to configure the DMA for ADC hannels.
- Since converted channel values are stored into a unique data register,
- it is useful to use DMA for conversion of more than one channel. This
- avoids the loss of the data already stored in the ADC Data register.
- When the DMA mode is enabled (using the ADC_DMACmd() function), after each
- conversion of a channel, a DMA request is generated.
-
- [..] Depending on the "DMA disable selection" configuration (using the
- ADC_DMARequestModeConfig() function), at the end of the last DMA
- transfer, two possibilities are allowed:
- (+) No new DMA request is issued to the DMA controller (One Shot Mode)
- (+) Requests can continue to be generated (Circular Mode).
- @endverbatim
- * @{
- */
- /**
- * @brief Enables or disables the specified ADC DMA request.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param NewState: new state of the selected ADC DMA transfer.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- if (NewState != DISABLE)
- {
- /* Enable the selected ADC DMA request */
- ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_DMAEN;
- }
- else
- {
- /* Disable the selected ADC DMA request */
- ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_DMAEN);
- }
- }
- /**
- * @brief Enables or disables the ADC DMA request after last transfer (Single-ADC mode)
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param ADC_DMARequestMode: the ADC channel to configure.
- * This parameter can be one of the following values:
- * @arg ADC_DMAMode_OneShot: DMA One Shot Mode
- * @arg ADC_DMAMode_Circular: DMA Circular Mode
- * @retval None
- */
- void ADC_DMARequestModeConfig(ADC_TypeDef* ADCx, uint32_t ADC_DMARequestMode)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_DMACFG;
- ADCx->CFGR1 |= (uint32_t)ADC_DMARequestMode;
- }
- /**
- * @}
- */
- /** @defgroup ADC_Group7 Interrupts and flags management functions
- * @brief Interrupts and flags management functions.
- *
- @verbatim
- ===============================================================================
- ##### Interrupts and flags management functions #####
- ===============================================================================
- [..] This section provides functions allowing to configure the ADC Interrupts
- and get the status and clear flags and Interrupts pending bits.
-
- [..] The ADC provide 6 Interrupts sources and 11 Flags which can be divided into
- 3 groups:
- *** Flags for ADC status ***
- ======================================================
- [..]
- (+)Flags :
- (##) ADC_FLAG_ADRDY : This flag is set after the ADC has been enabled (bit ADEN=1)
- and when the ADC reaches a state where it is ready to accept conversion requests
- (##) ADC_FLAG_ADEN : This flag is set by software to enable the ADC.
- The ADC will be effectively ready to operate once the ADRDY flag has been set.
- (##) ADC_FLAG_ADDIS : This flag is cleared once the ADC is effectively
- disabled.
- (##) ADC_FLAG_ADSTART : This flag is cleared after the execution of
- ADC_StopOfConversion() function, at the same time as the ADSTP bit is
- cleared by hardware
- (##) ADC_FLAG_ADSTP : This flag is cleared by hardware when the conversion
- is effectively discarded and the ADC is ready to accept a new start conversion
- (##) ADC_FLAG_ADCAL : This flag is set once the calibration is complete.
- (+)Interrupts
- (##) ADC_IT_ADRDY : specifies the interrupt source for ADC ready event.
- *** Flags and Interrupts for ADC channel conversion ***
- =====================================================
- [..]
- (+)Flags :
- (##) ADC_FLAG_EOC : This flag is set by hardware at the end of each conversion
- of a channel when a new data result is available in the data register
- (##) ADC_FLAG_EOSEQ : This bit is set by hardware at the end of the conversion
- of a sequence of channels selected by ADC_ChannelConfig() function.
- (##) ADC_FLAG_EOSMP : This bit is set by hardware at the end of the sampling phase.
- (##) ADC_FLAG_OVR : This flag is set by hardware when an overrun occurs,
- meaning that a new conversion has complete while the EOC flag was already set.
- (+)Interrupts :
- (##) ADC_IT_EOC : specifies the interrupt source for end of conversion event.
- (##) ADC_IT_EOSEQ : specifies the interrupt source for end of sequence event.
- (##) ADC_IT_EOSMP : specifies the interrupt source for end of sampling event.
- (##) ADC_IT_OVR : specifies the interrupt source for Overrun detection
- event.
- *** Flags and Interrupts for the Analog Watchdog ***
- ================================================
- [..]
- (+)Flags :
- (##) ADC_FLAG_AWD: This flag is set by hardware when the converted
- voltage crosses the values programmed thrsholds
- (+)Interrupts :
- (##) ADC_IT_AWD : specifies the interrupt source for Analog watchdog
- event.
-
- [..] The user should identify which mode will be used in his application to
- manage the ADC controller events: Polling mode or Interrupt mode.
-
- [..] In the Polling Mode it is advised to use the following functions:
- (+) ADC_GetFlagStatus() : to check if flags events occur.
- (+) ADC_ClearFlag() : to clear the flags events.
-
- [..] In the Interrupt Mode it is advised to use the following functions:
- (+) ADC_ITConfig() : to enable or disable the interrupt source.
- (+) ADC_GetITStatus() : to check if Interrupt occurs.
- (+) ADC_ClearITPendingBit() : to clear the Interrupt pending Bit
- (corresponding Flag).
- @endverbatim
- * @{
- */
- /**
- * @brief Enables or disables the specified ADC interrupts.
- * @param ADCx: where x can be 1 to select the ADC peripheral.
- * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
- * This parameter can be one of the following values:
- * @arg ADC_IT_ADRDY: ADC ready interrupt
- * @arg ADC_IT_EOSMP: End of sampling interrupt
- * @arg ADC_IT_EOC: End of conversion interrupt
- * @arg ADC_IT_EOSEQ: End of sequence of conversion interrupt
- * @arg ADC_IT_OVR: overrun interrupt
- * @arg ADC_IT_AWD: Analog watchdog interrupt
- * @param NewState: new state of the specified ADC interrupts.
- * This parameter can be: ENABLE or DISABLE.
- * @retval None
- */
- void ADC_ITConfig(ADC_TypeDef* ADCx, uint32_t ADC_IT, FunctionalState NewState)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_FUNCTIONAL_STATE(NewState));
- assert_param(IS_ADC_CONFIG_IT(ADC_IT));
- if (NewState != DISABLE)
- {
- /* Enable the selected ADC interrupts */
- ADCx->IER |= ADC_IT;
- }
- else
- {
- /* Disable the selected ADC interrupts */
- ADCx->IER &= (~(uint32_t)ADC_IT);
- }
- }
- /**
- * @brief Checks whether the specified ADC flag is set or not.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param ADC_FLAG: specifies the flag to check.
- * This parameter can be one of the following values:
- * @arg ADC_FLAG_AWD: Analog watchdog flag
- * @arg ADC_FLAG_OVR: Overrun flag
- * @arg ADC_FLAG_EOSEQ: End of Sequence flag
- * @arg ADC_FLAG_EOC: End of conversion flag
- * @arg ADC_FLAG_EOSMP: End of sampling flag
- * @arg ADC_FLAG_ADRDY: ADC Ready flag
- * @arg ADC_FLAG_ADEN: ADC enable flag
- * @arg ADC_FLAG_ADDIS: ADC disable flag
- * @arg ADC_FLAG_ADSTART: ADC start flag
- * @arg ADC_FLAG_ADSTP: ADC stop flag
- * @arg ADC_FLAG_ADCAL: ADC Calibration flag
- * @retval The new state of ADC_FLAG (SET or RESET).
- */
- FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
- {
- FlagStatus bitstatus = RESET;
- uint32_t tmpreg = 0;
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_GET_FLAG(ADC_FLAG));
- if((uint32_t)(ADC_FLAG & 0x01000000))
- {
- tmpreg = ADCx->CR & 0xFEFFFFFF;
- }
- else
- {
- tmpreg = ADCx->ISR;
- }
-
- /* Check the status of the specified ADC flag */
- if ((tmpreg & ADC_FLAG) != (uint32_t)RESET)
- {
- /* ADC_FLAG is set */
- bitstatus = SET;
- }
- else
- {
- /* ADC_FLAG is reset */
- bitstatus = RESET;
- }
- /* Return the ADC_FLAG status */
- return bitstatus;
- }
- /**
- * @brief Clears the ADCx's pending flags.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param ADC_FLAG: specifies the flag to clear.
- * This parameter can be any combination of the following values:
- * @arg ADC_FLAG_AWD: Analog watchdog flag
- * @arg ADC_FLAG_EOC: End of conversion flag
- * @arg ADC_FLAG_ADRDY: ADC Ready flag
- * @arg ADC_FLAG_EOSMP: End of sampling flag
- * @arg ADC_FLAG_EOSEQ: End of Sequence flag
- * @arg ADC_FLAG_OVR: Overrun flag
- * @retval None
- */
- void ADC_ClearFlag(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG));
- /* Clear the selected ADC flags */
- ADCx->ISR = (uint32_t)ADC_FLAG;
- }
- /**
- * @brief Checks whether the specified ADC interrupt has occurred or not.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral
- * @param ADC_IT: specifies the ADC interrupt source to check.
- * This parameter can be one of the following values:
- * @arg ADC_IT_ADRDY: ADC ready interrupt
- * @arg ADC_IT_EOSMP: End of sampling interrupt
- * @arg ADC_IT_EOC: End of conversion interrupt
- * @arg ADC_IT_EOSEQ: End of sequence of conversion interrupt
- * @arg ADC_IT_OVR: overrun interrupt
- * @arg ADC_IT_AWD: Analog watchdog interrupt
- * @retval The new state of ADC_IT (SET or RESET).
- */
- ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint32_t ADC_IT)
- {
- ITStatus bitstatus = RESET;
- uint32_t enablestatus = 0;
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_GET_IT(ADC_IT));
- /* Get the ADC_IT enable bit status */
- enablestatus = (uint32_t)(ADCx->IER & ADC_IT);
- /* Check the status of the specified ADC interrupt */
- if (((uint32_t)(ADCx->ISR & ADC_IT) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
- {
- /* ADC_IT is set */
- bitstatus = SET;
- }
- else
- {
- /* ADC_IT is reset */
- bitstatus = RESET;
- }
- /* Return the ADC_IT status */
- return bitstatus;
- }
- /**
- * @brief Clears the ADCx's interrupt pending bits.
- * @param ADCx: where x can be 1 to select the ADC1 peripheral.
- * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
- * This parameter can be one of the following values:
- * @arg ADC_IT_ADRDY: ADC ready interrupt
- * @arg ADC_IT_EOSMP: End of sampling interrupt
- * @arg ADC_IT_EOC: End of conversion interrupt
- * @arg ADC_IT_EOSEQ: End of sequence of conversion interrupt
- * @arg ADC_IT_OVR: overrun interrupt
- * @arg ADC_IT_AWD: Analog watchdog interrupt
- * @retval None
- */
- void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint32_t ADC_IT)
- {
- /* Check the parameters */
- assert_param(IS_ADC_ALL_PERIPH(ADCx));
- assert_param(IS_ADC_CLEAR_IT(ADC_IT));
- /* Clear the selected ADC interrupt pending bits */
- ADCx->ISR = (uint32_t)ADC_IT;
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|