mbed library with additional peripherals for ST F401 board

Fork of mbed-src by mbed official

This mbed LIB has additional peripherals for ST F401 board

  • UART2 : PA_3 rx, PA_2 tx
  • UART3 : PC_7 rx, PC_6 tx
  • I2C2 : PB_3 SDA, PB_10 SCL
  • I2C3 : PB_4 SDA, PA_8 SCL
Committer:
mbed_official
Date:
Mon Jan 27 14:30:07 2014 +0000
Revision:
76:aeb1df146756
Child:
106:ced8cbb51063
Synchronized with git revision a31ec9c5f7bcb5c8a1b2eced103f6a1dfa921abd

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

Add NUCLEO_L152RE

Who changed what in which revision?

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