mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri Mar 21 11:45:09 2014 +0000
Revision:
130:1dec54e4aec3
Synchronized with git revision e5c9ff6781a4e277a5a454e5a0b037f76e31739d

Full URL: https://github.com/mbedmicro/mbed/commit/e5c9ff6781a4e277a5a454e5a0b037f76e31739d/

STM32F0-Discovery (STM32F051R8) initial port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 130:1dec54e4aec3 1 /**
mbed_official 130:1dec54e4aec3 2 ******************************************************************************
mbed_official 130:1dec54e4aec3 3 * @file stm32f0xx_adc.c
mbed_official 130:1dec54e4aec3 4 * @author MCD Application Team
mbed_official 130:1dec54e4aec3 5 * @version V1.3.0
mbed_official 130:1dec54e4aec3 6 * @date 16-January-2014
mbed_official 130:1dec54e4aec3 7 * @brief This file provides firmware functions to manage the following
mbed_official 130:1dec54e4aec3 8 * functionalities of the Analog to Digital Convertor (ADC) peripheral:
mbed_official 130:1dec54e4aec3 9 * + Initialization and Configuration
mbed_official 130:1dec54e4aec3 10 * + Power saving
mbed_official 130:1dec54e4aec3 11 * + Analog Watchdog configuration
mbed_official 130:1dec54e4aec3 12 * + Temperature Sensor, Vrefint (Internal Reference Voltage) and
mbed_official 130:1dec54e4aec3 13 * Vbat (Voltage battery) management
mbed_official 130:1dec54e4aec3 14 * + ADC Channels Configuration
mbed_official 130:1dec54e4aec3 15 * + ADC Channels DMA Configuration
mbed_official 130:1dec54e4aec3 16 * + Interrupts and flags management
mbed_official 130:1dec54e4aec3 17 *
mbed_official 130:1dec54e4aec3 18 * @verbatim
mbed_official 130:1dec54e4aec3 19 ================================================================================
mbed_official 130:1dec54e4aec3 20 ##### How to use this driver #####
mbed_official 130:1dec54e4aec3 21 ================================================================================
mbed_official 130:1dec54e4aec3 22 [..]
mbed_official 130:1dec54e4aec3 23 (#) Enable the ADC interface clock using
mbed_official 130:1dec54e4aec3 24 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
mbed_official 130:1dec54e4aec3 25 (#) ADC pins configuration
mbed_official 130:1dec54e4aec3 26 (++) Enable the clock for the ADC GPIOs using the following function:
mbed_official 130:1dec54e4aec3 27 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOx, ENABLE);
mbed_official 130:1dec54e4aec3 28 (++) Configure these ADC pins in analog mode using GPIO_Init();
mbed_official 130:1dec54e4aec3 29 (#) Configure the ADC conversion resolution, data alignment, external
mbed_official 130:1dec54e4aec3 30 trigger and edge, scan direction and Enable/Disable the continuous mode
mbed_official 130:1dec54e4aec3 31 using the ADC_Init() function.
mbed_official 130:1dec54e4aec3 32 (#) Activate the ADC peripheral using ADC_Cmd() function.
mbed_official 130:1dec54e4aec3 33
mbed_official 130:1dec54e4aec3 34 *** ADC channels group configuration ***
mbed_official 130:1dec54e4aec3 35 ============================================
mbed_official 130:1dec54e4aec3 36 [..]
mbed_official 130:1dec54e4aec3 37 (+) To configure the ADC channels features, use ADC_Init() and
mbed_official 130:1dec54e4aec3 38 ADC_ChannelConfig() functions.
mbed_official 130:1dec54e4aec3 39 (+) To activate the continuous mode, use the ADC_ContinuousModeCmd()
mbed_official 130:1dec54e4aec3 40 function.
mbed_official 130:1dec54e4aec3 41 (+) To activate the Discontinuous mode, use the ADC_DiscModeCmd() functions.
mbed_official 130:1dec54e4aec3 42 (+) To activate the overrun mode, use the ADC_OverrunModeCmd() functions.
mbed_official 130:1dec54e4aec3 43 (+) To activate the calibration mode, use the ADC_GetCalibrationFactor() functions.
mbed_official 130:1dec54e4aec3 44 (+) To read the ADC converted values, use the ADC_GetConversionValue()
mbed_official 130:1dec54e4aec3 45 function.
mbed_official 130:1dec54e4aec3 46
mbed_official 130:1dec54e4aec3 47 *** DMA for ADC channels features configuration ***
mbed_official 130:1dec54e4aec3 48 =============================================================
mbed_official 130:1dec54e4aec3 49 [..]
mbed_official 130:1dec54e4aec3 50 (+) To enable the DMA mode for ADC channels group, use the ADC_DMACmd() function.
mbed_official 130:1dec54e4aec3 51 (+) To configure the DMA transfer request, use ADC_DMARequestModeConfig() function.
mbed_official 130:1dec54e4aec3 52
mbed_official 130:1dec54e4aec3 53 * @endverbatim
mbed_official 130:1dec54e4aec3 54 *
mbed_official 130:1dec54e4aec3 55 ******************************************************************************
mbed_official 130:1dec54e4aec3 56 * @attention
mbed_official 130:1dec54e4aec3 57 *
mbed_official 130:1dec54e4aec3 58 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 130:1dec54e4aec3 59 *
mbed_official 130:1dec54e4aec3 60 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 130:1dec54e4aec3 61 * are permitted provided that the following conditions are met:
mbed_official 130:1dec54e4aec3 62 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 130:1dec54e4aec3 63 * this list of conditions and the following disclaimer.
mbed_official 130:1dec54e4aec3 64 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 130:1dec54e4aec3 65 * this list of conditions and the following disclaimer in the documentation
mbed_official 130:1dec54e4aec3 66 * and/or other materials provided with the distribution.
mbed_official 130:1dec54e4aec3 67 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 130:1dec54e4aec3 68 * may be used to endorse or promote products derived from this software
mbed_official 130:1dec54e4aec3 69 * without specific prior written permission.
mbed_official 130:1dec54e4aec3 70 *
mbed_official 130:1dec54e4aec3 71 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 130:1dec54e4aec3 72 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 130:1dec54e4aec3 73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 130:1dec54e4aec3 74 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 130:1dec54e4aec3 75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 130:1dec54e4aec3 76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 130:1dec54e4aec3 77 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 130:1dec54e4aec3 78 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 130:1dec54e4aec3 79 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 130:1dec54e4aec3 80 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 130:1dec54e4aec3 81 *
mbed_official 130:1dec54e4aec3 82 ******************************************************************************
mbed_official 130:1dec54e4aec3 83 */
mbed_official 130:1dec54e4aec3 84
mbed_official 130:1dec54e4aec3 85 /* Includes ------------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 86 #include "stm32f0xx_adc.h"
mbed_official 130:1dec54e4aec3 87 #include "stm32f0xx_rcc.h"
mbed_official 130:1dec54e4aec3 88
mbed_official 130:1dec54e4aec3 89 /** @addtogroup STM32F0xx_StdPeriph_Driver
mbed_official 130:1dec54e4aec3 90 * @{
mbed_official 130:1dec54e4aec3 91 */
mbed_official 130:1dec54e4aec3 92
mbed_official 130:1dec54e4aec3 93 /** @defgroup ADC
mbed_official 130:1dec54e4aec3 94 * @brief ADC driver modules
mbed_official 130:1dec54e4aec3 95 * @{
mbed_official 130:1dec54e4aec3 96 */
mbed_official 130:1dec54e4aec3 97
mbed_official 130:1dec54e4aec3 98 /* Private typedef -----------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 99 /* Private define ------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 100 /* ADC CFGR mask */
mbed_official 130:1dec54e4aec3 101 #define CFGR1_CLEAR_MASK ((uint32_t)0xFFFFD203)
mbed_official 130:1dec54e4aec3 102
mbed_official 130:1dec54e4aec3 103 /* Calibration time out */
mbed_official 130:1dec54e4aec3 104 #define CALIBRATION_TIMEOUT ((uint32_t)0x0000F000)
mbed_official 130:1dec54e4aec3 105
mbed_official 130:1dec54e4aec3 106 /* Private macro -------------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 107 /* Private variables ---------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 108 /* Private function prototypes -----------------------------------------------*/
mbed_official 130:1dec54e4aec3 109 /* Private functions ---------------------------------------------------------*/
mbed_official 130:1dec54e4aec3 110
mbed_official 130:1dec54e4aec3 111 /** @defgroup ADC_Private_Functions
mbed_official 130:1dec54e4aec3 112 * @{
mbed_official 130:1dec54e4aec3 113 */
mbed_official 130:1dec54e4aec3 114
mbed_official 130:1dec54e4aec3 115 /** @defgroup ADC_Group1 Initialization and Configuration functions
mbed_official 130:1dec54e4aec3 116 * @brief Initialization and Configuration functions
mbed_official 130:1dec54e4aec3 117 *
mbed_official 130:1dec54e4aec3 118 @verbatim
mbed_official 130:1dec54e4aec3 119 ===============================================================================
mbed_official 130:1dec54e4aec3 120 ##### Initialization and Configuration functions #####
mbed_official 130:1dec54e4aec3 121 ===============================================================================
mbed_official 130:1dec54e4aec3 122 [..] This section provides functions allowing to:
mbed_official 130:1dec54e4aec3 123 (+) Initialize and configure the ADC Prescaler
mbed_official 130:1dec54e4aec3 124 (+) ADC Conversion Resolution (12bit..6bit)
mbed_official 130:1dec54e4aec3 125 (+) ADC Continuous Conversion Mode (Continuous or Single conversion)
mbed_official 130:1dec54e4aec3 126 (+) External trigger Edge and source
mbed_official 130:1dec54e4aec3 127 (+) Converted data alignment (left or right)
mbed_official 130:1dec54e4aec3 128 (+) The direction in which the channels will be scanned in the sequence
mbed_official 130:1dec54e4aec3 129 (+) Enable or disable the ADC peripheral
mbed_official 130:1dec54e4aec3 130
mbed_official 130:1dec54e4aec3 131 @endverbatim
mbed_official 130:1dec54e4aec3 132 * @{
mbed_official 130:1dec54e4aec3 133 */
mbed_official 130:1dec54e4aec3 134
mbed_official 130:1dec54e4aec3 135 /**
mbed_official 130:1dec54e4aec3 136 * @brief Deinitializes ADC1 peripheral registers to their default reset values.
mbed_official 130:1dec54e4aec3 137 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 130:1dec54e4aec3 138 * @retval None
mbed_official 130:1dec54e4aec3 139 */
mbed_official 130:1dec54e4aec3 140 void ADC_DeInit(ADC_TypeDef* ADCx)
mbed_official 130:1dec54e4aec3 141 {
mbed_official 130:1dec54e4aec3 142 /* Check the parameters */
mbed_official 130:1dec54e4aec3 143 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 144
mbed_official 130:1dec54e4aec3 145 if(ADCx == ADC1)
mbed_official 130:1dec54e4aec3 146 {
mbed_official 130:1dec54e4aec3 147 /* Enable ADC1 reset state */
mbed_official 130:1dec54e4aec3 148 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
mbed_official 130:1dec54e4aec3 149
mbed_official 130:1dec54e4aec3 150 /* Release ADC1 from reset state */
mbed_official 130:1dec54e4aec3 151 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
mbed_official 130:1dec54e4aec3 152 }
mbed_official 130:1dec54e4aec3 153 }
mbed_official 130:1dec54e4aec3 154
mbed_official 130:1dec54e4aec3 155 /**
mbed_official 130:1dec54e4aec3 156 * @brief Initializes the ADCx peripheral according to the specified parameters
mbed_official 130:1dec54e4aec3 157 * in the ADC_InitStruct.
mbed_official 130:1dec54e4aec3 158 * @note This function is used to configure the global features of the ADC (
mbed_official 130:1dec54e4aec3 159 * Resolution, Data Alignment, continuous mode activation, External
mbed_official 130:1dec54e4aec3 160 * trigger source and edge, Sequence Scan Direction).
mbed_official 130:1dec54e4aec3 161 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 130:1dec54e4aec3 162 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
mbed_official 130:1dec54e4aec3 163 * the configuration information for the specified ADC peripheral.
mbed_official 130:1dec54e4aec3 164 * @retval None
mbed_official 130:1dec54e4aec3 165 */
mbed_official 130:1dec54e4aec3 166 void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
mbed_official 130:1dec54e4aec3 167 {
mbed_official 130:1dec54e4aec3 168 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 169
mbed_official 130:1dec54e4aec3 170 /* Check the parameters */
mbed_official 130:1dec54e4aec3 171 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 172 assert_param(IS_ADC_RESOLUTION(ADC_InitStruct->ADC_Resolution));
mbed_official 130:1dec54e4aec3 173 assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ContinuousConvMode));
mbed_official 130:1dec54e4aec3 174 assert_param(IS_ADC_EXT_TRIG_EDGE(ADC_InitStruct->ADC_ExternalTrigConvEdge));
mbed_official 130:1dec54e4aec3 175 assert_param(IS_ADC_EXTERNAL_TRIG_CONV(ADC_InitStruct->ADC_ExternalTrigConv));
mbed_official 130:1dec54e4aec3 176 assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
mbed_official 130:1dec54e4aec3 177 assert_param(IS_ADC_SCAN_DIRECTION(ADC_InitStruct->ADC_ScanDirection));
mbed_official 130:1dec54e4aec3 178
mbed_official 130:1dec54e4aec3 179 /* Get the ADCx CFGR value */
mbed_official 130:1dec54e4aec3 180 tmpreg = ADCx->CFGR1;
mbed_official 130:1dec54e4aec3 181
mbed_official 130:1dec54e4aec3 182 /* Clear SCANDIR, RES[1:0], ALIGN, EXTSEL[2:0], EXTEN[1:0] and CONT bits */
mbed_official 130:1dec54e4aec3 183 tmpreg &= CFGR1_CLEAR_MASK;
mbed_official 130:1dec54e4aec3 184
mbed_official 130:1dec54e4aec3 185 /*---------------------------- ADCx CFGR Configuration ---------------------*/
mbed_official 130:1dec54e4aec3 186
mbed_official 130:1dec54e4aec3 187 /* Set RES[1:0] bits according to ADC_Resolution value */
mbed_official 130:1dec54e4aec3 188 /* Set CONT bit according to ADC_ContinuousConvMode value */
mbed_official 130:1dec54e4aec3 189 /* Set EXTEN[1:0] bits according to ADC_ExternalTrigConvEdge value */
mbed_official 130:1dec54e4aec3 190 /* Set EXTSEL[2:0] bits according to ADC_ExternalTrigConv value */
mbed_official 130:1dec54e4aec3 191 /* Set ALIGN bit according to ADC_DataAlign value */
mbed_official 130:1dec54e4aec3 192 /* Set SCANDIR bit according to ADC_ScanDirection value */
mbed_official 130:1dec54e4aec3 193
mbed_official 130:1dec54e4aec3 194 tmpreg |= (uint32_t)(ADC_InitStruct->ADC_Resolution | ((uint32_t)(ADC_InitStruct->ADC_ContinuousConvMode) << 13) |
mbed_official 130:1dec54e4aec3 195 ADC_InitStruct->ADC_ExternalTrigConvEdge | ADC_InitStruct->ADC_ExternalTrigConv |
mbed_official 130:1dec54e4aec3 196 ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ScanDirection);
mbed_official 130:1dec54e4aec3 197
mbed_official 130:1dec54e4aec3 198 /* Write to ADCx CFGR */
mbed_official 130:1dec54e4aec3 199 ADCx->CFGR1 = tmpreg;
mbed_official 130:1dec54e4aec3 200 }
mbed_official 130:1dec54e4aec3 201
mbed_official 130:1dec54e4aec3 202 /**
mbed_official 130:1dec54e4aec3 203 * @brief Fills each ADC_InitStruct member with its default value.
mbed_official 130:1dec54e4aec3 204 * @note This function is used to initialize the global features of the ADC (
mbed_official 130:1dec54e4aec3 205 * Resolution, Data Alignment, continuous mode activation, External
mbed_official 130:1dec54e4aec3 206 * trigger source and edge, Sequence Scan Direction).
mbed_official 130:1dec54e4aec3 207 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure which will
mbed_official 130:1dec54e4aec3 208 * be initialized.
mbed_official 130:1dec54e4aec3 209 * @retval None
mbed_official 130:1dec54e4aec3 210 */
mbed_official 130:1dec54e4aec3 211 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
mbed_official 130:1dec54e4aec3 212 {
mbed_official 130:1dec54e4aec3 213 /* Reset ADC init structure parameters values */
mbed_official 130:1dec54e4aec3 214 /* Initialize the ADC_Resolution member */
mbed_official 130:1dec54e4aec3 215 ADC_InitStruct->ADC_Resolution = ADC_Resolution_12b;
mbed_official 130:1dec54e4aec3 216
mbed_official 130:1dec54e4aec3 217 /* Initialize the ADC_ContinuousConvMode member */
mbed_official 130:1dec54e4aec3 218 ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
mbed_official 130:1dec54e4aec3 219
mbed_official 130:1dec54e4aec3 220 /* Initialize the ADC_ExternalTrigConvEdge member */
mbed_official 130:1dec54e4aec3 221 ADC_InitStruct->ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
mbed_official 130:1dec54e4aec3 222
mbed_official 130:1dec54e4aec3 223 /* Initialize the ADC_ExternalTrigConv member */
mbed_official 130:1dec54e4aec3 224 ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO;
mbed_official 130:1dec54e4aec3 225
mbed_official 130:1dec54e4aec3 226 /* Initialize the ADC_DataAlign member */
mbed_official 130:1dec54e4aec3 227 ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
mbed_official 130:1dec54e4aec3 228
mbed_official 130:1dec54e4aec3 229 /* Initialize the ADC_ScanDirection member */
mbed_official 130:1dec54e4aec3 230 ADC_InitStruct->ADC_ScanDirection = ADC_ScanDirection_Upward;
mbed_official 130:1dec54e4aec3 231 }
mbed_official 130:1dec54e4aec3 232
mbed_official 130:1dec54e4aec3 233 /**
mbed_official 130:1dec54e4aec3 234 * @brief Enables or disables the specified ADC peripheral.
mbed_official 130:1dec54e4aec3 235 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 236 * @param NewState: new state of the ADCx peripheral.
mbed_official 130:1dec54e4aec3 237 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 238 * @retval None
mbed_official 130:1dec54e4aec3 239 */
mbed_official 130:1dec54e4aec3 240 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 241 {
mbed_official 130:1dec54e4aec3 242 /* Check the parameters */
mbed_official 130:1dec54e4aec3 243 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 244 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 245
mbed_official 130:1dec54e4aec3 246 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 247 {
mbed_official 130:1dec54e4aec3 248 /* Set the ADEN bit to Enable the ADC peripheral */
mbed_official 130:1dec54e4aec3 249 ADCx->CR |= (uint32_t)ADC_CR_ADEN;
mbed_official 130:1dec54e4aec3 250 }
mbed_official 130:1dec54e4aec3 251 else
mbed_official 130:1dec54e4aec3 252 {
mbed_official 130:1dec54e4aec3 253 /* Set the ADDIS to Disable the ADC peripheral */
mbed_official 130:1dec54e4aec3 254 ADCx->CR |= (uint32_t)ADC_CR_ADDIS;
mbed_official 130:1dec54e4aec3 255 }
mbed_official 130:1dec54e4aec3 256 }
mbed_official 130:1dec54e4aec3 257
mbed_official 130:1dec54e4aec3 258 /**
mbed_official 130:1dec54e4aec3 259 * @brief Configure the ADC to either be clocked by the asynchronous clock(which is
mbed_official 130:1dec54e4aec3 260 * independent, the dedicated 14MHz clock) or the synchronous clock derived from
mbed_official 130:1dec54e4aec3 261 * the APB clock of the ADC bus interface divided by 2 or 4
mbed_official 130:1dec54e4aec3 262 * @note This function can be called only when ADC is disabled.
mbed_official 130:1dec54e4aec3 263 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 264 * @param ADC_ClockMode: This parameter can be :
mbed_official 130:1dec54e4aec3 265 * @arg ADC_ClockMode_AsynClk: ADC clocked by the dedicated 14MHz clock
mbed_official 130:1dec54e4aec3 266 * @arg ADC_ClockMode_SynClkDiv2: ADC clocked by PCLK/2
mbed_official 130:1dec54e4aec3 267 * @arg ADC_ClockMode_SynClkDiv4: ADC clocked by PCLK/4
mbed_official 130:1dec54e4aec3 268 * @retval None
mbed_official 130:1dec54e4aec3 269 */
mbed_official 130:1dec54e4aec3 270 void ADC_ClockModeConfig(ADC_TypeDef* ADCx, uint32_t ADC_ClockMode)
mbed_official 130:1dec54e4aec3 271 {
mbed_official 130:1dec54e4aec3 272 /* Check the parameters */
mbed_official 130:1dec54e4aec3 273 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 274 assert_param(IS_ADC_CLOCKMODE(ADC_ClockMode));
mbed_official 130:1dec54e4aec3 275
mbed_official 130:1dec54e4aec3 276 /* Configure the ADC Clock mode according to ADC_ClockMode */
mbed_official 130:1dec54e4aec3 277 ADCx->CFGR2 = (uint32_t)ADC_ClockMode;
mbed_official 130:1dec54e4aec3 278
mbed_official 130:1dec54e4aec3 279 }
mbed_official 130:1dec54e4aec3 280
mbed_official 130:1dec54e4aec3 281 /**
mbed_official 130:1dec54e4aec3 282 * @brief Enables or disables the jitter when the ADC is clocked by PCLK div2
mbed_official 130:1dec54e4aec3 283 * or div4
mbed_official 130:1dec54e4aec3 284 * @note This function is obsolete and maintained for legacy purpose only. ADC_ClockModeConfig()
mbed_official 130:1dec54e4aec3 285 * function should be used instead.
mbed_official 130:1dec54e4aec3 286 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 287 * @param ADC_JitterOff: This parameter can be :
mbed_official 130:1dec54e4aec3 288 * @arg ADC_JitterOff_PCLKDiv2: Remove jitter when ADC is clocked by PLCK divided by 2
mbed_official 130:1dec54e4aec3 289 * @arg ADC_JitterOff_PCLKDiv4: Remove jitter when ADC is clocked by PLCK divided by 4
mbed_official 130:1dec54e4aec3 290 * @param NewState: new state of the ADCx jitter.
mbed_official 130:1dec54e4aec3 291 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 292 * @retval None
mbed_official 130:1dec54e4aec3 293 */
mbed_official 130:1dec54e4aec3 294 void ADC_JitterCmd(ADC_TypeDef* ADCx, uint32_t ADC_JitterOff, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 295 {
mbed_official 130:1dec54e4aec3 296 /* Check the parameters */
mbed_official 130:1dec54e4aec3 297 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 298 assert_param(IS_ADC_JITTEROFF(ADC_JitterOff));
mbed_official 130:1dec54e4aec3 299 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 300
mbed_official 130:1dec54e4aec3 301 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 302 {
mbed_official 130:1dec54e4aec3 303 /* Disable Jitter */
mbed_official 130:1dec54e4aec3 304 ADCx->CFGR2 |= (uint32_t)ADC_JitterOff;
mbed_official 130:1dec54e4aec3 305 }
mbed_official 130:1dec54e4aec3 306 else
mbed_official 130:1dec54e4aec3 307 {
mbed_official 130:1dec54e4aec3 308 /* Enable Jitter */
mbed_official 130:1dec54e4aec3 309 ADCx->CFGR2 &= (uint32_t)(~ADC_JitterOff);
mbed_official 130:1dec54e4aec3 310 }
mbed_official 130:1dec54e4aec3 311 }
mbed_official 130:1dec54e4aec3 312
mbed_official 130:1dec54e4aec3 313 /**
mbed_official 130:1dec54e4aec3 314 * @}
mbed_official 130:1dec54e4aec3 315 */
mbed_official 130:1dec54e4aec3 316
mbed_official 130:1dec54e4aec3 317 /** @defgroup ADC_Group2 Power saving functions
mbed_official 130:1dec54e4aec3 318 * @brief Power saving functions
mbed_official 130:1dec54e4aec3 319 *
mbed_official 130:1dec54e4aec3 320 @verbatim
mbed_official 130:1dec54e4aec3 321 ===============================================================================
mbed_official 130:1dec54e4aec3 322 ##### Power saving functions #####
mbed_official 130:1dec54e4aec3 323 ===============================================================================
mbed_official 130:1dec54e4aec3 324 [..] This section provides functions allowing to reduce power consumption.
mbed_official 130:1dec54e4aec3 325 [..] The two function must be combined to get the maximal benefits:
mbed_official 130:1dec54e4aec3 326 When the ADC frequency is higher than the CPU one, it is recommended to
mbed_official 130:1dec54e4aec3 327 (#) Enable the Auto Delayed Conversion mode :
mbed_official 130:1dec54e4aec3 328 ==> using ADC_WaitModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 329 (#) Enable the power off in Delay phases :
mbed_official 130:1dec54e4aec3 330 ==> using ADC_AutoPowerOffCmd(ADC_TypeDef* ADCx, FunctionalState NewState);
mbed_official 130:1dec54e4aec3 331
mbed_official 130:1dec54e4aec3 332 @endverbatim
mbed_official 130:1dec54e4aec3 333 * @{
mbed_official 130:1dec54e4aec3 334 */
mbed_official 130:1dec54e4aec3 335
mbed_official 130:1dec54e4aec3 336 /**
mbed_official 130:1dec54e4aec3 337 * @brief Enables or disables the ADC Power Off.
mbed_official 130:1dec54e4aec3 338 * @note ADC power-on and power-off can be managed by hardware to cut the
mbed_official 130:1dec54e4aec3 339 * consumption when the ADC is not converting.
mbed_official 130:1dec54e4aec3 340 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 341 * @note The ADC can be powered down:
mbed_official 130:1dec54e4aec3 342 * - During the Auto delay phase: The ADC is powered on again at the end
mbed_official 130:1dec54e4aec3 343 * of the delay (until the previous data is read from the ADC data register).
mbed_official 130:1dec54e4aec3 344 * - During the ADC is waiting for a trigger event: The ADC is powered up
mbed_official 130:1dec54e4aec3 345 * at the next trigger event (when the conversion is started).
mbed_official 130:1dec54e4aec3 346 * @param NewState: new state of the ADCx power Off.
mbed_official 130:1dec54e4aec3 347 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 348 * @retval None
mbed_official 130:1dec54e4aec3 349 */
mbed_official 130:1dec54e4aec3 350 void ADC_AutoPowerOffCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 351 {
mbed_official 130:1dec54e4aec3 352 /* Check the parameters */
mbed_official 130:1dec54e4aec3 353 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 354 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 355
mbed_official 130:1dec54e4aec3 356 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 357 {
mbed_official 130:1dec54e4aec3 358 /* Enable the ADC Automatic Power-Off */
mbed_official 130:1dec54e4aec3 359 ADCx->CFGR1 |= ADC_CFGR1_AUTOFF;
mbed_official 130:1dec54e4aec3 360 }
mbed_official 130:1dec54e4aec3 361 else
mbed_official 130:1dec54e4aec3 362 {
mbed_official 130:1dec54e4aec3 363 /* Disable the ADC Automatic Power-Off */
mbed_official 130:1dec54e4aec3 364 ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_AUTOFF;
mbed_official 130:1dec54e4aec3 365 }
mbed_official 130:1dec54e4aec3 366 }
mbed_official 130:1dec54e4aec3 367
mbed_official 130:1dec54e4aec3 368 /**
mbed_official 130:1dec54e4aec3 369 * @brief Enables or disables the Wait conversion mode.
mbed_official 130:1dec54e4aec3 370 * @note When the CPU clock is not fast enough to manage the data rate, a
mbed_official 130:1dec54e4aec3 371 * Hardware delay can be introduced between ADC conversions to reduce
mbed_official 130:1dec54e4aec3 372 * this data rate.
mbed_official 130:1dec54e4aec3 373 * @note The Hardware delay is inserted after each conversions and until the
mbed_official 130:1dec54e4aec3 374 * previous data is read from the ADC data register
mbed_official 130:1dec54e4aec3 375 * @note This is a way to automatically adapt the speed of the ADC to the speed
mbed_official 130:1dec54e4aec3 376 * of the system which will read the data.
mbed_official 130:1dec54e4aec3 377 * @note Any hardware triggers wich occur while a conversion is on going or
mbed_official 130:1dec54e4aec3 378 * while the automatic Delay is applied are ignored
mbed_official 130:1dec54e4aec3 379 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 380 * @param NewState: new state of the ADCx Auto-Delay.
mbed_official 130:1dec54e4aec3 381 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 382 * @retval None
mbed_official 130:1dec54e4aec3 383 */
mbed_official 130:1dec54e4aec3 384 void ADC_WaitModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 385 {
mbed_official 130:1dec54e4aec3 386 /* Check the parameters */
mbed_official 130:1dec54e4aec3 387 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 388 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 389
mbed_official 130:1dec54e4aec3 390 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 391 {
mbed_official 130:1dec54e4aec3 392 /* Enable the ADC Automatic Delayed conversion */
mbed_official 130:1dec54e4aec3 393 ADCx->CFGR1 |= ADC_CFGR1_WAIT;
mbed_official 130:1dec54e4aec3 394 }
mbed_official 130:1dec54e4aec3 395 else
mbed_official 130:1dec54e4aec3 396 {
mbed_official 130:1dec54e4aec3 397 /* Disable the ADC Automatic Delayed conversion */
mbed_official 130:1dec54e4aec3 398 ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_WAIT;
mbed_official 130:1dec54e4aec3 399 }
mbed_official 130:1dec54e4aec3 400 }
mbed_official 130:1dec54e4aec3 401
mbed_official 130:1dec54e4aec3 402 /**
mbed_official 130:1dec54e4aec3 403 * @}
mbed_official 130:1dec54e4aec3 404 */
mbed_official 130:1dec54e4aec3 405
mbed_official 130:1dec54e4aec3 406 /** @defgroup ADC_Group3 Analog Watchdog configuration functions
mbed_official 130:1dec54e4aec3 407 * @brief Analog Watchdog configuration functions
mbed_official 130:1dec54e4aec3 408 *
mbed_official 130:1dec54e4aec3 409 @verbatim
mbed_official 130:1dec54e4aec3 410 ===============================================================================
mbed_official 130:1dec54e4aec3 411 ##### Analog Watchdog configuration functions #####
mbed_official 130:1dec54e4aec3 412 ===============================================================================
mbed_official 130:1dec54e4aec3 413 [..] This section provides functions allowing to configure the Analog Watchdog
mbed_official 130:1dec54e4aec3 414 (AWD) feature in the ADC.
mbed_official 130:1dec54e4aec3 415 [..] A typical configuration Analog Watchdog is done following these steps :
mbed_official 130:1dec54e4aec3 416 (#) the ADC guarded channel(s) is (are) selected using the
mbed_official 130:1dec54e4aec3 417 ADC_AnalogWatchdogSingleChannelConfig() function.
mbed_official 130:1dec54e4aec3 418 (#) The Analog watchdog lower and higher threshold are configured using the
mbed_official 130:1dec54e4aec3 419 ADC_AnalogWatchdogThresholdsConfig() function.
mbed_official 130:1dec54e4aec3 420 (#) The Analog watchdog is enabled and configured to enable the check, on one
mbed_official 130:1dec54e4aec3 421 or more channels, using the ADC_AnalogWatchdogCmd() function.
mbed_official 130:1dec54e4aec3 422 (#) Enable the analog watchdog on the selected channel using
mbed_official 130:1dec54e4aec3 423 ADC_AnalogWatchdogSingleChannelCmd() function
mbed_official 130:1dec54e4aec3 424
mbed_official 130:1dec54e4aec3 425 @endverbatim
mbed_official 130:1dec54e4aec3 426 * @{
mbed_official 130:1dec54e4aec3 427 */
mbed_official 130:1dec54e4aec3 428
mbed_official 130:1dec54e4aec3 429 /**
mbed_official 130:1dec54e4aec3 430 * @brief Enables or disables the analog watchdog
mbed_official 130:1dec54e4aec3 431 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 432 * @param NewState: new state of the ADCx Analog Watchdog.
mbed_official 130:1dec54e4aec3 433 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 434 * @retval None
mbed_official 130:1dec54e4aec3 435 */
mbed_official 130:1dec54e4aec3 436 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 437 {
mbed_official 130:1dec54e4aec3 438 /* Check the parameters */
mbed_official 130:1dec54e4aec3 439 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 440 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 441
mbed_official 130:1dec54e4aec3 442 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 443 {
mbed_official 130:1dec54e4aec3 444 /* Enable the ADC Analog Watchdog */
mbed_official 130:1dec54e4aec3 445 ADCx->CFGR1 |= ADC_CFGR1_AWDEN;
mbed_official 130:1dec54e4aec3 446 }
mbed_official 130:1dec54e4aec3 447 else
mbed_official 130:1dec54e4aec3 448 {
mbed_official 130:1dec54e4aec3 449 /* Disable the ADC Analog Watchdog */
mbed_official 130:1dec54e4aec3 450 ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_AWDEN;
mbed_official 130:1dec54e4aec3 451 }
mbed_official 130:1dec54e4aec3 452 }
mbed_official 130:1dec54e4aec3 453
mbed_official 130:1dec54e4aec3 454 /**
mbed_official 130:1dec54e4aec3 455 * @brief Configures the high and low thresholds of the analog watchdog.
mbed_official 130:1dec54e4aec3 456 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 457 * @param HighThreshold: the ADC analog watchdog High threshold value.
mbed_official 130:1dec54e4aec3 458 * This parameter must be a 12bit value.
mbed_official 130:1dec54e4aec3 459 * @param LowThreshold: the ADC analog watchdog Low threshold value.
mbed_official 130:1dec54e4aec3 460 * This parameter must be a 12bit value.
mbed_official 130:1dec54e4aec3 461 * @retval None
mbed_official 130:1dec54e4aec3 462 */
mbed_official 130:1dec54e4aec3 463 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,
mbed_official 130:1dec54e4aec3 464 uint16_t LowThreshold)
mbed_official 130:1dec54e4aec3 465 {
mbed_official 130:1dec54e4aec3 466 /* Check the parameters */
mbed_official 130:1dec54e4aec3 467 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 468 assert_param(IS_ADC_THRESHOLD(HighThreshold));
mbed_official 130:1dec54e4aec3 469 assert_param(IS_ADC_THRESHOLD(LowThreshold));
mbed_official 130:1dec54e4aec3 470
mbed_official 130:1dec54e4aec3 471 /* Set the ADCx high and low threshold */
mbed_official 130:1dec54e4aec3 472 ADCx->TR = LowThreshold | ((uint32_t)HighThreshold << 16);
mbed_official 130:1dec54e4aec3 473
mbed_official 130:1dec54e4aec3 474 }
mbed_official 130:1dec54e4aec3 475
mbed_official 130:1dec54e4aec3 476 /**
mbed_official 130:1dec54e4aec3 477 * @brief Configures the analog watchdog guarded single channel
mbed_official 130:1dec54e4aec3 478 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 479 * @param ADC_AnalogWatchdog_Channel: the ADC channel to configure for the analog watchdog.
mbed_official 130:1dec54e4aec3 480 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 481 * @arg ADC_AnalogWatchdog_Channel_0: ADC Channel0 selected
mbed_official 130:1dec54e4aec3 482 * @arg ADC_AnalogWatchdog_Channel_1: ADC Channel1 selected
mbed_official 130:1dec54e4aec3 483 * @arg ADC_AnalogWatchdog_Channel_2: ADC Channel2 selected
mbed_official 130:1dec54e4aec3 484 * @arg ADC_AnalogWatchdog_Channel_3: ADC Channel3 selected
mbed_official 130:1dec54e4aec3 485 * @arg ADC_AnalogWatchdog_Channel_4: ADC Channel4 selected
mbed_official 130:1dec54e4aec3 486 * @arg ADC_AnalogWatchdog_Channel_5: ADC Channel5 selected
mbed_official 130:1dec54e4aec3 487 * @arg ADC_AnalogWatchdog_Channel_6: ADC Channel6 selected
mbed_official 130:1dec54e4aec3 488 * @arg ADC_AnalogWatchdog_Channel_7: ADC Channel7 selected
mbed_official 130:1dec54e4aec3 489 * @arg ADC_AnalogWatchdog_Channel_8: ADC Channel8 selected
mbed_official 130:1dec54e4aec3 490 * @arg ADC_AnalogWatchdog_Channel_9: ADC Channel9 selected
mbed_official 130:1dec54e4aec3 491 * @arg ADC_AnalogWatchdog_Channel_10: ADC Channel10 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 492 * @arg ADC_AnalogWatchdog_Channel_11: ADC Channel11 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 493 * @arg ADC_AnalogWatchdog_Channel_12: ADC Channel12 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 494 * @arg ADC_AnalogWatchdog_Channel_13: ADC Channel13 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 495 * @arg ADC_AnalogWatchdog_Channel_14: ADC Channel14 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 496 * @arg ADC_AnalogWatchdog_Channel_15: ADC Channel15 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 497 * @arg ADC_AnalogWatchdog_Channel_16: ADC Channel16 selected
mbed_official 130:1dec54e4aec3 498 * @arg ADC_AnalogWatchdog_Channel_17: ADC Channel17 selected
mbed_official 130:1dec54e4aec3 499 * @arg ADC_AnalogWatchdog_Channel_18: ADC Channel18 selected, not available for STM32F030 devices
mbed_official 130:1dec54e4aec3 500 * @note The channel selected on the AWDCH must be also set into the CHSELR
mbed_official 130:1dec54e4aec3 501 * register
mbed_official 130:1dec54e4aec3 502 * @retval None
mbed_official 130:1dec54e4aec3 503 */
mbed_official 130:1dec54e4aec3 504 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog_Channel)
mbed_official 130:1dec54e4aec3 505 {
mbed_official 130:1dec54e4aec3 506 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 507
mbed_official 130:1dec54e4aec3 508 /* Check the parameters */
mbed_official 130:1dec54e4aec3 509 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 510 assert_param(IS_ADC_ANALOG_WATCHDOG_CHANNEL(ADC_AnalogWatchdog_Channel));
mbed_official 130:1dec54e4aec3 511
mbed_official 130:1dec54e4aec3 512 /* Get the old register value */
mbed_official 130:1dec54e4aec3 513 tmpreg = ADCx->CFGR1;
mbed_official 130:1dec54e4aec3 514
mbed_official 130:1dec54e4aec3 515 /* Clear the Analog watchdog channel select bits */
mbed_official 130:1dec54e4aec3 516 tmpreg &= ~ADC_CFGR1_AWDCH;
mbed_official 130:1dec54e4aec3 517
mbed_official 130:1dec54e4aec3 518 /* Set the Analog watchdog channel */
mbed_official 130:1dec54e4aec3 519 tmpreg |= ADC_AnalogWatchdog_Channel;
mbed_official 130:1dec54e4aec3 520
mbed_official 130:1dec54e4aec3 521 /* Store the new register value */
mbed_official 130:1dec54e4aec3 522 ADCx->CFGR1 = tmpreg;
mbed_official 130:1dec54e4aec3 523 }
mbed_official 130:1dec54e4aec3 524
mbed_official 130:1dec54e4aec3 525 /**
mbed_official 130:1dec54e4aec3 526 * @brief Enables or disables the ADC Analog Watchdog Single Channel.
mbed_official 130:1dec54e4aec3 527 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 528 * @param NewState: new state of the ADCx ADC Analog Watchdog Single Channel.
mbed_official 130:1dec54e4aec3 529 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 530 * @retval None
mbed_official 130:1dec54e4aec3 531 */
mbed_official 130:1dec54e4aec3 532 void ADC_AnalogWatchdogSingleChannelCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 533 {
mbed_official 130:1dec54e4aec3 534 /* Check the parameters */
mbed_official 130:1dec54e4aec3 535 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 536 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 537
mbed_official 130:1dec54e4aec3 538 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 539 {
mbed_official 130:1dec54e4aec3 540 /* Enable the ADC Analog Watchdog Single Channel */
mbed_official 130:1dec54e4aec3 541 ADCx->CFGR1 |= ADC_CFGR1_AWDSGL;
mbed_official 130:1dec54e4aec3 542 }
mbed_official 130:1dec54e4aec3 543 else
mbed_official 130:1dec54e4aec3 544 {
mbed_official 130:1dec54e4aec3 545 /* Disable the ADC Analog Watchdog Single Channel */
mbed_official 130:1dec54e4aec3 546 ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_AWDSGL;
mbed_official 130:1dec54e4aec3 547 }
mbed_official 130:1dec54e4aec3 548 }
mbed_official 130:1dec54e4aec3 549
mbed_official 130:1dec54e4aec3 550 /**
mbed_official 130:1dec54e4aec3 551 * @}
mbed_official 130:1dec54e4aec3 552 */
mbed_official 130:1dec54e4aec3 553
mbed_official 130:1dec54e4aec3 554 /** @defgroup ADC_Group4 Temperature Sensor, Vrefint and Vbat management functions
mbed_official 130:1dec54e4aec3 555 * @brief Temperature Sensor, Vrefint and Vbat management functions
mbed_official 130:1dec54e4aec3 556 *
mbed_official 130:1dec54e4aec3 557 @verbatim
mbed_official 130:1dec54e4aec3 558 ===============================================================================
mbed_official 130:1dec54e4aec3 559 ##### Temperature Sensor, Vrefint and Vbat management function #####
mbed_official 130:1dec54e4aec3 560 ===============================================================================
mbed_official 130:1dec54e4aec3 561 [..] This section provides a function allowing to enable/disable the internal
mbed_official 130:1dec54e4aec3 562 connections between the ADC and the Temperature Sensor, the Vrefint and
mbed_official 130:1dec54e4aec3 563 Vbat source.
mbed_official 130:1dec54e4aec3 564
mbed_official 130:1dec54e4aec3 565 [..] A typical configuration to get the Temperature sensor, Vrefint and Vbat channels
mbed_official 130:1dec54e4aec3 566 voltages is done following these steps :
mbed_official 130:1dec54e4aec3 567 (#) Enable the internal connection of Temperature sensor, Vrefint or Vbat sources
mbed_official 130:1dec54e4aec3 568 with the ADC channels using ADC_TempSensorCmd(), ADC_VrefintCmd() or ADC_VbatCmd()
mbed_official 130:1dec54e4aec3 569 functions.
mbed_official 130:1dec54e4aec3 570 (#) select the ADC_Channel_16(Temperature sensor), ADC_Channel_17(Vrefint)
mbed_official 130:1dec54e4aec3 571 or ADC_Channel_18(Voltage battery) using ADC_ChannelConfig() function
mbed_official 130:1dec54e4aec3 572 (#) Get the voltage values, using ADC_GetConversionValue() function
mbed_official 130:1dec54e4aec3 573
mbed_official 130:1dec54e4aec3 574 @endverbatim
mbed_official 130:1dec54e4aec3 575 * @{
mbed_official 130:1dec54e4aec3 576 */
mbed_official 130:1dec54e4aec3 577
mbed_official 130:1dec54e4aec3 578 /**
mbed_official 130:1dec54e4aec3 579 * @brief Enables or disables the temperature sensor channel.
mbed_official 130:1dec54e4aec3 580 * @param NewState: new state of the temperature sensor input channel.
mbed_official 130:1dec54e4aec3 581 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 582 * @retval None
mbed_official 130:1dec54e4aec3 583 */
mbed_official 130:1dec54e4aec3 584 void ADC_TempSensorCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 585 {
mbed_official 130:1dec54e4aec3 586 /* Check the parameters */
mbed_official 130:1dec54e4aec3 587 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 588
mbed_official 130:1dec54e4aec3 589 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 590 {
mbed_official 130:1dec54e4aec3 591 /* Enable the temperature sensor channel*/
mbed_official 130:1dec54e4aec3 592 ADC->CCR |= (uint32_t)ADC_CCR_TSEN;
mbed_official 130:1dec54e4aec3 593 }
mbed_official 130:1dec54e4aec3 594 else
mbed_official 130:1dec54e4aec3 595 {
mbed_official 130:1dec54e4aec3 596 /* Disable the temperature sensor channel*/
mbed_official 130:1dec54e4aec3 597 ADC->CCR &= (uint32_t)(~ADC_CCR_TSEN);
mbed_official 130:1dec54e4aec3 598 }
mbed_official 130:1dec54e4aec3 599 }
mbed_official 130:1dec54e4aec3 600
mbed_official 130:1dec54e4aec3 601 /**
mbed_official 130:1dec54e4aec3 602 * @brief Enables or disables the Vrefint channel.
mbed_official 130:1dec54e4aec3 603 * @param NewState: new state of the Vref input channel.
mbed_official 130:1dec54e4aec3 604 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 605 * @retval None
mbed_official 130:1dec54e4aec3 606 */
mbed_official 130:1dec54e4aec3 607 void ADC_VrefintCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 608 {
mbed_official 130:1dec54e4aec3 609 /* Check the parameters */
mbed_official 130:1dec54e4aec3 610 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 611
mbed_official 130:1dec54e4aec3 612 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 613 {
mbed_official 130:1dec54e4aec3 614 /* Enable the Vrefint channel*/
mbed_official 130:1dec54e4aec3 615 ADC->CCR |= (uint32_t)ADC_CCR_VREFEN;
mbed_official 130:1dec54e4aec3 616 }
mbed_official 130:1dec54e4aec3 617 else
mbed_official 130:1dec54e4aec3 618 {
mbed_official 130:1dec54e4aec3 619 /* Disable the Vrefint channel*/
mbed_official 130:1dec54e4aec3 620 ADC->CCR &= (uint32_t)(~ADC_CCR_VREFEN);
mbed_official 130:1dec54e4aec3 621 }
mbed_official 130:1dec54e4aec3 622 }
mbed_official 130:1dec54e4aec3 623
mbed_official 130:1dec54e4aec3 624 /**
mbed_official 130:1dec54e4aec3 625 * @brief Enables or disables the Vbat channel.
mbed_official 130:1dec54e4aec3 626 * @note This feature is not applicable for STM32F030 devices.
mbed_official 130:1dec54e4aec3 627 * @param NewState: new state of the Vbat input channel.
mbed_official 130:1dec54e4aec3 628 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 629 * @retval None
mbed_official 130:1dec54e4aec3 630 */
mbed_official 130:1dec54e4aec3 631 void ADC_VbatCmd(FunctionalState NewState)
mbed_official 130:1dec54e4aec3 632 {
mbed_official 130:1dec54e4aec3 633 /* Check the parameters */
mbed_official 130:1dec54e4aec3 634 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 635
mbed_official 130:1dec54e4aec3 636 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 637 {
mbed_official 130:1dec54e4aec3 638 /* Enable the Vbat channel*/
mbed_official 130:1dec54e4aec3 639 ADC->CCR |= (uint32_t)ADC_CCR_VBATEN;
mbed_official 130:1dec54e4aec3 640 }
mbed_official 130:1dec54e4aec3 641 else
mbed_official 130:1dec54e4aec3 642 {
mbed_official 130:1dec54e4aec3 643 /* Disable the Vbat channel*/
mbed_official 130:1dec54e4aec3 644 ADC->CCR &= (uint32_t)(~ADC_CCR_VBATEN);
mbed_official 130:1dec54e4aec3 645 }
mbed_official 130:1dec54e4aec3 646 }
mbed_official 130:1dec54e4aec3 647
mbed_official 130:1dec54e4aec3 648 /**
mbed_official 130:1dec54e4aec3 649 * @}
mbed_official 130:1dec54e4aec3 650 */
mbed_official 130:1dec54e4aec3 651
mbed_official 130:1dec54e4aec3 652 /** @defgroup ADC_Group5 Channels Configuration functions
mbed_official 130:1dec54e4aec3 653 * @brief Channels Configuration functions
mbed_official 130:1dec54e4aec3 654 *
mbed_official 130:1dec54e4aec3 655 @verbatim
mbed_official 130:1dec54e4aec3 656 ===============================================================================
mbed_official 130:1dec54e4aec3 657 ##### Channels Configuration functions #####
mbed_official 130:1dec54e4aec3 658 ===============================================================================
mbed_official 130:1dec54e4aec3 659 [..] This section provides functions allowing to manage the ADC channels,
mbed_official 130:1dec54e4aec3 660 it is composed of 3 sub sections :
mbed_official 130:1dec54e4aec3 661 (#) Configuration and management functions for ADC channels: This subsection
mbed_official 130:1dec54e4aec3 662 provides functions allowing to configure the ADC channels :
mbed_official 130:1dec54e4aec3 663 (++) Select the ADC channels
mbed_official 130:1dec54e4aec3 664 (++) Activate ADC Calibration
mbed_official 130:1dec54e4aec3 665 (++) Activate the Overrun Mode.
mbed_official 130:1dec54e4aec3 666 (++) Activate the Discontinuous Mode
mbed_official 130:1dec54e4aec3 667 (++) Activate the Continuous Mode.
mbed_official 130:1dec54e4aec3 668 (++) Configure the sampling time for each channel
mbed_official 130:1dec54e4aec3 669 (++) Select the conversion Trigger and Edge for ADC channels
mbed_official 130:1dec54e4aec3 670 (++) Select the scan direction.
mbed_official 130:1dec54e4aec3 671 -@@- Please Note that the following features for ADC channels are configurated
mbed_official 130:1dec54e4aec3 672 using the ADC_Init() function :
mbed_official 130:1dec54e4aec3 673 (+@@) Activate the Continuous Mode (can be also activated by ADC_OverrunModeCmd().
mbed_official 130:1dec54e4aec3 674 (+@@) Select the conversion Trigger and Edge for ADC channels
mbed_official 130:1dec54e4aec3 675 (+@@) Select the scan direction.
mbed_official 130:1dec54e4aec3 676 (#) Control the ADC peripheral : This subsection permits to command the ADC:
mbed_official 130:1dec54e4aec3 677 (++) Stop or discard an on-going conversion (ADSTP command)
mbed_official 130:1dec54e4aec3 678 (++) Start the ADC conversion .
mbed_official 130:1dec54e4aec3 679 (#) Get the conversion data: This subsection provides an important function in
mbed_official 130:1dec54e4aec3 680 the ADC peripheral since it returns the converted data of the current
mbed_official 130:1dec54e4aec3 681 ADC channel. When the Conversion value is read, the EOC Flag is
mbed_official 130:1dec54e4aec3 682 automatically cleared.
mbed_official 130:1dec54e4aec3 683
mbed_official 130:1dec54e4aec3 684 @endverbatim
mbed_official 130:1dec54e4aec3 685 * @{
mbed_official 130:1dec54e4aec3 686 */
mbed_official 130:1dec54e4aec3 687
mbed_official 130:1dec54e4aec3 688 /**
mbed_official 130:1dec54e4aec3 689 * @brief Configures for the selected ADC and its sampling time.
mbed_official 130:1dec54e4aec3 690 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 130:1dec54e4aec3 691 * @param ADC_Channel: the ADC channel to configure.
mbed_official 130:1dec54e4aec3 692 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 693 * @arg ADC_Channel_0: ADC Channel0 selected
mbed_official 130:1dec54e4aec3 694 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 130:1dec54e4aec3 695 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 130:1dec54e4aec3 696 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 130:1dec54e4aec3 697 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 130:1dec54e4aec3 698 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 130:1dec54e4aec3 699 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 130:1dec54e4aec3 700 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 130:1dec54e4aec3 701 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 130:1dec54e4aec3 702 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 130:1dec54e4aec3 703 * @arg ADC_Channel_10: ADC Channel10 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 704 * @arg ADC_Channel_11: ADC Channel11 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 705 * @arg ADC_Channel_12: ADC Channel12 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 706 * @arg ADC_Channel_13: ADC Channel13 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 707 * @arg ADC_Channel_14: ADC Channel14 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 708 * @arg ADC_Channel_15: ADC Channel15 selected, not available for STM32F031 devices
mbed_official 130:1dec54e4aec3 709 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 130:1dec54e4aec3 710 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 130:1dec54e4aec3 711 * @arg ADC_Channel_18: ADC Channel18 selected, not available for STM32F030 devices
mbed_official 130:1dec54e4aec3 712 * @param ADC_SampleTime: The sample time value to be set for the selected channel.
mbed_official 130:1dec54e4aec3 713 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 714 * @arg ADC_SampleTime_1_5Cycles: Sample time equal to 1.5 cycles
mbed_official 130:1dec54e4aec3 715 * @arg ADC_SampleTime_7_5Cycles: Sample time equal to 7.5 cycles
mbed_official 130:1dec54e4aec3 716 * @arg ADC_SampleTime_13_5Cycles: Sample time equal to 13.5 cycles
mbed_official 130:1dec54e4aec3 717 * @arg ADC_SampleTime_28_5Cycles: Sample time equal to 28.5 cycles
mbed_official 130:1dec54e4aec3 718 * @arg ADC_SampleTime_41_5Cycles: Sample time equal to 41.5 cycles
mbed_official 130:1dec54e4aec3 719 * @arg ADC_SampleTime_55_5Cycles: Sample time equal to 55.5 cycles
mbed_official 130:1dec54e4aec3 720 * @arg ADC_SampleTime_71_5Cycles: Sample time equal to 71.5 cycles
mbed_official 130:1dec54e4aec3 721 * @arg ADC_SampleTime_239_5Cycles: Sample time equal to 239.5 cycles
mbed_official 130:1dec54e4aec3 722 * @retval None
mbed_official 130:1dec54e4aec3 723 */
mbed_official 130:1dec54e4aec3 724 void ADC_ChannelConfig(ADC_TypeDef* ADCx, uint32_t ADC_Channel, uint32_t ADC_SampleTime)
mbed_official 130:1dec54e4aec3 725 {
mbed_official 130:1dec54e4aec3 726 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 727
mbed_official 130:1dec54e4aec3 728 /* Check the parameters */
mbed_official 130:1dec54e4aec3 729 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 730 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 130:1dec54e4aec3 731 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
mbed_official 130:1dec54e4aec3 732
mbed_official 130:1dec54e4aec3 733 /* Configure the ADC Channel */
mbed_official 130:1dec54e4aec3 734 ADCx->CHSELR |= (uint32_t)ADC_Channel;
mbed_official 130:1dec54e4aec3 735
mbed_official 130:1dec54e4aec3 736 /* Clear the Sampling time Selection bits */
mbed_official 130:1dec54e4aec3 737 tmpreg &= ~ADC_SMPR1_SMPR;
mbed_official 130:1dec54e4aec3 738
mbed_official 130:1dec54e4aec3 739 /* Set the ADC Sampling Time register */
mbed_official 130:1dec54e4aec3 740 tmpreg |= (uint32_t)ADC_SampleTime;
mbed_official 130:1dec54e4aec3 741
mbed_official 130:1dec54e4aec3 742 /* Configure the ADC Sample time register */
mbed_official 130:1dec54e4aec3 743 ADCx->SMPR = tmpreg ;
mbed_official 130:1dec54e4aec3 744 }
mbed_official 130:1dec54e4aec3 745
mbed_official 130:1dec54e4aec3 746 /**
mbed_official 130:1dec54e4aec3 747 * @brief Enable the Continuous mode for the selected ADCx channels.
mbed_official 130:1dec54e4aec3 748 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 749 * @param NewState: new state of the Continuous mode.
mbed_official 130:1dec54e4aec3 750 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 751 * @note It is not possible to have both discontinuous mode and continuous mode
mbed_official 130:1dec54e4aec3 752 * enabled. In this case (If DISCEN and CONT are Set), the ADC behaves
mbed_official 130:1dec54e4aec3 753 * as if continuous mode was disabled
mbed_official 130:1dec54e4aec3 754 * @retval None
mbed_official 130:1dec54e4aec3 755 */
mbed_official 130:1dec54e4aec3 756 void ADC_ContinuousModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 757 {
mbed_official 130:1dec54e4aec3 758 /* Check the parameters */
mbed_official 130:1dec54e4aec3 759 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 760 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 761
mbed_official 130:1dec54e4aec3 762 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 763 {
mbed_official 130:1dec54e4aec3 764 /* Enable the Continuous mode*/
mbed_official 130:1dec54e4aec3 765 ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_CONT;
mbed_official 130:1dec54e4aec3 766 }
mbed_official 130:1dec54e4aec3 767 else
mbed_official 130:1dec54e4aec3 768 {
mbed_official 130:1dec54e4aec3 769 /* Disable the Continuous mode */
mbed_official 130:1dec54e4aec3 770 ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_CONT);
mbed_official 130:1dec54e4aec3 771 }
mbed_official 130:1dec54e4aec3 772 }
mbed_official 130:1dec54e4aec3 773
mbed_official 130:1dec54e4aec3 774 /**
mbed_official 130:1dec54e4aec3 775 * @brief Enable the discontinuous mode for the selected ADC channels.
mbed_official 130:1dec54e4aec3 776 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 777 * @param NewState: new state of the discontinuous mode.
mbed_official 130:1dec54e4aec3 778 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 779 * @note It is not possible to have both discontinuous mode and continuous mode
mbed_official 130:1dec54e4aec3 780 * enabled. In this case (If DISCEN and CONT are Set), the ADC behaves
mbed_official 130:1dec54e4aec3 781 * as if continuous mode was disabled
mbed_official 130:1dec54e4aec3 782 * @retval None
mbed_official 130:1dec54e4aec3 783 */
mbed_official 130:1dec54e4aec3 784 void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 785 {
mbed_official 130:1dec54e4aec3 786 /* Check the parameters */
mbed_official 130:1dec54e4aec3 787 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 788 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 789
mbed_official 130:1dec54e4aec3 790 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 791 {
mbed_official 130:1dec54e4aec3 792 /* Enable the Discontinuous mode */
mbed_official 130:1dec54e4aec3 793 ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_DISCEN;
mbed_official 130:1dec54e4aec3 794 }
mbed_official 130:1dec54e4aec3 795 else
mbed_official 130:1dec54e4aec3 796 {
mbed_official 130:1dec54e4aec3 797 /* Disable the Discontinuous mode */
mbed_official 130:1dec54e4aec3 798 ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_DISCEN);
mbed_official 130:1dec54e4aec3 799 }
mbed_official 130:1dec54e4aec3 800 }
mbed_official 130:1dec54e4aec3 801
mbed_official 130:1dec54e4aec3 802 /**
mbed_official 130:1dec54e4aec3 803 * @brief Enable the Overrun mode for the selected ADC channels.
mbed_official 130:1dec54e4aec3 804 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 805 * @param NewState: new state of the Overrun mode.
mbed_official 130:1dec54e4aec3 806 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 807 * @retval None
mbed_official 130:1dec54e4aec3 808 */
mbed_official 130:1dec54e4aec3 809 void ADC_OverrunModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 810 {
mbed_official 130:1dec54e4aec3 811 /* Check the parameters */
mbed_official 130:1dec54e4aec3 812 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 813 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 814
mbed_official 130:1dec54e4aec3 815 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 816 {
mbed_official 130:1dec54e4aec3 817 /* Enable the Overrun mode */
mbed_official 130:1dec54e4aec3 818 ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_OVRMOD;
mbed_official 130:1dec54e4aec3 819 }
mbed_official 130:1dec54e4aec3 820 else
mbed_official 130:1dec54e4aec3 821 {
mbed_official 130:1dec54e4aec3 822 /* Disable the Overrun mode */
mbed_official 130:1dec54e4aec3 823 ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_OVRMOD);
mbed_official 130:1dec54e4aec3 824 }
mbed_official 130:1dec54e4aec3 825 }
mbed_official 130:1dec54e4aec3 826
mbed_official 130:1dec54e4aec3 827 /**
mbed_official 130:1dec54e4aec3 828 * @brief Active the Calibration operation for the selected ADC.
mbed_official 130:1dec54e4aec3 829 * @note The Calibration can be initiated only when ADC is still in the
mbed_official 130:1dec54e4aec3 830 * reset configuration (ADEN must be equal to 0).
mbed_official 130:1dec54e4aec3 831 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 832 * @retval ADC Calibration factor
mbed_official 130:1dec54e4aec3 833 */
mbed_official 130:1dec54e4aec3 834 uint32_t ADC_GetCalibrationFactor(ADC_TypeDef* ADCx)
mbed_official 130:1dec54e4aec3 835 {
mbed_official 130:1dec54e4aec3 836 uint32_t tmpreg = 0, calibrationcounter = 0, calibrationstatus = 0;
mbed_official 130:1dec54e4aec3 837
mbed_official 130:1dec54e4aec3 838 /* Check the parameters */
mbed_official 130:1dec54e4aec3 839 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 840
mbed_official 130:1dec54e4aec3 841 /* Set the ADC calibartion */
mbed_official 130:1dec54e4aec3 842 ADCx->CR |= (uint32_t)ADC_CR_ADCAL;
mbed_official 130:1dec54e4aec3 843
mbed_official 130:1dec54e4aec3 844 /* Wait until no ADC calibration is completed */
mbed_official 130:1dec54e4aec3 845 do
mbed_official 130:1dec54e4aec3 846 {
mbed_official 130:1dec54e4aec3 847 calibrationstatus = ADCx->CR & ADC_CR_ADCAL;
mbed_official 130:1dec54e4aec3 848 calibrationcounter++;
mbed_official 130:1dec54e4aec3 849 } while((calibrationcounter != CALIBRATION_TIMEOUT) && (calibrationstatus != 0x00));
mbed_official 130:1dec54e4aec3 850
mbed_official 130:1dec54e4aec3 851 if((uint32_t)(ADCx->CR & ADC_CR_ADCAL) == RESET)
mbed_official 130:1dec54e4aec3 852 {
mbed_official 130:1dec54e4aec3 853 /*Get the calibration factor from the ADC data register */
mbed_official 130:1dec54e4aec3 854 tmpreg = ADCx->DR;
mbed_official 130:1dec54e4aec3 855 }
mbed_official 130:1dec54e4aec3 856 else
mbed_official 130:1dec54e4aec3 857 {
mbed_official 130:1dec54e4aec3 858 /* Error factor */
mbed_official 130:1dec54e4aec3 859 tmpreg = 0x00000000;
mbed_official 130:1dec54e4aec3 860 }
mbed_official 130:1dec54e4aec3 861 return tmpreg;
mbed_official 130:1dec54e4aec3 862 }
mbed_official 130:1dec54e4aec3 863
mbed_official 130:1dec54e4aec3 864 /**
mbed_official 130:1dec54e4aec3 865 * @brief Stop the on going conversions for the selected ADC.
mbed_official 130:1dec54e4aec3 866 * @note When ADSTP is set, any on going conversion is aborted, and the ADC
mbed_official 130:1dec54e4aec3 867 * data register is not updated with current conversion.
mbed_official 130:1dec54e4aec3 868 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 869 * @retval None
mbed_official 130:1dec54e4aec3 870 */
mbed_official 130:1dec54e4aec3 871 void ADC_StopOfConversion(ADC_TypeDef* ADCx)
mbed_official 130:1dec54e4aec3 872 {
mbed_official 130:1dec54e4aec3 873 /* Check the parameters */
mbed_official 130:1dec54e4aec3 874 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 875
mbed_official 130:1dec54e4aec3 876 ADCx->CR |= (uint32_t)ADC_CR_ADSTP;
mbed_official 130:1dec54e4aec3 877 }
mbed_official 130:1dec54e4aec3 878
mbed_official 130:1dec54e4aec3 879 /**
mbed_official 130:1dec54e4aec3 880 * @brief Start Conversion for the selected ADC channels.
mbed_official 130:1dec54e4aec3 881 * @note In continuous mode, ADSTART is not cleared by hardware with the
mbed_official 130:1dec54e4aec3 882 * assertion of EOSEQ because the sequence is automatic relaunched
mbed_official 130:1dec54e4aec3 883 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 884 * @retval None
mbed_official 130:1dec54e4aec3 885 */
mbed_official 130:1dec54e4aec3 886 void ADC_StartOfConversion(ADC_TypeDef* ADCx)
mbed_official 130:1dec54e4aec3 887 {
mbed_official 130:1dec54e4aec3 888 /* Check the parameters */
mbed_official 130:1dec54e4aec3 889 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 890
mbed_official 130:1dec54e4aec3 891 ADCx->CR |= (uint32_t)ADC_CR_ADSTART;
mbed_official 130:1dec54e4aec3 892 }
mbed_official 130:1dec54e4aec3 893
mbed_official 130:1dec54e4aec3 894 /**
mbed_official 130:1dec54e4aec3 895 * @brief Returns the last ADCx conversion result data for ADC channel.
mbed_official 130:1dec54e4aec3 896 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 897 * @retval The Data conversion value.
mbed_official 130:1dec54e4aec3 898 */
mbed_official 130:1dec54e4aec3 899 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)
mbed_official 130:1dec54e4aec3 900 {
mbed_official 130:1dec54e4aec3 901 /* Check the parameters */
mbed_official 130:1dec54e4aec3 902 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 903
mbed_official 130:1dec54e4aec3 904 /* Return the selected ADC conversion value */
mbed_official 130:1dec54e4aec3 905 return (uint16_t) ADCx->DR;
mbed_official 130:1dec54e4aec3 906 }
mbed_official 130:1dec54e4aec3 907
mbed_official 130:1dec54e4aec3 908 /**
mbed_official 130:1dec54e4aec3 909 * @}
mbed_official 130:1dec54e4aec3 910 */
mbed_official 130:1dec54e4aec3 911
mbed_official 130:1dec54e4aec3 912 /** @defgroup ADC_Group6 DMA Configuration functions
mbed_official 130:1dec54e4aec3 913 * @brief Regular Channels DMA Configuration functions
mbed_official 130:1dec54e4aec3 914 *
mbed_official 130:1dec54e4aec3 915 @verbatim
mbed_official 130:1dec54e4aec3 916 ===============================================================================
mbed_official 130:1dec54e4aec3 917 ##### DMA Configuration functions #####
mbed_official 130:1dec54e4aec3 918 ===============================================================================
mbed_official 130:1dec54e4aec3 919 [..] This section provides functions allowing to configure the DMA for ADC hannels.
mbed_official 130:1dec54e4aec3 920 Since converted channel values are stored into a unique data register,
mbed_official 130:1dec54e4aec3 921 it is useful to use DMA for conversion of more than one channel. This
mbed_official 130:1dec54e4aec3 922 avoids the loss of the data already stored in the ADC Data register.
mbed_official 130:1dec54e4aec3 923 When the DMA mode is enabled (using the ADC_DMACmd() function), after each
mbed_official 130:1dec54e4aec3 924 conversion of a channel, a DMA request is generated.
mbed_official 130:1dec54e4aec3 925
mbed_official 130:1dec54e4aec3 926 [..] Depending on the "DMA disable selection" configuration (using the
mbed_official 130:1dec54e4aec3 927 ADC_DMARequestModeConfig() function), at the end of the last DMA
mbed_official 130:1dec54e4aec3 928 transfer, two possibilities are allowed:
mbed_official 130:1dec54e4aec3 929 (+) No new DMA request is issued to the DMA controller (One Shot Mode)
mbed_official 130:1dec54e4aec3 930 (+) Requests can continue to be generated (Circular Mode).
mbed_official 130:1dec54e4aec3 931
mbed_official 130:1dec54e4aec3 932 @endverbatim
mbed_official 130:1dec54e4aec3 933 * @{
mbed_official 130:1dec54e4aec3 934 */
mbed_official 130:1dec54e4aec3 935
mbed_official 130:1dec54e4aec3 936 /**
mbed_official 130:1dec54e4aec3 937 * @brief Enables or disables the specified ADC DMA request.
mbed_official 130:1dec54e4aec3 938 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 939 * @param NewState: new state of the selected ADC DMA transfer.
mbed_official 130:1dec54e4aec3 940 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 941 * @retval None
mbed_official 130:1dec54e4aec3 942 */
mbed_official 130:1dec54e4aec3 943 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 944 {
mbed_official 130:1dec54e4aec3 945 /* Check the parameters */
mbed_official 130:1dec54e4aec3 946 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 947 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 948
mbed_official 130:1dec54e4aec3 949 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 950 {
mbed_official 130:1dec54e4aec3 951 /* Enable the selected ADC DMA request */
mbed_official 130:1dec54e4aec3 952 ADCx->CFGR1 |= (uint32_t)ADC_CFGR1_DMAEN;
mbed_official 130:1dec54e4aec3 953 }
mbed_official 130:1dec54e4aec3 954 else
mbed_official 130:1dec54e4aec3 955 {
mbed_official 130:1dec54e4aec3 956 /* Disable the selected ADC DMA request */
mbed_official 130:1dec54e4aec3 957 ADCx->CFGR1 &= (uint32_t)(~ADC_CFGR1_DMAEN);
mbed_official 130:1dec54e4aec3 958 }
mbed_official 130:1dec54e4aec3 959 }
mbed_official 130:1dec54e4aec3 960
mbed_official 130:1dec54e4aec3 961 /**
mbed_official 130:1dec54e4aec3 962 * @brief Enables or disables the ADC DMA request after last transfer (Single-ADC mode)
mbed_official 130:1dec54e4aec3 963 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 964 * @param ADC_DMARequestMode: the ADC channel to configure.
mbed_official 130:1dec54e4aec3 965 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 966 * @arg ADC_DMAMode_OneShot: DMA One Shot Mode
mbed_official 130:1dec54e4aec3 967 * @arg ADC_DMAMode_Circular: DMA Circular Mode
mbed_official 130:1dec54e4aec3 968 * @retval None
mbed_official 130:1dec54e4aec3 969 */
mbed_official 130:1dec54e4aec3 970 void ADC_DMARequestModeConfig(ADC_TypeDef* ADCx, uint32_t ADC_DMARequestMode)
mbed_official 130:1dec54e4aec3 971 {
mbed_official 130:1dec54e4aec3 972 /* Check the parameters */
mbed_official 130:1dec54e4aec3 973 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 974
mbed_official 130:1dec54e4aec3 975 ADCx->CFGR1 &= (uint32_t)~ADC_CFGR1_DMACFG;
mbed_official 130:1dec54e4aec3 976 ADCx->CFGR1 |= (uint32_t)ADC_DMARequestMode;
mbed_official 130:1dec54e4aec3 977 }
mbed_official 130:1dec54e4aec3 978
mbed_official 130:1dec54e4aec3 979 /**
mbed_official 130:1dec54e4aec3 980 * @}
mbed_official 130:1dec54e4aec3 981 */
mbed_official 130:1dec54e4aec3 982
mbed_official 130:1dec54e4aec3 983 /** @defgroup ADC_Group7 Interrupts and flags management functions
mbed_official 130:1dec54e4aec3 984 * @brief Interrupts and flags management functions.
mbed_official 130:1dec54e4aec3 985 *
mbed_official 130:1dec54e4aec3 986 @verbatim
mbed_official 130:1dec54e4aec3 987 ===============================================================================
mbed_official 130:1dec54e4aec3 988 ##### Interrupts and flags management functions #####
mbed_official 130:1dec54e4aec3 989 ===============================================================================
mbed_official 130:1dec54e4aec3 990 [..] This section provides functions allowing to configure the ADC Interrupts
mbed_official 130:1dec54e4aec3 991 and get the status and clear flags and Interrupts pending bits.
mbed_official 130:1dec54e4aec3 992
mbed_official 130:1dec54e4aec3 993 [..] The ADC provide 6 Interrupts sources and 11 Flags which can be divided into
mbed_official 130:1dec54e4aec3 994 3 groups:
mbed_official 130:1dec54e4aec3 995
mbed_official 130:1dec54e4aec3 996 *** Flags for ADC status ***
mbed_official 130:1dec54e4aec3 997 ======================================================
mbed_official 130:1dec54e4aec3 998 [..]
mbed_official 130:1dec54e4aec3 999 (+)Flags :
mbed_official 130:1dec54e4aec3 1000 (##) ADC_FLAG_ADRDY : This flag is set after the ADC has been enabled (bit ADEN=1)
mbed_official 130:1dec54e4aec3 1001 and when the ADC reaches a state where it is ready to accept conversion requests
mbed_official 130:1dec54e4aec3 1002 (##) ADC_FLAG_ADEN : This flag is set by software to enable the ADC.
mbed_official 130:1dec54e4aec3 1003 The ADC will be effectively ready to operate once the ADRDY flag has been set.
mbed_official 130:1dec54e4aec3 1004 (##) ADC_FLAG_ADDIS : This flag is cleared once the ADC is effectively
mbed_official 130:1dec54e4aec3 1005 disabled.
mbed_official 130:1dec54e4aec3 1006 (##) ADC_FLAG_ADSTART : This flag is cleared after the execution of
mbed_official 130:1dec54e4aec3 1007 ADC_StopOfConversion() function, at the same time as the ADSTP bit is
mbed_official 130:1dec54e4aec3 1008 cleared by hardware
mbed_official 130:1dec54e4aec3 1009 (##) ADC_FLAG_ADSTP : This flag is cleared by hardware when the conversion
mbed_official 130:1dec54e4aec3 1010 is effectively discarded and the ADC is ready to accept a new start conversion
mbed_official 130:1dec54e4aec3 1011 (##) ADC_FLAG_ADCAL : This flag is set once the calibration is complete.
mbed_official 130:1dec54e4aec3 1012
mbed_official 130:1dec54e4aec3 1013 (+)Interrupts
mbed_official 130:1dec54e4aec3 1014 (##) ADC_IT_ADRDY : specifies the interrupt source for ADC ready event.
mbed_official 130:1dec54e4aec3 1015
mbed_official 130:1dec54e4aec3 1016 *** Flags and Interrupts for ADC channel conversion ***
mbed_official 130:1dec54e4aec3 1017 =====================================================
mbed_official 130:1dec54e4aec3 1018 [..]
mbed_official 130:1dec54e4aec3 1019 (+)Flags :
mbed_official 130:1dec54e4aec3 1020 (##) ADC_FLAG_EOC : This flag is set by hardware at the end of each conversion
mbed_official 130:1dec54e4aec3 1021 of a channel when a new data result is available in the data register
mbed_official 130:1dec54e4aec3 1022 (##) ADC_FLAG_EOSEQ : This bit is set by hardware at the end of the conversion
mbed_official 130:1dec54e4aec3 1023 of a sequence of channels selected by ADC_ChannelConfig() function.
mbed_official 130:1dec54e4aec3 1024 (##) ADC_FLAG_EOSMP : This bit is set by hardware at the end of the sampling phase.
mbed_official 130:1dec54e4aec3 1025 (##) ADC_FLAG_OVR : This flag is set by hardware when an overrun occurs,
mbed_official 130:1dec54e4aec3 1026 meaning that a new conversion has complete while the EOC flag was already set.
mbed_official 130:1dec54e4aec3 1027
mbed_official 130:1dec54e4aec3 1028 (+)Interrupts :
mbed_official 130:1dec54e4aec3 1029 (##) ADC_IT_EOC : specifies the interrupt source for end of conversion event.
mbed_official 130:1dec54e4aec3 1030 (##) ADC_IT_EOSEQ : specifies the interrupt source for end of sequence event.
mbed_official 130:1dec54e4aec3 1031 (##) ADC_IT_EOSMP : specifies the interrupt source for end of sampling event.
mbed_official 130:1dec54e4aec3 1032 (##) ADC_IT_OVR : specifies the interrupt source for Overrun detection
mbed_official 130:1dec54e4aec3 1033 event.
mbed_official 130:1dec54e4aec3 1034
mbed_official 130:1dec54e4aec3 1035 *** Flags and Interrupts for the Analog Watchdog ***
mbed_official 130:1dec54e4aec3 1036 ================================================
mbed_official 130:1dec54e4aec3 1037 [..]
mbed_official 130:1dec54e4aec3 1038 (+)Flags :
mbed_official 130:1dec54e4aec3 1039 (##) ADC_FLAG_AWD: This flag is set by hardware when the converted
mbed_official 130:1dec54e4aec3 1040 voltage crosses the values programmed thrsholds
mbed_official 130:1dec54e4aec3 1041
mbed_official 130:1dec54e4aec3 1042 (+)Interrupts :
mbed_official 130:1dec54e4aec3 1043 (##) ADC_IT_AWD : specifies the interrupt source for Analog watchdog
mbed_official 130:1dec54e4aec3 1044 event.
mbed_official 130:1dec54e4aec3 1045
mbed_official 130:1dec54e4aec3 1046 [..] The user should identify which mode will be used in his application to
mbed_official 130:1dec54e4aec3 1047 manage the ADC controller events: Polling mode or Interrupt mode.
mbed_official 130:1dec54e4aec3 1048
mbed_official 130:1dec54e4aec3 1049 [..] In the Polling Mode it is advised to use the following functions:
mbed_official 130:1dec54e4aec3 1050 (+) ADC_GetFlagStatus() : to check if flags events occur.
mbed_official 130:1dec54e4aec3 1051 (+) ADC_ClearFlag() : to clear the flags events.
mbed_official 130:1dec54e4aec3 1052
mbed_official 130:1dec54e4aec3 1053 [..] In the Interrupt Mode it is advised to use the following functions:
mbed_official 130:1dec54e4aec3 1054 (+) ADC_ITConfig() : to enable or disable the interrupt source.
mbed_official 130:1dec54e4aec3 1055 (+) ADC_GetITStatus() : to check if Interrupt occurs.
mbed_official 130:1dec54e4aec3 1056 (+) ADC_ClearITPendingBit() : to clear the Interrupt pending Bit
mbed_official 130:1dec54e4aec3 1057 (corresponding Flag).
mbed_official 130:1dec54e4aec3 1058
mbed_official 130:1dec54e4aec3 1059 @endverbatim
mbed_official 130:1dec54e4aec3 1060 * @{
mbed_official 130:1dec54e4aec3 1061 */
mbed_official 130:1dec54e4aec3 1062
mbed_official 130:1dec54e4aec3 1063 /**
mbed_official 130:1dec54e4aec3 1064 * @brief Enables or disables the specified ADC interrupts.
mbed_official 130:1dec54e4aec3 1065 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 130:1dec54e4aec3 1066 * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
mbed_official 130:1dec54e4aec3 1067 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1068 * @arg ADC_IT_ADRDY: ADC ready interrupt
mbed_official 130:1dec54e4aec3 1069 * @arg ADC_IT_EOSMP: End of sampling interrupt
mbed_official 130:1dec54e4aec3 1070 * @arg ADC_IT_EOC: End of conversion interrupt
mbed_official 130:1dec54e4aec3 1071 * @arg ADC_IT_EOSEQ: End of sequence of conversion interrupt
mbed_official 130:1dec54e4aec3 1072 * @arg ADC_IT_OVR: overrun interrupt
mbed_official 130:1dec54e4aec3 1073 * @arg ADC_IT_AWD: Analog watchdog interrupt
mbed_official 130:1dec54e4aec3 1074 * @param NewState: new state of the specified ADC interrupts.
mbed_official 130:1dec54e4aec3 1075 * This parameter can be: ENABLE or DISABLE.
mbed_official 130:1dec54e4aec3 1076 * @retval None
mbed_official 130:1dec54e4aec3 1077 */
mbed_official 130:1dec54e4aec3 1078 void ADC_ITConfig(ADC_TypeDef* ADCx, uint32_t ADC_IT, FunctionalState NewState)
mbed_official 130:1dec54e4aec3 1079 {
mbed_official 130:1dec54e4aec3 1080 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1081 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 1082 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 130:1dec54e4aec3 1083 assert_param(IS_ADC_CONFIG_IT(ADC_IT));
mbed_official 130:1dec54e4aec3 1084
mbed_official 130:1dec54e4aec3 1085 if (NewState != DISABLE)
mbed_official 130:1dec54e4aec3 1086 {
mbed_official 130:1dec54e4aec3 1087 /* Enable the selected ADC interrupts */
mbed_official 130:1dec54e4aec3 1088 ADCx->IER |= ADC_IT;
mbed_official 130:1dec54e4aec3 1089 }
mbed_official 130:1dec54e4aec3 1090 else
mbed_official 130:1dec54e4aec3 1091 {
mbed_official 130:1dec54e4aec3 1092 /* Disable the selected ADC interrupts */
mbed_official 130:1dec54e4aec3 1093 ADCx->IER &= (~(uint32_t)ADC_IT);
mbed_official 130:1dec54e4aec3 1094 }
mbed_official 130:1dec54e4aec3 1095 }
mbed_official 130:1dec54e4aec3 1096
mbed_official 130:1dec54e4aec3 1097 /**
mbed_official 130:1dec54e4aec3 1098 * @brief Checks whether the specified ADC flag is set or not.
mbed_official 130:1dec54e4aec3 1099 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 1100 * @param ADC_FLAG: specifies the flag to check.
mbed_official 130:1dec54e4aec3 1101 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1102 * @arg ADC_FLAG_AWD: Analog watchdog flag
mbed_official 130:1dec54e4aec3 1103 * @arg ADC_FLAG_OVR: Overrun flag
mbed_official 130:1dec54e4aec3 1104 * @arg ADC_FLAG_EOSEQ: End of Sequence flag
mbed_official 130:1dec54e4aec3 1105 * @arg ADC_FLAG_EOC: End of conversion flag
mbed_official 130:1dec54e4aec3 1106 * @arg ADC_FLAG_EOSMP: End of sampling flag
mbed_official 130:1dec54e4aec3 1107 * @arg ADC_FLAG_ADRDY: ADC Ready flag
mbed_official 130:1dec54e4aec3 1108 * @arg ADC_FLAG_ADEN: ADC enable flag
mbed_official 130:1dec54e4aec3 1109 * @arg ADC_FLAG_ADDIS: ADC disable flag
mbed_official 130:1dec54e4aec3 1110 * @arg ADC_FLAG_ADSTART: ADC start flag
mbed_official 130:1dec54e4aec3 1111 * @arg ADC_FLAG_ADSTP: ADC stop flag
mbed_official 130:1dec54e4aec3 1112 * @arg ADC_FLAG_ADCAL: ADC Calibration flag
mbed_official 130:1dec54e4aec3 1113 * @retval The new state of ADC_FLAG (SET or RESET).
mbed_official 130:1dec54e4aec3 1114 */
mbed_official 130:1dec54e4aec3 1115 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
mbed_official 130:1dec54e4aec3 1116 {
mbed_official 130:1dec54e4aec3 1117 FlagStatus bitstatus = RESET;
mbed_official 130:1dec54e4aec3 1118 uint32_t tmpreg = 0;
mbed_official 130:1dec54e4aec3 1119
mbed_official 130:1dec54e4aec3 1120 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1121 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 1122 assert_param(IS_ADC_GET_FLAG(ADC_FLAG));
mbed_official 130:1dec54e4aec3 1123
mbed_official 130:1dec54e4aec3 1124 if((uint32_t)(ADC_FLAG & 0x01000000))
mbed_official 130:1dec54e4aec3 1125 {
mbed_official 130:1dec54e4aec3 1126 tmpreg = ADCx->CR & 0xFEFFFFFF;
mbed_official 130:1dec54e4aec3 1127 }
mbed_official 130:1dec54e4aec3 1128 else
mbed_official 130:1dec54e4aec3 1129 {
mbed_official 130:1dec54e4aec3 1130 tmpreg = ADCx->ISR;
mbed_official 130:1dec54e4aec3 1131 }
mbed_official 130:1dec54e4aec3 1132
mbed_official 130:1dec54e4aec3 1133 /* Check the status of the specified ADC flag */
mbed_official 130:1dec54e4aec3 1134 if ((tmpreg & ADC_FLAG) != (uint32_t)RESET)
mbed_official 130:1dec54e4aec3 1135 {
mbed_official 130:1dec54e4aec3 1136 /* ADC_FLAG is set */
mbed_official 130:1dec54e4aec3 1137 bitstatus = SET;
mbed_official 130:1dec54e4aec3 1138 }
mbed_official 130:1dec54e4aec3 1139 else
mbed_official 130:1dec54e4aec3 1140 {
mbed_official 130:1dec54e4aec3 1141 /* ADC_FLAG is reset */
mbed_official 130:1dec54e4aec3 1142 bitstatus = RESET;
mbed_official 130:1dec54e4aec3 1143 }
mbed_official 130:1dec54e4aec3 1144 /* Return the ADC_FLAG status */
mbed_official 130:1dec54e4aec3 1145 return bitstatus;
mbed_official 130:1dec54e4aec3 1146 }
mbed_official 130:1dec54e4aec3 1147
mbed_official 130:1dec54e4aec3 1148 /**
mbed_official 130:1dec54e4aec3 1149 * @brief Clears the ADCx's pending flags.
mbed_official 130:1dec54e4aec3 1150 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 1151 * @param ADC_FLAG: specifies the flag to clear.
mbed_official 130:1dec54e4aec3 1152 * This parameter can be any combination of the following values:
mbed_official 130:1dec54e4aec3 1153 * @arg ADC_FLAG_AWD: Analog watchdog flag
mbed_official 130:1dec54e4aec3 1154 * @arg ADC_FLAG_EOC: End of conversion flag
mbed_official 130:1dec54e4aec3 1155 * @arg ADC_FLAG_ADRDY: ADC Ready flag
mbed_official 130:1dec54e4aec3 1156 * @arg ADC_FLAG_EOSMP: End of sampling flag
mbed_official 130:1dec54e4aec3 1157 * @arg ADC_FLAG_EOSEQ: End of Sequence flag
mbed_official 130:1dec54e4aec3 1158 * @arg ADC_FLAG_OVR: Overrun flag
mbed_official 130:1dec54e4aec3 1159 * @retval None
mbed_official 130:1dec54e4aec3 1160 */
mbed_official 130:1dec54e4aec3 1161 void ADC_ClearFlag(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
mbed_official 130:1dec54e4aec3 1162 {
mbed_official 130:1dec54e4aec3 1163 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1164 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 1165 assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG));
mbed_official 130:1dec54e4aec3 1166
mbed_official 130:1dec54e4aec3 1167 /* Clear the selected ADC flags */
mbed_official 130:1dec54e4aec3 1168 ADCx->ISR = (uint32_t)ADC_FLAG;
mbed_official 130:1dec54e4aec3 1169 }
mbed_official 130:1dec54e4aec3 1170
mbed_official 130:1dec54e4aec3 1171 /**
mbed_official 130:1dec54e4aec3 1172 * @brief Checks whether the specified ADC interrupt has occurred or not.
mbed_official 130:1dec54e4aec3 1173 * @param ADCx: where x can be 1 to select the ADC1 peripheral
mbed_official 130:1dec54e4aec3 1174 * @param ADC_IT: specifies the ADC interrupt source to check.
mbed_official 130:1dec54e4aec3 1175 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1176 * @arg ADC_IT_ADRDY: ADC ready interrupt
mbed_official 130:1dec54e4aec3 1177 * @arg ADC_IT_EOSMP: End of sampling interrupt
mbed_official 130:1dec54e4aec3 1178 * @arg ADC_IT_EOC: End of conversion interrupt
mbed_official 130:1dec54e4aec3 1179 * @arg ADC_IT_EOSEQ: End of sequence of conversion interrupt
mbed_official 130:1dec54e4aec3 1180 * @arg ADC_IT_OVR: overrun interrupt
mbed_official 130:1dec54e4aec3 1181 * @arg ADC_IT_AWD: Analog watchdog interrupt
mbed_official 130:1dec54e4aec3 1182 * @retval The new state of ADC_IT (SET or RESET).
mbed_official 130:1dec54e4aec3 1183 */
mbed_official 130:1dec54e4aec3 1184 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint32_t ADC_IT)
mbed_official 130:1dec54e4aec3 1185 {
mbed_official 130:1dec54e4aec3 1186 ITStatus bitstatus = RESET;
mbed_official 130:1dec54e4aec3 1187 uint32_t enablestatus = 0;
mbed_official 130:1dec54e4aec3 1188
mbed_official 130:1dec54e4aec3 1189 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1190 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 1191 assert_param(IS_ADC_GET_IT(ADC_IT));
mbed_official 130:1dec54e4aec3 1192
mbed_official 130:1dec54e4aec3 1193 /* Get the ADC_IT enable bit status */
mbed_official 130:1dec54e4aec3 1194 enablestatus = (uint32_t)(ADCx->IER & ADC_IT);
mbed_official 130:1dec54e4aec3 1195
mbed_official 130:1dec54e4aec3 1196 /* Check the status of the specified ADC interrupt */
mbed_official 130:1dec54e4aec3 1197 if (((uint32_t)(ADCx->ISR & ADC_IT) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
mbed_official 130:1dec54e4aec3 1198 {
mbed_official 130:1dec54e4aec3 1199 /* ADC_IT is set */
mbed_official 130:1dec54e4aec3 1200 bitstatus = SET;
mbed_official 130:1dec54e4aec3 1201 }
mbed_official 130:1dec54e4aec3 1202 else
mbed_official 130:1dec54e4aec3 1203 {
mbed_official 130:1dec54e4aec3 1204 /* ADC_IT is reset */
mbed_official 130:1dec54e4aec3 1205 bitstatus = RESET;
mbed_official 130:1dec54e4aec3 1206 }
mbed_official 130:1dec54e4aec3 1207 /* Return the ADC_IT status */
mbed_official 130:1dec54e4aec3 1208 return bitstatus;
mbed_official 130:1dec54e4aec3 1209 }
mbed_official 130:1dec54e4aec3 1210
mbed_official 130:1dec54e4aec3 1211 /**
mbed_official 130:1dec54e4aec3 1212 * @brief Clears the ADCx's interrupt pending bits.
mbed_official 130:1dec54e4aec3 1213 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 130:1dec54e4aec3 1214 * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
mbed_official 130:1dec54e4aec3 1215 * This parameter can be one of the following values:
mbed_official 130:1dec54e4aec3 1216 * @arg ADC_IT_ADRDY: ADC ready interrupt
mbed_official 130:1dec54e4aec3 1217 * @arg ADC_IT_EOSMP: End of sampling interrupt
mbed_official 130:1dec54e4aec3 1218 * @arg ADC_IT_EOC: End of conversion interrupt
mbed_official 130:1dec54e4aec3 1219 * @arg ADC_IT_EOSEQ: End of sequence of conversion interrupt
mbed_official 130:1dec54e4aec3 1220 * @arg ADC_IT_OVR: overrun interrupt
mbed_official 130:1dec54e4aec3 1221 * @arg ADC_IT_AWD: Analog watchdog interrupt
mbed_official 130:1dec54e4aec3 1222 * @retval None
mbed_official 130:1dec54e4aec3 1223 */
mbed_official 130:1dec54e4aec3 1224 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint32_t ADC_IT)
mbed_official 130:1dec54e4aec3 1225 {
mbed_official 130:1dec54e4aec3 1226 /* Check the parameters */
mbed_official 130:1dec54e4aec3 1227 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 130:1dec54e4aec3 1228 assert_param(IS_ADC_CLEAR_IT(ADC_IT));
mbed_official 130:1dec54e4aec3 1229
mbed_official 130:1dec54e4aec3 1230 /* Clear the selected ADC interrupt pending bits */
mbed_official 130:1dec54e4aec3 1231 ADCx->ISR = (uint32_t)ADC_IT;
mbed_official 130:1dec54e4aec3 1232 }
mbed_official 130:1dec54e4aec3 1233
mbed_official 130:1dec54e4aec3 1234 /**
mbed_official 130:1dec54e4aec3 1235 * @}
mbed_official 130:1dec54e4aec3 1236 */
mbed_official 130:1dec54e4aec3 1237
mbed_official 130:1dec54e4aec3 1238 /**
mbed_official 130:1dec54e4aec3 1239 * @}
mbed_official 130:1dec54e4aec3 1240 */
mbed_official 130:1dec54e4aec3 1241
mbed_official 130:1dec54e4aec3 1242 /**
mbed_official 130:1dec54e4aec3 1243 * @}
mbed_official 130:1dec54e4aec3 1244 */
mbed_official 130:1dec54e4aec3 1245
mbed_official 130:1dec54e4aec3 1246 /**
mbed_official 130:1dec54e4aec3 1247 * @}
mbed_official 130:1dec54e4aec3 1248 */
mbed_official 130:1dec54e4aec3 1249
mbed_official 130:1dec54e4aec3 1250 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/