CARME-M4 BSP  V1.5
stm32f4xx_adc.c File Reference

This file provides firmware functions to manage the following functionalities of the Analog to Digital Convertor (ADC) peripheral: More...

#include "stm32f4xx_adc.h"
#include "stm32f4xx_rcc.h"
+ Include dependency graph for stm32f4xx_adc.c:

Go to the source code of this file.

Macros

#define CR1_DISCNUM_RESET   ((uint32_t)0xFFFF1FFF)
 
#define CR1_AWDCH_RESET   ((uint32_t)0xFFFFFFE0)
 
#define CR1_AWDMode_RESET   ((uint32_t)0xFF3FFDFF)
 
#define CR1_CLEAR_MASK   ((uint32_t)0xFCFFFEFF)
 
#define CR2_EXTEN_RESET   ((uint32_t)0xCFFFFFFF)
 
#define CR2_JEXTEN_RESET   ((uint32_t)0xFFCFFFFF)
 
#define CR2_JEXTSEL_RESET   ((uint32_t)0xFFF0FFFF)
 
#define CR2_CLEAR_MASK   ((uint32_t)0xC0FFF7FD)
 
#define SQR3_SQ_SET   ((uint32_t)0x0000001F)
 
#define SQR2_SQ_SET   ((uint32_t)0x0000001F)
 
#define SQR1_SQ_SET   ((uint32_t)0x0000001F)
 
#define SQR1_L_RESET   ((uint32_t)0xFF0FFFFF)
 
#define JSQR_JSQ_SET   ((uint32_t)0x0000001F)
 
#define JSQR_JL_SET   ((uint32_t)0x00300000)
 
#define JSQR_JL_RESET   ((uint32_t)0xFFCFFFFF)
 
#define SMPR1_SMP_SET   ((uint32_t)0x00000007)
 
#define SMPR2_SMP_SET   ((uint32_t)0x00000007)
 
#define JDR_OFFSET   ((uint8_t)0x28)
 
#define CDR_ADDRESS   ((uint32_t)0x40012308)
 
#define CR_CLEAR_MASK   ((uint32_t)0xFFFC30E0)
 

Functions

void ADC_DeInit (void)
 Deinitializes all ADCs peripherals registers to their default reset values. More...
 
void ADC_Init (ADC_TypeDef *ADCx, ADC_InitTypeDef *ADC_InitStruct)
 Initializes the ADCx peripheral according to the specified parameters in the ADC_InitStruct. More...
 
void ADC_StructInit (ADC_InitTypeDef *ADC_InitStruct)
 Fills each ADC_InitStruct member with its default value. More...
 
void ADC_CommonInit (ADC_CommonInitTypeDef *ADC_CommonInitStruct)
 Initializes the ADCs peripherals according to the specified parameters in the ADC_CommonInitStruct. More...
 
void ADC_CommonStructInit (ADC_CommonInitTypeDef *ADC_CommonInitStruct)
 Fills each ADC_CommonInitStruct member with its default value. More...
 
void ADC_Cmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the specified ADC peripheral. More...
 
void ADC_AnalogWatchdogCmd (ADC_TypeDef *ADCx, uint32_t ADC_AnalogWatchdog)
 Enables or disables the analog watchdog on single/all regular or injected channels. More...
 
void ADC_AnalogWatchdogThresholdsConfig (ADC_TypeDef *ADCx, uint16_t HighThreshold, uint16_t LowThreshold)
 Configures the high and low thresholds of the analog watchdog. More...
 
void ADC_AnalogWatchdogSingleChannelConfig (ADC_TypeDef *ADCx, uint8_t ADC_Channel)
 Configures the analog watchdog guarded single channel. More...
 
void ADC_TempSensorVrefintCmd (FunctionalState NewState)
 Enables or disables the temperature sensor and Vrefint channels. More...
 
void ADC_VBATCmd (FunctionalState NewState)
 Enables or disables the VBAT (Voltage Battery) channel. More...
 
void ADC_RegularChannelConfig (ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
 Configures for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. More...
 
void ADC_SoftwareStartConv (ADC_TypeDef *ADCx)
 Enables the selected ADC software start conversion of the regular channels. More...
 
FlagStatus ADC_GetSoftwareStartConvStatus (ADC_TypeDef *ADCx)
 Gets the selected ADC Software start regular conversion Status. More...
 
void ADC_EOCOnEachRegularChannelCmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the EOC on each regular channel conversion. More...
 
void ADC_ContinuousModeCmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the ADC continuous conversion mode. More...
 
void ADC_DiscModeChannelCountConfig (ADC_TypeDef *ADCx, uint8_t Number)
 Configures the discontinuous mode for the selected ADC regular group channel. More...
 
void ADC_DiscModeCmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the discontinuous mode on regular group channel for the specified ADC. More...
 
uint16_t ADC_GetConversionValue (ADC_TypeDef *ADCx)
 Returns the last ADCx conversion result data for regular channel. More...
 
uint32_t ADC_GetMultiModeConversionValue (void)
 Returns the last ADC1, ADC2 and ADC3 regular conversions results data in the selected multi mode. More...
 
void ADC_DMACmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the specified ADC DMA request. More...
 
void ADC_DMARequestAfterLastTransferCmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the ADC DMA request after last transfer (Single-ADC mode) More...
 
void ADC_MultiModeDMARequestAfterLastTransferCmd (FunctionalState NewState)
 Enables or disables the ADC DMA request after last transfer in multi ADC mode. More...
 
void ADC_InjectedChannelConfig (ADC_TypeDef *ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
 Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time. More...
 
void ADC_InjectedSequencerLengthConfig (ADC_TypeDef *ADCx, uint8_t Length)
 Configures the sequencer length for injected channels. More...
 
void ADC_SetInjectedOffset (ADC_TypeDef *ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset)
 Set the injected channels conversion value offset. More...
 
void ADC_ExternalTrigInjectedConvConfig (ADC_TypeDef *ADCx, uint32_t ADC_ExternalTrigInjecConv)
 Configures the ADCx external trigger for injected channels conversion. More...
 
void ADC_ExternalTrigInjectedConvEdgeConfig (ADC_TypeDef *ADCx, uint32_t ADC_ExternalTrigInjecConvEdge)
 Configures the ADCx external trigger edge for injected channels conversion. More...
 
void ADC_SoftwareStartInjectedConv (ADC_TypeDef *ADCx)
 Enables the selected ADC software start conversion of the injected channels. More...
 
FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus (ADC_TypeDef *ADCx)
 Gets the selected ADC Software start injected conversion Status. More...
 
void ADC_AutoInjectedConvCmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the selected ADC automatic injected group conversion after regular one. More...
 
void ADC_InjectedDiscModeCmd (ADC_TypeDef *ADCx, FunctionalState NewState)
 Enables or disables the discontinuous mode for injected group channel for the specified ADC. More...
 
uint16_t ADC_GetInjectedConversionValue (ADC_TypeDef *ADCx, uint8_t ADC_InjectedChannel)
 Returns the ADC injected channel conversion result. More...
 
void ADC_ITConfig (ADC_TypeDef *ADCx, uint16_t ADC_IT, FunctionalState NewState)
 Enables or disables the specified ADC interrupts. More...
 
FlagStatus ADC_GetFlagStatus (ADC_TypeDef *ADCx, uint8_t ADC_FLAG)
 Checks whether the specified ADC flag is set or not. More...
 
void ADC_ClearFlag (ADC_TypeDef *ADCx, uint8_t ADC_FLAG)
 Clears the ADCx's pending flags. More...
 
ITStatus ADC_GetITStatus (ADC_TypeDef *ADCx, uint16_t ADC_IT)
 Checks whether the specified ADC interrupt has occurred or not. More...
 
void ADC_ClearITPendingBit (ADC_TypeDef *ADCx, uint16_t ADC_IT)
 Clears the ADCx's interrupt pending bits. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Analog to Digital Convertor (ADC) peripheral:

Author
MCD Application Team
Version
V1.3.0
Date
08-November-2013
  • Initialization and Configuration (in addition to ADC multi mode selection)
  • Analog Watchdog configuration
  • Temperature Sensor & Vrefint (Voltage Reference internal) & VBAT management
  • Regular Channels Configuration
  • Regular Channels DMA Configuration
  • Injected channels Configuration
  • Interrupts and flags management
===============================================================================
                    ##### How to use this driver #####
===============================================================================
   [..]
   (#) Enable the ADC interface clock using 
       RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADCx, ENABLE); 
      
   (#) ADC pins configuration
        (++) Enable the clock for the ADC GPIOs using the following function:
            RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOx, ENABLE);   
        (++) Configure these ADC pins in analog mode using GPIO_Init();  
 
    (#) Configure the ADC Prescaler, conversion resolution and data 
        alignment using the ADC_Init() function.
    (#) Activate the ADC peripheral using ADC_Cmd() function.
 
    *** Regular channels group configuration ***
    ============================================
    [..]    
      (+) To configure the ADC regular channels group features, use 
          ADC_Init() and ADC_RegularChannelConfig() functions.
      (+) To activate the continuous mode, use the ADC_continuousModeCmd()
          function.
      (+) To configurate and activate the Discontinuous mode, use the 
          ADC_DiscModeChannelCountConfig() and ADC_DiscModeCmd() functions.
      (+) To read the ADC converted values, use the ADC_GetConversionValue()
          function.
 
    *** Multi mode ADCs Regular channels configuration ***
    ======================================================
    [..]
      (+) Refer to "Regular channels group configuration" description to
          configure the ADC1, ADC2 and ADC3 regular channels.        
      (+) Select the Multi mode ADC regular channels features (dual or 
          triple mode) using ADC_CommonInit() function and configure 
          the DMA mode using ADC_MultiModeDMARequestAfterLastTransferCmd() 
          functions.        
      (+) Read the ADCs converted values using the 
          ADC_GetMultiModeConversionValue() function.
 
    *** DMA for Regular channels group features configuration ***
    ============================================================= 
    [..]
      (+) To enable the DMA mode for regular channels group, use the 
          ADC_DMACmd() function.
      (+) To enable the generation of DMA requests continuously at the end
          of the last DMA transfer, use the ADC_DMARequestAfterLastTransferCmd() 
          function.
 
    *** Injected channels group configuration ***
    =============================================    
    [..]
      (+) To configure the ADC Injected channels group features, use 
          ADC_InjectedChannelConfig() and  ADC_InjectedSequencerLengthConfig()
          functions.
      (+) To activate the continuous mode, use the ADC_continuousModeCmd()
          function.
      (+) To activate the Injected Discontinuous mode, use the 
          ADC_InjectedDiscModeCmd() function.  
      (+) To activate the AutoInjected mode, use the ADC_AutoInjectedConvCmd() 
          function.        
      (+) To read the ADC converted values, use the ADC_GetInjectedConversionValue() 
          function.
Attention

© COPYRIGHT 2013 STMicroelectronics

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.

Definition in file stm32f4xx_adc.c.