mbed library sources

Dependents:   Marvino mbot

Fork of mbed-src by mbed official

Committer:
jaerts
Date:
Tue Dec 22 13:22:16 2015 +0000
Revision:
637:ed69428d4850
Parent:
155:8435094ec241
Add very shady LPC1768 CAN Filter implementation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 155:8435094ec241 1 /**
mbed_official 155:8435094ec241 2 ******************************************************************************
mbed_official 155:8435094ec241 3 * @file stm32f30x_adc.c
mbed_official 155:8435094ec241 4 * @author MCD Application Team
mbed_official 155:8435094ec241 5 * @version V1.1.0
mbed_official 155:8435094ec241 6 * @date 27-February-2014
mbed_official 155:8435094ec241 7 * @brief This file provides firmware functions to manage the following
mbed_official 155:8435094ec241 8 * functionalities of the Analog to Digital Convertor (ADC) peripheral:
mbed_official 155:8435094ec241 9 * + Initialization and Configuration
mbed_official 155:8435094ec241 10 * + Analog Watchdog configuration
mbed_official 155:8435094ec241 11 * + Temperature Sensor, Vbat & Vrefint (Internal Reference Voltage) management
mbed_official 155:8435094ec241 12 * + Regular Channels Configuration
mbed_official 155:8435094ec241 13 * + Regular Channels DMA Configuration
mbed_official 155:8435094ec241 14 * + Injected channels Configuration
mbed_official 155:8435094ec241 15 * + Interrupts and flags management
mbed_official 155:8435094ec241 16 * + Dual mode configuration
mbed_official 155:8435094ec241 17 *
mbed_official 155:8435094ec241 18 @verbatim
mbed_official 155:8435094ec241 19 ==============================================================================
mbed_official 155:8435094ec241 20 ##### How to use this driver #####
mbed_official 155:8435094ec241 21 ==============================================================================
mbed_official 155:8435094ec241 22 [..]
mbed_official 155:8435094ec241 23 (#) select the ADC clock using the function RCC_ADCCLKConfig()
mbed_official 155:8435094ec241 24 (#) Enable the ADC interface clock using RCC_AHBPeriphClockCmd();
mbed_official 155:8435094ec241 25 (#) ADC pins configuration
mbed_official 155:8435094ec241 26 (++) Enable the clock for the ADC GPIOs using the following function:
mbed_official 155:8435094ec241 27 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOx, ENABLE);
mbed_official 155:8435094ec241 28 (++) Configure these ADC pins in analog mode using GPIO_Init();
mbed_official 155:8435094ec241 29 (#) Configure the ADC conversion resolution, data alignment, external
mbed_official 155:8435094ec241 30 trigger and edge, sequencer lenght and Enable/Disable the continuous mode
mbed_official 155:8435094ec241 31 using the ADC_Init() function.
mbed_official 155:8435094ec241 32 (#) Activate the ADC peripheral using ADC_Cmd() function.
mbed_official 155:8435094ec241 33
mbed_official 155:8435094ec241 34 *** ADC channels group configuration ***
mbed_official 155:8435094ec241 35 ========================================
mbed_official 155:8435094ec241 36 [..]
mbed_official 155:8435094ec241 37 (+) To configure the ADC channels features, use ADC_Init(), ADC_InjectedInit()
mbed_official 155:8435094ec241 38 and/or ADC_RegularChannelConfig() functions.
mbed_official 155:8435094ec241 39 (+) To activate the continuous mode, use the ADC_ContinuousModeCmd()
mbed_official 155:8435094ec241 40 function.
mbed_official 155:8435094ec241 41 (+) To activate the Discontinuous mode, use the ADC_DiscModeCmd() functions.
mbed_official 155:8435094ec241 42 (+) To activate the overrun mode, use the ADC_OverrunModeCmd() functions.
mbed_official 155:8435094ec241 43 (+) To activate the calibration mode, use the ADC_StartCalibration() functions.
mbed_official 155:8435094ec241 44 (+) To read the ADC converted values, use the ADC_GetConversionValue()
mbed_official 155:8435094ec241 45 function.
mbed_official 155:8435094ec241 46
mbed_official 155:8435094ec241 47 *** DMA for ADC channels features configuration ***
mbed_official 155:8435094ec241 48 ===================================================
mbed_official 155:8435094ec241 49 [..]
mbed_official 155:8435094ec241 50 (+) To enable the DMA mode for ADC channels group, use the ADC_DMACmd() function.
mbed_official 155:8435094ec241 51 (+) To configure the DMA transfer request, use ADC_DMAConfig() function.
mbed_official 155:8435094ec241 52
mbed_official 155:8435094ec241 53 @endverbatim
mbed_official 155:8435094ec241 54 *
mbed_official 155:8435094ec241 55 ******************************************************************************
mbed_official 155:8435094ec241 56 * @attention
mbed_official 155:8435094ec241 57 *
mbed_official 155:8435094ec241 58 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 155:8435094ec241 59 *
mbed_official 155:8435094ec241 60 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 155:8435094ec241 61 * are permitted provided that the following conditions are met:
mbed_official 155:8435094ec241 62 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 155:8435094ec241 63 * this list of conditions and the following disclaimer.
mbed_official 155:8435094ec241 64 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 155:8435094ec241 65 * this list of conditions and the following disclaimer in the documentation
mbed_official 155:8435094ec241 66 * and/or other materials provided with the distribution.
mbed_official 155:8435094ec241 67 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 155:8435094ec241 68 * may be used to endorse or promote products derived from this software
mbed_official 155:8435094ec241 69 * without specific prior written permission.
mbed_official 155:8435094ec241 70 *
mbed_official 155:8435094ec241 71 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 155:8435094ec241 72 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 155:8435094ec241 73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 155:8435094ec241 74 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 155:8435094ec241 75 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 155:8435094ec241 76 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 155:8435094ec241 77 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 155:8435094ec241 78 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 155:8435094ec241 79 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 155:8435094ec241 80 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 155:8435094ec241 81 *
mbed_official 155:8435094ec241 82 ******************************************************************************
mbed_official 155:8435094ec241 83 */
mbed_official 155:8435094ec241 84
mbed_official 155:8435094ec241 85 /* Includes ------------------------------------------------------------------*/
mbed_official 155:8435094ec241 86 #include "stm32f30x_adc.h"
mbed_official 155:8435094ec241 87 #include "stm32f30x_rcc.h"
mbed_official 155:8435094ec241 88
mbed_official 155:8435094ec241 89 /** @addtogroup STM32F30x_StdPeriph_Driver
mbed_official 155:8435094ec241 90 * @{
mbed_official 155:8435094ec241 91 */
mbed_official 155:8435094ec241 92
mbed_official 155:8435094ec241 93 /** @defgroup ADC
mbed_official 155:8435094ec241 94 * @brief ADC driver modules
mbed_official 155:8435094ec241 95 * @{
mbed_official 155:8435094ec241 96 */
mbed_official 155:8435094ec241 97
mbed_official 155:8435094ec241 98 /* Private typedef -----------------------------------------------------------*/
mbed_official 155:8435094ec241 99 /* Private define ------------------------------------------------------------*/
mbed_official 155:8435094ec241 100
mbed_official 155:8435094ec241 101 /* CFGR register Mask */
mbed_official 155:8435094ec241 102 #define CFGR_CLEAR_Mask ((uint32_t)0xFDFFC007)
mbed_official 155:8435094ec241 103
mbed_official 155:8435094ec241 104 /* JSQR register Mask */
mbed_official 155:8435094ec241 105 #define JSQR_CLEAR_Mask ((uint32_t)0x00000000)
mbed_official 155:8435094ec241 106
mbed_official 155:8435094ec241 107 /* ADC ADON mask */
mbed_official 155:8435094ec241 108 #define CCR_CLEAR_MASK ((uint32_t)0xFFFC10E0)
mbed_official 155:8435094ec241 109
mbed_official 155:8435094ec241 110 /* ADC JDRx registers offset */
mbed_official 155:8435094ec241 111 #define JDR_Offset ((uint8_t)0x80)
mbed_official 155:8435094ec241 112
mbed_official 155:8435094ec241 113 /* Private macro -------------------------------------------------------------*/
mbed_official 155:8435094ec241 114 /* Private variables ---------------------------------------------------------*/
mbed_official 155:8435094ec241 115 /* Private function prototypes -----------------------------------------------*/
mbed_official 155:8435094ec241 116 /* Private functions ---------------------------------------------------------*/
mbed_official 155:8435094ec241 117
mbed_official 155:8435094ec241 118 /** @defgroup ADC_Private_Functions
mbed_official 155:8435094ec241 119 * @{
mbed_official 155:8435094ec241 120 */
mbed_official 155:8435094ec241 121
mbed_official 155:8435094ec241 122 /** @defgroup ADC_Group1 Initialization and Configuration functions
mbed_official 155:8435094ec241 123 * @brief Initialization and Configuration functions
mbed_official 155:8435094ec241 124 *
mbed_official 155:8435094ec241 125 @verbatim
mbed_official 155:8435094ec241 126 ===============================================================================
mbed_official 155:8435094ec241 127 ##### Initialization and Configuration functions #####
mbed_official 155:8435094ec241 128 ===============================================================================
mbed_official 155:8435094ec241 129 [..]
mbed_official 155:8435094ec241 130 This section provides functions allowing to:
mbed_official 155:8435094ec241 131 (#) Initialize and configure the ADC injected and/or regular channels and dual mode.
mbed_official 155:8435094ec241 132 (#) Management of the calibration process
mbed_official 155:8435094ec241 133 (#) ADC Power-on Power-off
mbed_official 155:8435094ec241 134 (#) Single ended or differential mode
mbed_official 155:8435094ec241 135 (#) Enabling the queue of context and the auto delay mode
mbed_official 155:8435094ec241 136 (#) The number of ADC conversions that will be done using the sequencer for regular
mbed_official 155:8435094ec241 137 channel group
mbed_official 155:8435094ec241 138 (#) Enable or disable the ADC peripheral
mbed_official 155:8435094ec241 139
mbed_official 155:8435094ec241 140 @endverbatim
mbed_official 155:8435094ec241 141 * @{
mbed_official 155:8435094ec241 142 */
mbed_official 155:8435094ec241 143
mbed_official 155:8435094ec241 144 /**
mbed_official 155:8435094ec241 145 * @brief Deinitializes the ADCx peripheral registers to their default reset values.
mbed_official 155:8435094ec241 146 * @param ADCx: where x can be 1, 2,3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 147 * @retval None
mbed_official 155:8435094ec241 148 */
mbed_official 155:8435094ec241 149 void ADC_DeInit(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 150 {
mbed_official 155:8435094ec241 151 /* Check the parameters */
mbed_official 155:8435094ec241 152 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 153
mbed_official 155:8435094ec241 154
mbed_official 155:8435094ec241 155 if((ADCx == ADC1) || (ADCx == ADC2))
mbed_official 155:8435094ec241 156 {
mbed_official 155:8435094ec241 157 /* Enable ADC1/ADC2 reset state */
mbed_official 155:8435094ec241 158 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC12, ENABLE);
mbed_official 155:8435094ec241 159 /* Release ADC1/ADC2 from reset state */
mbed_official 155:8435094ec241 160 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC12, DISABLE);
mbed_official 155:8435094ec241 161 }
mbed_official 155:8435094ec241 162 else if((ADCx == ADC3) || (ADCx == ADC4))
mbed_official 155:8435094ec241 163 {
mbed_official 155:8435094ec241 164 /* Enable ADC3/ADC4 reset state */
mbed_official 155:8435094ec241 165 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC34, ENABLE);
mbed_official 155:8435094ec241 166 /* Release ADC3/ADC4 from reset state */
mbed_official 155:8435094ec241 167 RCC_AHBPeriphResetCmd(RCC_AHBPeriph_ADC34, DISABLE);
mbed_official 155:8435094ec241 168 }
mbed_official 155:8435094ec241 169 }
mbed_official 155:8435094ec241 170 /**
mbed_official 155:8435094ec241 171 * @brief Initializes the ADCx peripheral according to the specified parameters
mbed_official 155:8435094ec241 172 * in the ADC_InitStruct.
mbed_official 155:8435094ec241 173 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 174 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
mbed_official 155:8435094ec241 175 * the configuration information for the specified ADC peripheral.
mbed_official 155:8435094ec241 176 * @retval None
mbed_official 155:8435094ec241 177 */
mbed_official 155:8435094ec241 178 void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
mbed_official 155:8435094ec241 179 {
mbed_official 155:8435094ec241 180 uint32_t tmpreg1 = 0;
mbed_official 155:8435094ec241 181 /* Check the parameters */
mbed_official 155:8435094ec241 182 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 183 assert_param(IS_ADC_CONVMODE(ADC_InitStruct->ADC_ContinuousConvMode));
mbed_official 155:8435094ec241 184 assert_param(IS_ADC_RESOLUTION(ADC_InitStruct->ADC_Resolution));
mbed_official 155:8435094ec241 185 assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct->ADC_ExternalTrigConvEvent));
mbed_official 155:8435094ec241 186 assert_param(IS_EXTERNALTRIG_EDGE(ADC_InitStruct->ADC_ExternalTrigEventEdge));
mbed_official 155:8435094ec241 187 assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
mbed_official 155:8435094ec241 188 assert_param(IS_ADC_OVRUNMODE(ADC_InitStruct->ADC_OverrunMode));
mbed_official 155:8435094ec241 189 assert_param(IS_ADC_AUTOINJECMODE(ADC_InitStruct->ADC_AutoInjMode));
mbed_official 155:8435094ec241 190 assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct->ADC_NbrOfRegChannel));
mbed_official 155:8435094ec241 191
mbed_official 155:8435094ec241 192 /*---------------------------- ADCx CFGR Configuration -----------------*/
mbed_official 155:8435094ec241 193 /* Get the ADCx CFGR value */
mbed_official 155:8435094ec241 194 tmpreg1 = ADCx->CFGR;
mbed_official 155:8435094ec241 195 /* Clear SCAN bit */
mbed_official 155:8435094ec241 196 tmpreg1 &= CFGR_CLEAR_Mask;
mbed_official 155:8435094ec241 197 /* Configure ADCx: scan conversion mode */
mbed_official 155:8435094ec241 198 /* Set SCAN bit according to ADC_ScanConvMode value */
mbed_official 155:8435094ec241 199 tmpreg1 |= (uint32_t)ADC_InitStruct->ADC_ContinuousConvMode |
mbed_official 155:8435094ec241 200 ADC_InitStruct->ADC_Resolution|
mbed_official 155:8435094ec241 201 ADC_InitStruct->ADC_ExternalTrigConvEvent|
mbed_official 155:8435094ec241 202 ADC_InitStruct->ADC_ExternalTrigEventEdge|
mbed_official 155:8435094ec241 203 ADC_InitStruct->ADC_DataAlign|
mbed_official 155:8435094ec241 204 ADC_InitStruct->ADC_OverrunMode|
mbed_official 155:8435094ec241 205 ADC_InitStruct->ADC_AutoInjMode;
mbed_official 155:8435094ec241 206
mbed_official 155:8435094ec241 207 /* Write to ADCx CFGR */
mbed_official 155:8435094ec241 208 ADCx->CFGR = tmpreg1;
mbed_official 155:8435094ec241 209
mbed_official 155:8435094ec241 210 /*---------------------------- ADCx SQR1 Configuration -----------------*/
mbed_official 155:8435094ec241 211 /* Get the ADCx SQR1 value */
mbed_official 155:8435094ec241 212 tmpreg1 = ADCx->SQR1;
mbed_official 155:8435094ec241 213 /* Clear L bits */
mbed_official 155:8435094ec241 214 tmpreg1 &= ~(uint32_t)(ADC_SQR1_L);
mbed_official 155:8435094ec241 215 /* Configure ADCx: regular channel sequence length */
mbed_official 155:8435094ec241 216 /* Set L bits according to ADC_NbrOfRegChannel value */
mbed_official 155:8435094ec241 217 tmpreg1 |= (uint32_t) (ADC_InitStruct->ADC_NbrOfRegChannel - 1);
mbed_official 155:8435094ec241 218 /* Write to ADCx SQR1 */
mbed_official 155:8435094ec241 219 ADCx->SQR1 = tmpreg1;
mbed_official 155:8435094ec241 220
mbed_official 155:8435094ec241 221 }
mbed_official 155:8435094ec241 222
mbed_official 155:8435094ec241 223 /**
mbed_official 155:8435094ec241 224 * @brief Fills each ADC_InitStruct member with its default value.
mbed_official 155:8435094ec241 225 * @param ADC_InitStruct : pointer to an ADC_InitTypeDef structure which will be initialized.
mbed_official 155:8435094ec241 226 * @retval None
mbed_official 155:8435094ec241 227 */
mbed_official 155:8435094ec241 228 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
mbed_official 155:8435094ec241 229 {
mbed_official 155:8435094ec241 230 /* Reset ADC init structure parameters values */
mbed_official 155:8435094ec241 231 ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
mbed_official 155:8435094ec241 232 ADC_InitStruct->ADC_Resolution = ADC_Resolution_12b;
mbed_official 155:8435094ec241 233 ADC_InitStruct->ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
mbed_official 155:8435094ec241 234 ADC_InitStruct->ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
mbed_official 155:8435094ec241 235 ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
mbed_official 155:8435094ec241 236 ADC_InitStruct->ADC_OverrunMode = DISABLE;
mbed_official 155:8435094ec241 237 ADC_InitStruct->ADC_AutoInjMode = DISABLE;
mbed_official 155:8435094ec241 238 ADC_InitStruct->ADC_NbrOfRegChannel = 1;
mbed_official 155:8435094ec241 239 }
mbed_official 155:8435094ec241 240
mbed_official 155:8435094ec241 241 /**
mbed_official 155:8435094ec241 242 * @brief Initializes the ADCx peripheral according to the specified parameters
mbed_official 155:8435094ec241 243 * in the ADC_InitStruct.
mbed_official 155:8435094ec241 244 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 245 * @param ADC_InjectInitStruct: pointer to an ADC_InjecInitTypeDef structure that contains
mbed_official 155:8435094ec241 246 * the configuration information for the specified ADC injected channel.
mbed_official 155:8435094ec241 247 * @retval None
mbed_official 155:8435094ec241 248 */
mbed_official 155:8435094ec241 249 void ADC_InjectedInit(ADC_TypeDef* ADCx, ADC_InjectedInitTypeDef* ADC_InjectedInitStruct)
mbed_official 155:8435094ec241 250 {
mbed_official 155:8435094ec241 251 uint32_t tmpreg1 = 0;
mbed_official 155:8435094ec241 252 /* Check the parameters */
mbed_official 155:8435094ec241 253 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 254 assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_InjectedInitStruct->ADC_ExternalTrigInjecConvEvent));
mbed_official 155:8435094ec241 255 assert_param(IS_EXTERNALTRIGINJ_EDGE(ADC_InjectedInitStruct->ADC_ExternalTrigInjecEventEdge));
mbed_official 155:8435094ec241 256 assert_param(IS_ADC_INJECTED_LENGTH(ADC_InjectedInitStruct->ADC_NbrOfInjecChannel));
mbed_official 155:8435094ec241 257 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct->ADC_InjecSequence1));
mbed_official 155:8435094ec241 258 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct->ADC_InjecSequence2));
mbed_official 155:8435094ec241 259 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct->ADC_InjecSequence3));
mbed_official 155:8435094ec241 260 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedInitStruct->ADC_InjecSequence4));
mbed_official 155:8435094ec241 261
mbed_official 155:8435094ec241 262 /*---------------------------- ADCx JSQR Configuration -----------------*/
mbed_official 155:8435094ec241 263 /* Get the ADCx JSQR value */
mbed_official 155:8435094ec241 264 tmpreg1 = ADCx->JSQR;
mbed_official 155:8435094ec241 265 /* Clear L bits */
mbed_official 155:8435094ec241 266 tmpreg1 &= JSQR_CLEAR_Mask;
mbed_official 155:8435094ec241 267 /* Configure ADCx: Injected channel sequence length, external trigger,
mbed_official 155:8435094ec241 268 external trigger edge and sequences
mbed_official 155:8435094ec241 269 */
mbed_official 155:8435094ec241 270 tmpreg1 = (uint32_t) ((ADC_InjectedInitStruct->ADC_NbrOfInjecChannel - (uint8_t)1) |
mbed_official 155:8435094ec241 271 ADC_InjectedInitStruct->ADC_ExternalTrigInjecConvEvent |
mbed_official 155:8435094ec241 272 ADC_InjectedInitStruct->ADC_ExternalTrigInjecEventEdge |
mbed_official 155:8435094ec241 273 (uint32_t)((ADC_InjectedInitStruct->ADC_InjecSequence1) << 8) |
mbed_official 155:8435094ec241 274 (uint32_t)((ADC_InjectedInitStruct->ADC_InjecSequence2) << 14) |
mbed_official 155:8435094ec241 275 (uint32_t)((ADC_InjectedInitStruct->ADC_InjecSequence3) << 20) |
mbed_official 155:8435094ec241 276 (uint32_t)((ADC_InjectedInitStruct->ADC_InjecSequence4) << 26));
mbed_official 155:8435094ec241 277 /* Write to ADCx SQR1 */
mbed_official 155:8435094ec241 278 ADCx->JSQR = tmpreg1;
mbed_official 155:8435094ec241 279 }
mbed_official 155:8435094ec241 280
mbed_official 155:8435094ec241 281 /**
mbed_official 155:8435094ec241 282 * @brief Fills each ADC_InjectedInitStruct member with its default value.
mbed_official 155:8435094ec241 283 * @param ADC_InjectedInitStruct : pointer to an ADC_InjectedInitTypeDef structure which will be initialized.
mbed_official 155:8435094ec241 284 * @retval None
mbed_official 155:8435094ec241 285 */
mbed_official 155:8435094ec241 286 void ADC_InjectedStructInit(ADC_InjectedInitTypeDef* ADC_InjectedInitStruct)
mbed_official 155:8435094ec241 287 {
mbed_official 155:8435094ec241 288 ADC_InjectedInitStruct->ADC_ExternalTrigInjecConvEvent = ADC_ExternalTrigInjecConvEvent_0;
mbed_official 155:8435094ec241 289 ADC_InjectedInitStruct->ADC_ExternalTrigInjecEventEdge = ADC_ExternalTrigInjecEventEdge_None;
mbed_official 155:8435094ec241 290 ADC_InjectedInitStruct->ADC_NbrOfInjecChannel = 1;
mbed_official 155:8435094ec241 291 ADC_InjectedInitStruct->ADC_InjecSequence1 = ADC_InjectedChannel_1;
mbed_official 155:8435094ec241 292 ADC_InjectedInitStruct->ADC_InjecSequence2 = ADC_InjectedChannel_1;
mbed_official 155:8435094ec241 293 ADC_InjectedInitStruct->ADC_InjecSequence3 = ADC_InjectedChannel_1;
mbed_official 155:8435094ec241 294 ADC_InjectedInitStruct->ADC_InjecSequence4 = ADC_InjectedChannel_1;
mbed_official 155:8435094ec241 295 }
mbed_official 155:8435094ec241 296
mbed_official 155:8435094ec241 297 /**
mbed_official 155:8435094ec241 298 * @brief Initializes the ADCs peripherals according to the specified parameters
mbed_official 155:8435094ec241 299 * in the ADC_CommonInitStruct.
mbed_official 155:8435094ec241 300 * @param ADCx: where x can be 1 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 301 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
mbed_official 155:8435094ec241 302 * that contains the configuration information for All ADCs peripherals.
mbed_official 155:8435094ec241 303 * @retval None
mbed_official 155:8435094ec241 304 */
mbed_official 155:8435094ec241 305 void ADC_CommonInit(ADC_TypeDef* ADCx, ADC_CommonInitTypeDef* ADC_CommonInitStruct)
mbed_official 155:8435094ec241 306 {
mbed_official 155:8435094ec241 307 uint32_t tmpreg1 = 0;
mbed_official 155:8435094ec241 308 /* Check the parameters */
mbed_official 155:8435094ec241 309 assert_param(IS_ADC_MODE(ADC_CommonInitStruct->ADC_Mode));
mbed_official 155:8435094ec241 310 assert_param(IS_ADC_CLOCKMODE(ADC_CommonInitStruct->ADC_Clock));
mbed_official 155:8435094ec241 311 assert_param(IS_ADC_DMA_MODE(ADC_CommonInitStruct->ADC_DMAMode));
mbed_official 155:8435094ec241 312 assert_param(IS_ADC_DMA_ACCESS_MODE(ADC_CommonInitStruct->ADC_DMAAccessMode));
mbed_official 155:8435094ec241 313 assert_param(IS_ADC_TWOSAMPLING_DELAY(ADC_CommonInitStruct->ADC_TwoSamplingDelay));
mbed_official 155:8435094ec241 314
mbed_official 155:8435094ec241 315 if((ADCx == ADC1) || (ADCx == ADC2))
mbed_official 155:8435094ec241 316 {
mbed_official 155:8435094ec241 317 /* Get the ADC CCR value */
mbed_official 155:8435094ec241 318 tmpreg1 = ADC1_2->CCR;
mbed_official 155:8435094ec241 319
mbed_official 155:8435094ec241 320 /* Clear MULTI, DELAY, DMA and ADCPRE bits */
mbed_official 155:8435094ec241 321 tmpreg1 &= CCR_CLEAR_MASK;
mbed_official 155:8435094ec241 322 }
mbed_official 155:8435094ec241 323 else
mbed_official 155:8435094ec241 324 {
mbed_official 155:8435094ec241 325 /* Get the ADC CCR value */
mbed_official 155:8435094ec241 326 tmpreg1 = ADC3_4->CCR;
mbed_official 155:8435094ec241 327
mbed_official 155:8435094ec241 328 /* Clear MULTI, DELAY, DMA and ADCPRE bits */
mbed_official 155:8435094ec241 329 tmpreg1 &= CCR_CLEAR_MASK;
mbed_official 155:8435094ec241 330 }
mbed_official 155:8435094ec241 331 /*---------------------------- ADC CCR Configuration -----------------*/
mbed_official 155:8435094ec241 332 /* Configure ADCx: Multi mode, Delay between two sampling time, ADC clock, DMA mode
mbed_official 155:8435094ec241 333 and DMA access mode for dual mode */
mbed_official 155:8435094ec241 334 /* Set MULTI bits according to ADC_Mode value */
mbed_official 155:8435094ec241 335 /* Set CKMODE bits according to ADC_Clock value */
mbed_official 155:8435094ec241 336 /* Set MDMA bits according to ADC_DMAAccessMode value */
mbed_official 155:8435094ec241 337 /* Set DMACFG bits according to ADC_DMAMode value */
mbed_official 155:8435094ec241 338 /* Set DELAY bits according to ADC_TwoSamplingDelay value */
mbed_official 155:8435094ec241 339 tmpreg1 |= (uint32_t)(ADC_CommonInitStruct->ADC_Mode |
mbed_official 155:8435094ec241 340 ADC_CommonInitStruct->ADC_Clock |
mbed_official 155:8435094ec241 341 ADC_CommonInitStruct->ADC_DMAAccessMode |
mbed_official 155:8435094ec241 342 (uint32_t)(ADC_CommonInitStruct->ADC_DMAMode << 12) |
mbed_official 155:8435094ec241 343 (uint32_t)((uint32_t)ADC_CommonInitStruct->ADC_TwoSamplingDelay << 8));
mbed_official 155:8435094ec241 344
mbed_official 155:8435094ec241 345 if((ADCx == ADC1) || (ADCx == ADC2))
mbed_official 155:8435094ec241 346 {
mbed_official 155:8435094ec241 347 /* Write to ADC CCR */
mbed_official 155:8435094ec241 348 ADC1_2->CCR = tmpreg1;
mbed_official 155:8435094ec241 349 }
mbed_official 155:8435094ec241 350 else
mbed_official 155:8435094ec241 351 {
mbed_official 155:8435094ec241 352 /* Write to ADC CCR */
mbed_official 155:8435094ec241 353 ADC3_4->CCR = tmpreg1;
mbed_official 155:8435094ec241 354 }
mbed_official 155:8435094ec241 355 }
mbed_official 155:8435094ec241 356
mbed_official 155:8435094ec241 357 /**
mbed_official 155:8435094ec241 358 * @brief Fills each ADC_CommonInitStruct member with its default value.
mbed_official 155:8435094ec241 359 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
mbed_official 155:8435094ec241 360 * which will be initialized.
mbed_official 155:8435094ec241 361 * @retval None
mbed_official 155:8435094ec241 362 */
mbed_official 155:8435094ec241 363 void ADC_CommonStructInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct)
mbed_official 155:8435094ec241 364 {
mbed_official 155:8435094ec241 365 /* Initialize the ADC_Mode member */
mbed_official 155:8435094ec241 366 ADC_CommonInitStruct->ADC_Mode = ADC_Mode_Independent;
mbed_official 155:8435094ec241 367
mbed_official 155:8435094ec241 368 /* initialize the ADC_Clock member */
mbed_official 155:8435094ec241 369 ADC_CommonInitStruct->ADC_Clock = ADC_Clock_AsynClkMode;
mbed_official 155:8435094ec241 370
mbed_official 155:8435094ec241 371 /* Initialize the ADC_DMAAccessMode member */
mbed_official 155:8435094ec241 372 ADC_CommonInitStruct->ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
mbed_official 155:8435094ec241 373
mbed_official 155:8435094ec241 374 /* Initialize the ADC_DMAMode member */
mbed_official 155:8435094ec241 375 ADC_CommonInitStruct->ADC_DMAMode = ADC_DMAMode_OneShot;
mbed_official 155:8435094ec241 376
mbed_official 155:8435094ec241 377 /* Initialize the ADC_TwoSamplingDelay member */
mbed_official 155:8435094ec241 378 ADC_CommonInitStruct->ADC_TwoSamplingDelay = 0;
mbed_official 155:8435094ec241 379
mbed_official 155:8435094ec241 380 }
mbed_official 155:8435094ec241 381
mbed_official 155:8435094ec241 382 /**
mbed_official 155:8435094ec241 383 * @brief Enables or disables the specified ADC peripheral.
mbed_official 155:8435094ec241 384 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 385 * @param NewState: new state of the ADCx peripheral.
mbed_official 155:8435094ec241 386 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 387 * @retval None
mbed_official 155:8435094ec241 388 */
mbed_official 155:8435094ec241 389 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 390 {
mbed_official 155:8435094ec241 391 /* Check the parameters */
mbed_official 155:8435094ec241 392 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 393 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 394
mbed_official 155:8435094ec241 395 if (NewState != DISABLE)
mbed_official 155:8435094ec241 396 {
mbed_official 155:8435094ec241 397 /* Set the ADEN bit */
mbed_official 155:8435094ec241 398 ADCx->CR |= ADC_CR_ADEN;
mbed_official 155:8435094ec241 399 }
mbed_official 155:8435094ec241 400 else
mbed_official 155:8435094ec241 401 {
mbed_official 155:8435094ec241 402 /* Disable the selected ADC peripheral: Set the ADDIS bit */
mbed_official 155:8435094ec241 403 ADCx->CR |= ADC_CR_ADDIS;
mbed_official 155:8435094ec241 404 }
mbed_official 155:8435094ec241 405 }
mbed_official 155:8435094ec241 406
mbed_official 155:8435094ec241 407 /**
mbed_official 155:8435094ec241 408 * @brief Starts the selected ADC calibration process.
mbed_official 155:8435094ec241 409 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 410 * @retval None
mbed_official 155:8435094ec241 411 */
mbed_official 155:8435094ec241 412 void ADC_StartCalibration(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 413 {
mbed_official 155:8435094ec241 414 /* Check the parameters */
mbed_official 155:8435094ec241 415 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 416
mbed_official 155:8435094ec241 417 /* Set the ADCAL bit */
mbed_official 155:8435094ec241 418 ADCx->CR |= ADC_CR_ADCAL;
mbed_official 155:8435094ec241 419 }
mbed_official 155:8435094ec241 420
mbed_official 155:8435094ec241 421 /**
mbed_official 155:8435094ec241 422 * @brief Returns the ADCx calibration value.
mbed_official 155:8435094ec241 423 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 424 * @retval None
mbed_official 155:8435094ec241 425 */
mbed_official 155:8435094ec241 426 uint32_t ADC_GetCalibrationValue(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 427 {
mbed_official 155:8435094ec241 428 /* Check the parameters */
mbed_official 155:8435094ec241 429 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 430
mbed_official 155:8435094ec241 431 /* Return the selected ADC calibration value */
mbed_official 155:8435094ec241 432 return (uint32_t)ADCx->CALFACT;
mbed_official 155:8435094ec241 433 }
mbed_official 155:8435094ec241 434
mbed_official 155:8435094ec241 435 /**
mbed_official 155:8435094ec241 436 * @brief Sets the ADCx calibration register.
mbed_official 155:8435094ec241 437 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 438 * @retval None
mbed_official 155:8435094ec241 439 */
mbed_official 155:8435094ec241 440 void ADC_SetCalibrationValue(ADC_TypeDef* ADCx, uint32_t ADC_Calibration)
mbed_official 155:8435094ec241 441 {
mbed_official 155:8435094ec241 442 /* Check the parameters */
mbed_official 155:8435094ec241 443 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 444
mbed_official 155:8435094ec241 445 /* Set the ADC calibration register value */
mbed_official 155:8435094ec241 446 ADCx->CALFACT = ADC_Calibration;
mbed_official 155:8435094ec241 447 }
mbed_official 155:8435094ec241 448
mbed_official 155:8435094ec241 449 /**
mbed_official 155:8435094ec241 450 * @brief Select the ADC calibration mode.
mbed_official 155:8435094ec241 451 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 452 * @param ADC_CalibrationMode: the ADC calibration mode.
mbed_official 155:8435094ec241 453 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 454 * @arg ADC_CalibrationMode_Single: to select the calibration for single channel
mbed_official 155:8435094ec241 455 * @arg ADC_CalibrationMode_Differential: to select the calibration for differential channel
mbed_official 155:8435094ec241 456 * @retval None
mbed_official 155:8435094ec241 457 */
mbed_official 155:8435094ec241 458 void ADC_SelectCalibrationMode(ADC_TypeDef* ADCx, uint32_t ADC_CalibrationMode)
mbed_official 155:8435094ec241 459 {
mbed_official 155:8435094ec241 460 /* Check the parameters */
mbed_official 155:8435094ec241 461 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 462 assert_param(IS_ADC_CALIBRATION_MODE(ADC_CalibrationMode));
mbed_official 155:8435094ec241 463 /* Set or Reset the ADCALDIF bit */
mbed_official 155:8435094ec241 464 ADCx->CR &= (~ADC_CR_ADCALDIF);
mbed_official 155:8435094ec241 465 ADCx->CR |= ADC_CalibrationMode;
mbed_official 155:8435094ec241 466
mbed_official 155:8435094ec241 467 }
mbed_official 155:8435094ec241 468
mbed_official 155:8435094ec241 469 /**
mbed_official 155:8435094ec241 470 * @brief Gets the selected ADC calibration status.
mbed_official 155:8435094ec241 471 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 472 * @retval The new state of ADC calibration (SET or RESET).
mbed_official 155:8435094ec241 473 */
mbed_official 155:8435094ec241 474 FlagStatus ADC_GetCalibrationStatus(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 475 {
mbed_official 155:8435094ec241 476 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 477 /* Check the parameters */
mbed_official 155:8435094ec241 478 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 479 /* Check the status of CAL bit */
mbed_official 155:8435094ec241 480 if ((ADCx->CR & ADC_CR_ADCAL) != (uint32_t)RESET)
mbed_official 155:8435094ec241 481 {
mbed_official 155:8435094ec241 482 /* CAL bit is set: calibration on going */
mbed_official 155:8435094ec241 483 bitstatus = SET;
mbed_official 155:8435094ec241 484 }
mbed_official 155:8435094ec241 485 else
mbed_official 155:8435094ec241 486 {
mbed_official 155:8435094ec241 487 /* CAL bit is reset: end of calibration */
mbed_official 155:8435094ec241 488 bitstatus = RESET;
mbed_official 155:8435094ec241 489 }
mbed_official 155:8435094ec241 490 /* Return the CAL bit status */
mbed_official 155:8435094ec241 491 return bitstatus;
mbed_official 155:8435094ec241 492 }
mbed_official 155:8435094ec241 493
mbed_official 155:8435094ec241 494 /**
mbed_official 155:8435094ec241 495 * @brief ADC Disable Command.
mbed_official 155:8435094ec241 496 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 497 * @retval None
mbed_official 155:8435094ec241 498 */
mbed_official 155:8435094ec241 499 void ADC_DisableCmd(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 500 {
mbed_official 155:8435094ec241 501 /* Check the parameters */
mbed_official 155:8435094ec241 502 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 503
mbed_official 155:8435094ec241 504 /* Set the ADDIS bit */
mbed_official 155:8435094ec241 505 ADCx->CR |= ADC_CR_ADDIS;
mbed_official 155:8435094ec241 506 }
mbed_official 155:8435094ec241 507
mbed_official 155:8435094ec241 508
mbed_official 155:8435094ec241 509 /**
mbed_official 155:8435094ec241 510 * @brief Gets the selected ADC disable command Status.
mbed_official 155:8435094ec241 511 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 512 * @retval The new state of ADC ADC disable command (SET or RESET).
mbed_official 155:8435094ec241 513 */
mbed_official 155:8435094ec241 514 FlagStatus ADC_GetDisableCmdStatus(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 515 {
mbed_official 155:8435094ec241 516 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 517 /* Check the parameters */
mbed_official 155:8435094ec241 518 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 519
mbed_official 155:8435094ec241 520 /* Check the status of ADDIS bit */
mbed_official 155:8435094ec241 521 if ((ADCx->CR & ADC_CR_ADDIS) != (uint32_t)RESET)
mbed_official 155:8435094ec241 522 {
mbed_official 155:8435094ec241 523 /* ADDIS bit is set */
mbed_official 155:8435094ec241 524 bitstatus = SET;
mbed_official 155:8435094ec241 525 }
mbed_official 155:8435094ec241 526 else
mbed_official 155:8435094ec241 527 {
mbed_official 155:8435094ec241 528 /* ADDIS bit is reset */
mbed_official 155:8435094ec241 529 bitstatus = RESET;
mbed_official 155:8435094ec241 530 }
mbed_official 155:8435094ec241 531 /* Return the ADDIS bit status */
mbed_official 155:8435094ec241 532 return bitstatus;
mbed_official 155:8435094ec241 533 }
mbed_official 155:8435094ec241 534
mbed_official 155:8435094ec241 535 /**
mbed_official 155:8435094ec241 536 * @brief Enables or disables the specified ADC Voltage Regulator.
mbed_official 155:8435094ec241 537 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 538 * @param NewState: new state of the ADCx Voltage Regulator.
mbed_official 155:8435094ec241 539 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 540 * @retval None
mbed_official 155:8435094ec241 541 */
mbed_official 155:8435094ec241 542 void ADC_VoltageRegulatorCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 543 {
mbed_official 155:8435094ec241 544 /* Check the parameters */
mbed_official 155:8435094ec241 545 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 546 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 547
mbed_official 155:8435094ec241 548 /* set the intermediate state before moving the ADC voltage regulator
mbed_official 155:8435094ec241 549 from enable state to disable state or from disable state to enable state */
mbed_official 155:8435094ec241 550 ADCx->CR &= ~(ADC_CR_ADVREGEN);
mbed_official 155:8435094ec241 551
mbed_official 155:8435094ec241 552 if (NewState != DISABLE)
mbed_official 155:8435094ec241 553 {
mbed_official 155:8435094ec241 554 /* Set the ADVREGEN bit 0 */
mbed_official 155:8435094ec241 555 ADCx->CR |= ADC_CR_ADVREGEN_0;
mbed_official 155:8435094ec241 556 }
mbed_official 155:8435094ec241 557 else
mbed_official 155:8435094ec241 558 {
mbed_official 155:8435094ec241 559 /* Set the ADVREGEN bit 1 */
mbed_official 155:8435094ec241 560 ADCx->CR |=ADC_CR_ADVREGEN_1;
mbed_official 155:8435094ec241 561 }
mbed_official 155:8435094ec241 562 }
mbed_official 155:8435094ec241 563
mbed_official 155:8435094ec241 564 /**
mbed_official 155:8435094ec241 565 * @brief Selectes the differential mode for a specific channel
mbed_official 155:8435094ec241 566 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 567 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
mbed_official 155:8435094ec241 568 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 569 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 570 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 571 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 572 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 573 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 574 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 575 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 576 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 577 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 578 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 579 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 580 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 581 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 582 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 583 * @note : Channel 15, 16 and 17 are fixed to single-ended inputs mode.
mbed_official 155:8435094ec241 584 * @retval None
mbed_official 155:8435094ec241 585 */
mbed_official 155:8435094ec241 586 void ADC_SelectDifferentialMode(ADC_TypeDef* ADCx, uint8_t ADC_Channel, FunctionalState NewState)
mbed_official 155:8435094ec241 587 {
mbed_official 155:8435094ec241 588 /* Check the parameters */
mbed_official 155:8435094ec241 589 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 590 assert_param(IS_ADC_DIFFCHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 591 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 592
mbed_official 155:8435094ec241 593 if (NewState != DISABLE)
mbed_official 155:8435094ec241 594 {
mbed_official 155:8435094ec241 595 /* Set the DIFSEL bit */
mbed_official 155:8435094ec241 596 ADCx->DIFSEL |= (uint32_t)(1 << ADC_Channel );
mbed_official 155:8435094ec241 597 }
mbed_official 155:8435094ec241 598 else
mbed_official 155:8435094ec241 599 {
mbed_official 155:8435094ec241 600 /* Reset the DIFSEL bit */
mbed_official 155:8435094ec241 601 ADCx->DIFSEL &= ~(uint32_t)(1 << ADC_Channel);
mbed_official 155:8435094ec241 602 }
mbed_official 155:8435094ec241 603 }
mbed_official 155:8435094ec241 604
mbed_official 155:8435094ec241 605 /**
mbed_official 155:8435094ec241 606 * @brief Selects the Queue Of Context Mode for injected channels.
mbed_official 155:8435094ec241 607 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 608 * @param NewState: new state of the Queue Of Context Mode.
mbed_official 155:8435094ec241 609 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 610 * @retval None
mbed_official 155:8435094ec241 611 */
mbed_official 155:8435094ec241 612 void ADC_SelectQueueOfContextMode(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 613 {
mbed_official 155:8435094ec241 614 /* Check the parameters */
mbed_official 155:8435094ec241 615 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 616 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 617
mbed_official 155:8435094ec241 618 if (NewState != DISABLE)
mbed_official 155:8435094ec241 619 {
mbed_official 155:8435094ec241 620 /* Set the JQM bit */
mbed_official 155:8435094ec241 621 ADCx->CFGR |= (uint32_t)(ADC_CFGR_JQM );
mbed_official 155:8435094ec241 622 }
mbed_official 155:8435094ec241 623 else
mbed_official 155:8435094ec241 624 {
mbed_official 155:8435094ec241 625 /* Reset the JQM bit */
mbed_official 155:8435094ec241 626 ADCx->CFGR &= ~(uint32_t)(ADC_CFGR_JQM);
mbed_official 155:8435094ec241 627 }
mbed_official 155:8435094ec241 628 }
mbed_official 155:8435094ec241 629
mbed_official 155:8435094ec241 630 /**
mbed_official 155:8435094ec241 631 * @brief Selects the ADC Delayed Conversion Mode.
mbed_official 155:8435094ec241 632 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 633 * @param NewState: new state of the ADC Delayed Conversion Mode.
mbed_official 155:8435094ec241 634 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 635 * @retval None
mbed_official 155:8435094ec241 636 */
mbed_official 155:8435094ec241 637 void ADC_AutoDelayCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 638 {
mbed_official 155:8435094ec241 639 /* Check the parameters */
mbed_official 155:8435094ec241 640 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 641 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 642
mbed_official 155:8435094ec241 643 if (NewState != DISABLE)
mbed_official 155:8435094ec241 644 {
mbed_official 155:8435094ec241 645 /* Set the AUTDLY bit */
mbed_official 155:8435094ec241 646 ADCx->CFGR |= (uint32_t)(ADC_CFGR_AUTDLY );
mbed_official 155:8435094ec241 647 }
mbed_official 155:8435094ec241 648 else
mbed_official 155:8435094ec241 649 {
mbed_official 155:8435094ec241 650 /* Reset the AUTDLY bit */
mbed_official 155:8435094ec241 651 ADCx->CFGR &= ~(uint32_t)(ADC_CFGR_AUTDLY);
mbed_official 155:8435094ec241 652 }
mbed_official 155:8435094ec241 653 }
mbed_official 155:8435094ec241 654
mbed_official 155:8435094ec241 655 /**
mbed_official 155:8435094ec241 656 * @}
mbed_official 155:8435094ec241 657 */
mbed_official 155:8435094ec241 658
mbed_official 155:8435094ec241 659 /** @defgroup ADC_Group2 Analog Watchdog configuration functions
mbed_official 155:8435094ec241 660 * @brief Analog Watchdog configuration functions
mbed_official 155:8435094ec241 661 *
mbed_official 155:8435094ec241 662 @verbatim
mbed_official 155:8435094ec241 663 ===============================================================================
mbed_official 155:8435094ec241 664 ##### Analog Watchdog configuration functions #####
mbed_official 155:8435094ec241 665 ===============================================================================
mbed_official 155:8435094ec241 666
mbed_official 155:8435094ec241 667 [..] This section provides functions allowing to configure the 3 Analog Watchdogs
mbed_official 155:8435094ec241 668 (AWDG1, AWDG2 and AWDG3) in the ADC.
mbed_official 155:8435094ec241 669
mbed_official 155:8435094ec241 670 [..] A typical configuration Analog Watchdog is done following these steps :
mbed_official 155:8435094ec241 671 (#) The ADC guarded channel(s) is (are) selected using the functions:
mbed_official 155:8435094ec241 672 (++) ADC_AnalogWatchdog1SingleChannelConfig().
mbed_official 155:8435094ec241 673 (++) ADC_AnalogWatchdog2SingleChannelConfig().
mbed_official 155:8435094ec241 674 (++) ADC_AnalogWatchdog3SingleChannelConfig().
mbed_official 155:8435094ec241 675
mbed_official 155:8435094ec241 676 (#) The Analog watchdog lower and higher threshold are configured using the functions:
mbed_official 155:8435094ec241 677 (++) ADC_AnalogWatchdog1ThresholdsConfig().
mbed_official 155:8435094ec241 678 (++) ADC_AnalogWatchdog2ThresholdsConfig().
mbed_official 155:8435094ec241 679 (++) ADC_AnalogWatchdog3ThresholdsConfig().
mbed_official 155:8435094ec241 680
mbed_official 155:8435094ec241 681 (#) The Analog watchdog is enabled and configured to enable the check, on one
mbed_official 155:8435094ec241 682 or more channels, using the function:
mbed_official 155:8435094ec241 683 (++) ADC_AnalogWatchdogCmd().
mbed_official 155:8435094ec241 684
mbed_official 155:8435094ec241 685 @endverbatim
mbed_official 155:8435094ec241 686 * @{
mbed_official 155:8435094ec241 687 */
mbed_official 155:8435094ec241 688
mbed_official 155:8435094ec241 689 /**
mbed_official 155:8435094ec241 690 * @brief Enables or disables the analog watchdog on single/all regular
mbed_official 155:8435094ec241 691 * or injected channels
mbed_official 155:8435094ec241 692 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 693 * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration.
mbed_official 155:8435094ec241 694 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 695 * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single regular channel
mbed_official 155:8435094ec241 696 * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single injected channel
mbed_official 155:8435094ec241 697 * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a single regular or injected channel
mbed_official 155:8435094ec241 698 * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular channel
mbed_official 155:8435094ec241 699 * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected channel
mbed_official 155:8435094ec241 700 * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all regular and injected channels
mbed_official 155:8435094ec241 701 * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog
mbed_official 155:8435094ec241 702 * @retval None
mbed_official 155:8435094ec241 703 */
mbed_official 155:8435094ec241 704 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog)
mbed_official 155:8435094ec241 705 {
mbed_official 155:8435094ec241 706 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 707 /* Check the parameters */
mbed_official 155:8435094ec241 708 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 709 assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog));
mbed_official 155:8435094ec241 710 /* Get the old register value */
mbed_official 155:8435094ec241 711 tmpreg = ADCx->CFGR;
mbed_official 155:8435094ec241 712 /* Clear AWDEN, AWDENJ and AWDSGL bits */
mbed_official 155:8435094ec241 713 tmpreg &= ~(uint32_t)(ADC_CFGR_AWD1SGL|ADC_CFGR_AWD1EN|ADC_CFGR_JAWD1EN);
mbed_official 155:8435094ec241 714 /* Set the analog watchdog enable mode */
mbed_official 155:8435094ec241 715 tmpreg |= ADC_AnalogWatchdog;
mbed_official 155:8435094ec241 716 /* Store the new register value */
mbed_official 155:8435094ec241 717 ADCx->CFGR = tmpreg;
mbed_official 155:8435094ec241 718 }
mbed_official 155:8435094ec241 719
mbed_official 155:8435094ec241 720 /**
mbed_official 155:8435094ec241 721 * @brief Configures the high and low thresholds of the analog watchdog1.
mbed_official 155:8435094ec241 722 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 723 * @param HighThreshold: the ADC analog watchdog High threshold value.
mbed_official 155:8435094ec241 724 * This parameter must be a 12bit value.
mbed_official 155:8435094ec241 725 * @param LowThreshold: the ADC analog watchdog Low threshold value.
mbed_official 155:8435094ec241 726 * This parameter must be a 12bit value.
mbed_official 155:8435094ec241 727 * @retval None
mbed_official 155:8435094ec241 728 */
mbed_official 155:8435094ec241 729 void ADC_AnalogWatchdog1ThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,
mbed_official 155:8435094ec241 730 uint16_t LowThreshold)
mbed_official 155:8435094ec241 731 {
mbed_official 155:8435094ec241 732 /* Check the parameters */
mbed_official 155:8435094ec241 733 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 734 assert_param(IS_ADC_THRESHOLD(HighThreshold));
mbed_official 155:8435094ec241 735 assert_param(IS_ADC_THRESHOLD(LowThreshold));
mbed_official 155:8435094ec241 736 /* Set the ADCx high threshold */
mbed_official 155:8435094ec241 737 ADCx->TR1 &= ~(uint32_t)ADC_TR1_HT1;
mbed_official 155:8435094ec241 738 ADCx->TR1 |= (uint32_t)((uint32_t)HighThreshold << 16);
mbed_official 155:8435094ec241 739
mbed_official 155:8435094ec241 740 /* Set the ADCx low threshold */
mbed_official 155:8435094ec241 741 ADCx->TR1 &= ~(uint32_t)ADC_TR1_LT1;
mbed_official 155:8435094ec241 742 ADCx->TR1 |= LowThreshold;
mbed_official 155:8435094ec241 743 }
mbed_official 155:8435094ec241 744
mbed_official 155:8435094ec241 745 /**
mbed_official 155:8435094ec241 746 * @brief Configures the high and low thresholds of the analog watchdog2.
mbed_official 155:8435094ec241 747 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 748 * @param HighThreshold: the ADC analog watchdog High threshold value.
mbed_official 155:8435094ec241 749 * This parameter must be a 8bit value.
mbed_official 155:8435094ec241 750 * @param LowThreshold: the ADC analog watchdog Low threshold value.
mbed_official 155:8435094ec241 751 * This parameter must be a 8bit value.
mbed_official 155:8435094ec241 752 * @retval None
mbed_official 155:8435094ec241 753 */
mbed_official 155:8435094ec241 754 void ADC_AnalogWatchdog2ThresholdsConfig(ADC_TypeDef* ADCx, uint8_t HighThreshold,
mbed_official 155:8435094ec241 755 uint8_t LowThreshold)
mbed_official 155:8435094ec241 756 {
mbed_official 155:8435094ec241 757 /* Check the parameters */
mbed_official 155:8435094ec241 758 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 759
mbed_official 155:8435094ec241 760 /* Set the ADCx high threshold */
mbed_official 155:8435094ec241 761 ADCx->TR2 &= ~(uint32_t)ADC_TR2_HT2;
mbed_official 155:8435094ec241 762 ADCx->TR2 |= (uint32_t)((uint32_t)HighThreshold << 16);
mbed_official 155:8435094ec241 763
mbed_official 155:8435094ec241 764 /* Set the ADCx low threshold */
mbed_official 155:8435094ec241 765 ADCx->TR2 &= ~(uint32_t)ADC_TR2_LT2;
mbed_official 155:8435094ec241 766 ADCx->TR2 |= LowThreshold;
mbed_official 155:8435094ec241 767 }
mbed_official 155:8435094ec241 768
mbed_official 155:8435094ec241 769 /**
mbed_official 155:8435094ec241 770 * @brief Configures the high and low thresholds of the analog watchdog3.
mbed_official 155:8435094ec241 771 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 772 * @param HighThreshold: the ADC analog watchdog High threshold value.
mbed_official 155:8435094ec241 773 * This parameter must be a 8bit value.
mbed_official 155:8435094ec241 774 * @param LowThreshold: the ADC analog watchdog Low threshold value.
mbed_official 155:8435094ec241 775 * This parameter must be a 8bit value.
mbed_official 155:8435094ec241 776 * @retval None
mbed_official 155:8435094ec241 777 */
mbed_official 155:8435094ec241 778 void ADC_AnalogWatchdog3ThresholdsConfig(ADC_TypeDef* ADCx, uint8_t HighThreshold,
mbed_official 155:8435094ec241 779 uint8_t LowThreshold)
mbed_official 155:8435094ec241 780 {
mbed_official 155:8435094ec241 781 /* Check the parameters */
mbed_official 155:8435094ec241 782 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 783
mbed_official 155:8435094ec241 784 /* Set the ADCx high threshold */
mbed_official 155:8435094ec241 785 ADCx->TR3 &= ~(uint32_t)ADC_TR3_HT3;
mbed_official 155:8435094ec241 786 ADCx->TR3 |= (uint32_t)((uint32_t)HighThreshold << 16);
mbed_official 155:8435094ec241 787
mbed_official 155:8435094ec241 788 /* Set the ADCx low threshold */
mbed_official 155:8435094ec241 789 ADCx->TR3 &= ~(uint32_t)ADC_TR3_LT3;
mbed_official 155:8435094ec241 790 ADCx->TR3 |= LowThreshold;
mbed_official 155:8435094ec241 791 }
mbed_official 155:8435094ec241 792
mbed_official 155:8435094ec241 793 /**
mbed_official 155:8435094ec241 794 * @brief Configures the analog watchdog 2 guarded single channel
mbed_official 155:8435094ec241 795 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 796 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
mbed_official 155:8435094ec241 797 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 798 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 799 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 800 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 801 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 802 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 803 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 804 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 805 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 806 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 807 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 808 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 809 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 810 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 811 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 812 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 813 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 814 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 815 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 816 * @retval None
mbed_official 155:8435094ec241 817 */
mbed_official 155:8435094ec241 818 void ADC_AnalogWatchdog1SingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel)
mbed_official 155:8435094ec241 819 {
mbed_official 155:8435094ec241 820 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 821 /* Check the parameters */
mbed_official 155:8435094ec241 822 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 823 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 824 /* Get the old register value */
mbed_official 155:8435094ec241 825 tmpreg = ADCx->CFGR;
mbed_official 155:8435094ec241 826 /* Clear the Analog watchdog channel select bits */
mbed_official 155:8435094ec241 827 tmpreg &= ~(uint32_t)ADC_CFGR_AWD1CH;
mbed_official 155:8435094ec241 828 /* Set the Analog watchdog channel */
mbed_official 155:8435094ec241 829 tmpreg |= (uint32_t)((uint32_t)ADC_Channel << 26);
mbed_official 155:8435094ec241 830 /* Store the new register value */
mbed_official 155:8435094ec241 831 ADCx->CFGR = tmpreg;
mbed_official 155:8435094ec241 832 }
mbed_official 155:8435094ec241 833
mbed_official 155:8435094ec241 834 /**
mbed_official 155:8435094ec241 835 * @brief Configures the analog watchdog 2 guarded single channel
mbed_official 155:8435094ec241 836 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 837 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
mbed_official 155:8435094ec241 838 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 839 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 840 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 841 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 842 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 843 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 844 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 845 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 846 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 847 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 848 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 849 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 850 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 851 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 852 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 853 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 854 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 855 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 856 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 857 * @retval None
mbed_official 155:8435094ec241 858 */
mbed_official 155:8435094ec241 859 void ADC_AnalogWatchdog2SingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel)
mbed_official 155:8435094ec241 860 {
mbed_official 155:8435094ec241 861 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 862 /* Check the parameters */
mbed_official 155:8435094ec241 863 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 864 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 865 /* Get the old register value */
mbed_official 155:8435094ec241 866 tmpreg = ADCx->AWD2CR;
mbed_official 155:8435094ec241 867 /* Clear the Analog watchdog channel select bits */
mbed_official 155:8435094ec241 868 tmpreg &= ~(uint32_t)ADC_AWD2CR_AWD2CH;
mbed_official 155:8435094ec241 869 /* Set the Analog watchdog channel */
mbed_official 155:8435094ec241 870 tmpreg |= (uint32_t)1 << (ADC_Channel);
mbed_official 155:8435094ec241 871 /* Store the new register value */
mbed_official 155:8435094ec241 872 ADCx->AWD2CR |= tmpreg;
mbed_official 155:8435094ec241 873 }
mbed_official 155:8435094ec241 874
mbed_official 155:8435094ec241 875 /**
mbed_official 155:8435094ec241 876 * @brief Configures the analog watchdog 3 guarded single channel
mbed_official 155:8435094ec241 877 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 878 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
mbed_official 155:8435094ec241 879 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 880 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 881 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 882 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 883 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 884 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 885 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 886 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 887 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 888 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 889 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 890 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 891 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 892 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 893 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 894 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 895 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 896 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 897 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 898 * @retval None
mbed_official 155:8435094ec241 899 */
mbed_official 155:8435094ec241 900 void ADC_AnalogWatchdog3SingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel)
mbed_official 155:8435094ec241 901 {
mbed_official 155:8435094ec241 902 uint32_t tmpreg = 0;
mbed_official 155:8435094ec241 903 /* Check the parameters */
mbed_official 155:8435094ec241 904 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 905 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 906 /* Get the old register value */
mbed_official 155:8435094ec241 907 tmpreg = ADCx->AWD3CR;
mbed_official 155:8435094ec241 908 /* Clear the Analog watchdog channel select bits */
mbed_official 155:8435094ec241 909 tmpreg &= ~(uint32_t)ADC_AWD3CR_AWD3CH;
mbed_official 155:8435094ec241 910 /* Set the Analog watchdog channel */
mbed_official 155:8435094ec241 911 tmpreg |= (uint32_t)1 << (ADC_Channel);
mbed_official 155:8435094ec241 912 /* Store the new register value */
mbed_official 155:8435094ec241 913 ADCx->AWD3CR |= tmpreg;
mbed_official 155:8435094ec241 914 }
mbed_official 155:8435094ec241 915
mbed_official 155:8435094ec241 916 /**
mbed_official 155:8435094ec241 917 * @}
mbed_official 155:8435094ec241 918 */
mbed_official 155:8435094ec241 919
mbed_official 155:8435094ec241 920 /** @defgroup ADC_Group3 Temperature Sensor - Vrefint (Internal Reference Voltage) and VBAT management functions
mbed_official 155:8435094ec241 921 * @brief Vbat, Temperature Sensor & Vrefint (Internal Reference Voltage) management function
mbed_official 155:8435094ec241 922 *
mbed_official 155:8435094ec241 923 @verbatim
mbed_official 155:8435094ec241 924 ====================================================================================================
mbed_official 155:8435094ec241 925 ##### Temperature Sensor - Vrefint (Internal Reference Voltage) and VBAT management functions #####
mbed_official 155:8435094ec241 926 ====================================================================================================
mbed_official 155:8435094ec241 927
mbed_official 155:8435094ec241 928 [..] This section provides a function allowing to enable/ disable the internal
mbed_official 155:8435094ec241 929 connections between the ADC and the Vbat/2, Temperature Sensor and the Vrefint source.
mbed_official 155:8435094ec241 930
mbed_official 155:8435094ec241 931 [..] A typical configuration to get the Temperature sensor and Vrefint channels
mbed_official 155:8435094ec241 932 voltages is done following these steps :
mbed_official 155:8435094ec241 933 (#) Enable the internal connection of Vbat/2, Temperature sensor and Vrefint sources
mbed_official 155:8435094ec241 934 with the ADC channels using:
mbed_official 155:8435094ec241 935 (++) ADC_TempSensorCmd()
mbed_official 155:8435094ec241 936 (++) ADC_VrefintCmd()
mbed_official 155:8435094ec241 937 (++) ADC_VbatCmd()
mbed_official 155:8435094ec241 938
mbed_official 155:8435094ec241 939 (#) select the ADC_Channel_TempSensor and/or ADC_Channel_Vrefint and/or ADC_Channel_Vbat using
mbed_official 155:8435094ec241 940 (++) ADC_RegularChannelConfig() or
mbed_official 155:8435094ec241 941 (++) ADC_InjectedInit() functions
mbed_official 155:8435094ec241 942
mbed_official 155:8435094ec241 943 (#) Get the voltage values, using:
mbed_official 155:8435094ec241 944 (++) ADC_GetConversionValue() or
mbed_official 155:8435094ec241 945 (++) ADC_GetInjectedConversionValue().
mbed_official 155:8435094ec241 946
mbed_official 155:8435094ec241 947 @endverbatim
mbed_official 155:8435094ec241 948 * @{
mbed_official 155:8435094ec241 949 */
mbed_official 155:8435094ec241 950
mbed_official 155:8435094ec241 951 /**
mbed_official 155:8435094ec241 952 * @brief Enables or disables the temperature sensor channel.
mbed_official 155:8435094ec241 953 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 155:8435094ec241 954 * @param NewState: new state of the temperature sensor.
mbed_official 155:8435094ec241 955 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 956 * @retval None
mbed_official 155:8435094ec241 957 */
mbed_official 155:8435094ec241 958 void ADC_TempSensorCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 959 {
mbed_official 155:8435094ec241 960 /* Check the parameters */
mbed_official 155:8435094ec241 961 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 962
mbed_official 155:8435094ec241 963 if (NewState != DISABLE)
mbed_official 155:8435094ec241 964 {
mbed_official 155:8435094ec241 965 /* Enable the temperature sensor channel*/
mbed_official 155:8435094ec241 966 ADC1_2->CCR |= ADC12_CCR_TSEN;
mbed_official 155:8435094ec241 967 }
mbed_official 155:8435094ec241 968 else
mbed_official 155:8435094ec241 969 {
mbed_official 155:8435094ec241 970 /* Disable the temperature sensor channel*/
mbed_official 155:8435094ec241 971 ADC1_2->CCR &= ~(uint32_t)ADC12_CCR_TSEN;
mbed_official 155:8435094ec241 972 }
mbed_official 155:8435094ec241 973 }
mbed_official 155:8435094ec241 974
mbed_official 155:8435094ec241 975 /**
mbed_official 155:8435094ec241 976 * @brief Enables or disables the Vrefint channel.
mbed_official 155:8435094ec241 977 * @param ADCx: where x can be 1 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 978 * @param NewState: new state of the Vrefint.
mbed_official 155:8435094ec241 979 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 980 * @retval None
mbed_official 155:8435094ec241 981 */
mbed_official 155:8435094ec241 982 void ADC_VrefintCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 983 {
mbed_official 155:8435094ec241 984 /* Check the parameters */
mbed_official 155:8435094ec241 985 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 986 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 987
mbed_official 155:8435094ec241 988 if((ADCx == ADC1) || (ADCx == ADC2))
mbed_official 155:8435094ec241 989 {
mbed_official 155:8435094ec241 990 if (NewState != DISABLE)
mbed_official 155:8435094ec241 991 {
mbed_official 155:8435094ec241 992 /* Enable the Vrefint channel*/
mbed_official 155:8435094ec241 993 ADC1_2->CCR |= ADC12_CCR_VREFEN;
mbed_official 155:8435094ec241 994 }
mbed_official 155:8435094ec241 995 else
mbed_official 155:8435094ec241 996 {
mbed_official 155:8435094ec241 997 /* Disable the Vrefint channel*/
mbed_official 155:8435094ec241 998 ADC1_2->CCR &= ~(uint32_t)ADC12_CCR_VREFEN;
mbed_official 155:8435094ec241 999 }
mbed_official 155:8435094ec241 1000 }
mbed_official 155:8435094ec241 1001 else
mbed_official 155:8435094ec241 1002 {
mbed_official 155:8435094ec241 1003 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1004 {
mbed_official 155:8435094ec241 1005 /* Enable the Vrefint channel*/
mbed_official 155:8435094ec241 1006 ADC3_4->CCR |= ADC34_CCR_VREFEN;
mbed_official 155:8435094ec241 1007 }
mbed_official 155:8435094ec241 1008 else
mbed_official 155:8435094ec241 1009 {
mbed_official 155:8435094ec241 1010 /* Disable the Vrefint channel*/
mbed_official 155:8435094ec241 1011 ADC3_4->CCR &= ~(uint32_t)ADC34_CCR_VREFEN;
mbed_official 155:8435094ec241 1012 }
mbed_official 155:8435094ec241 1013 }
mbed_official 155:8435094ec241 1014 }
mbed_official 155:8435094ec241 1015
mbed_official 155:8435094ec241 1016 /**
mbed_official 155:8435094ec241 1017 * @brief Enables or disables the Vbat channel.
mbed_official 155:8435094ec241 1018 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 155:8435094ec241 1019 * @param NewState: new state of the Vbat.
mbed_official 155:8435094ec241 1020 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1021 * @retval None
mbed_official 155:8435094ec241 1022 */
mbed_official 155:8435094ec241 1023 void ADC_VbatCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1024 {
mbed_official 155:8435094ec241 1025 /* Check the parameters */
mbed_official 155:8435094ec241 1026 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1027
mbed_official 155:8435094ec241 1028 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1029 {
mbed_official 155:8435094ec241 1030 /* Enable the Vbat channel*/
mbed_official 155:8435094ec241 1031 ADC1_2->CCR |= ADC12_CCR_VBATEN;
mbed_official 155:8435094ec241 1032 }
mbed_official 155:8435094ec241 1033 else
mbed_official 155:8435094ec241 1034 {
mbed_official 155:8435094ec241 1035 /* Disable the Vbat channel*/
mbed_official 155:8435094ec241 1036 ADC1_2->CCR &= ~(uint32_t)ADC12_CCR_VBATEN;
mbed_official 155:8435094ec241 1037 }
mbed_official 155:8435094ec241 1038 }
mbed_official 155:8435094ec241 1039
mbed_official 155:8435094ec241 1040 /**
mbed_official 155:8435094ec241 1041 * @}
mbed_official 155:8435094ec241 1042 */
mbed_official 155:8435094ec241 1043
mbed_official 155:8435094ec241 1044 /** @defgroup ADC_Group4 Regular Channels Configuration functions
mbed_official 155:8435094ec241 1045 * @brief Regular Channels Configuration functions
mbed_official 155:8435094ec241 1046 *
mbed_official 155:8435094ec241 1047 @verbatim
mbed_official 155:8435094ec241 1048 ===============================================================================
mbed_official 155:8435094ec241 1049 ##### Channels Configuration functions #####
mbed_official 155:8435094ec241 1050 ===============================================================================
mbed_official 155:8435094ec241 1051
mbed_official 155:8435094ec241 1052 [..] This section provides functions allowing to manage the ADC regular channels.
mbed_official 155:8435094ec241 1053
mbed_official 155:8435094ec241 1054 [..] To configure a regular sequence of channels use:
mbed_official 155:8435094ec241 1055 (#) ADC_RegularChannelConfig()
mbed_official 155:8435094ec241 1056 this fuction allows:
mbed_official 155:8435094ec241 1057 (++) Configure the rank in the regular group sequencer for each channel
mbed_official 155:8435094ec241 1058 (++) Configure the sampling time for each channel
mbed_official 155:8435094ec241 1059
mbed_official 155:8435094ec241 1060 (#) ADC_RegularChannelSequencerLengthConfig() to set the length of the regular sequencer
mbed_official 155:8435094ec241 1061
mbed_official 155:8435094ec241 1062 [..] The regular trigger is configured using the following functions:
mbed_official 155:8435094ec241 1063 (#) ADC_SelectExternalTrigger()
mbed_official 155:8435094ec241 1064 (#) ADC_ExternalTriggerPolarityConfig()
mbed_official 155:8435094ec241 1065
mbed_official 155:8435094ec241 1066 [..] The start and the stop conversion are controlled by:
mbed_official 155:8435094ec241 1067 (#) ADC_StartConversion()
mbed_official 155:8435094ec241 1068 (#) ADC_StopConversion()
mbed_official 155:8435094ec241 1069
mbed_official 155:8435094ec241 1070 [..]
mbed_official 155:8435094ec241 1071 (@)Please Note that the following features for regular channels are configurated
mbed_official 155:8435094ec241 1072 using the ADC_Init() function :
mbed_official 155:8435094ec241 1073 (++) continuous mode activation
mbed_official 155:8435094ec241 1074 (++) Resolution
mbed_official 155:8435094ec241 1075 (++) Data Alignement
mbed_official 155:8435094ec241 1076 (++) Overrun Mode.
mbed_official 155:8435094ec241 1077
mbed_official 155:8435094ec241 1078 [..] Get the conversion data: This subsection provides an important function in
mbed_official 155:8435094ec241 1079 the ADC peripheral since it returns the converted data of the current
mbed_official 155:8435094ec241 1080 regular channel. When the Conversion value is read, the EOC Flag is
mbed_official 155:8435094ec241 1081 automatically cleared.
mbed_official 155:8435094ec241 1082
mbed_official 155:8435094ec241 1083 [..] To configure the discontinous mode, the following functions should be used:
mbed_official 155:8435094ec241 1084 (#) ADC_DiscModeChannelCountConfig() to configure the number of discontinuous channel to be converted.
mbed_official 155:8435094ec241 1085 (#) ADC_DiscModeCmd() to enable the discontinuous mode.
mbed_official 155:8435094ec241 1086
mbed_official 155:8435094ec241 1087 [..] To configure and enable/disable the Channel offset use the functions:
mbed_official 155:8435094ec241 1088 (++) ADC_SetChannelOffset1()
mbed_official 155:8435094ec241 1089 (++) ADC_SetChannelOffset2()
mbed_official 155:8435094ec241 1090 (++) ADC_SetChannelOffset3()
mbed_official 155:8435094ec241 1091 (++) ADC_SetChannelOffset4()
mbed_official 155:8435094ec241 1092 (++) ADC_ChannelOffset1Cmd()
mbed_official 155:8435094ec241 1093 (++) ADC_ChannelOffset2Cmd()
mbed_official 155:8435094ec241 1094 (++) ADC_ChannelOffset3Cmd()
mbed_official 155:8435094ec241 1095 (++) ADC_ChannelOffset4Cmd()
mbed_official 155:8435094ec241 1096
mbed_official 155:8435094ec241 1097 @endverbatim
mbed_official 155:8435094ec241 1098 * @{
mbed_official 155:8435094ec241 1099 */
mbed_official 155:8435094ec241 1100
mbed_official 155:8435094ec241 1101 /**
mbed_official 155:8435094ec241 1102 * @brief Configures for the selected ADC regular channel its corresponding
mbed_official 155:8435094ec241 1103 * rank in the sequencer and its sample time.
mbed_official 155:8435094ec241 1104 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1105 * @param ADC_Channel: the ADC channel to configure.
mbed_official 155:8435094ec241 1106 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1107 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 1108 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 1109 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 1110 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 1111 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 1112 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 1113 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 1114 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 1115 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 1116 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 1117 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 1118 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 1119 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 1120 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 1121 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 1122 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 1123 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 1124 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 1125 * @param Rank: The rank in the regular group sequencer. This parameter must be between 1 to 16.
mbed_official 155:8435094ec241 1126 * @param ADC_SampleTime: The sample time value to be set for the selected channel.
mbed_official 155:8435094ec241 1127 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1128 * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
mbed_official 155:8435094ec241 1129 * @arg ADC_SampleTime_2Cycles5: Sample time equal to 2.5 cycles
mbed_official 155:8435094ec241 1130 * @arg ADC_SampleTime_4Cycles5: Sample time equal to 4.5 cycles
mbed_official 155:8435094ec241 1131 * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
mbed_official 155:8435094ec241 1132 * @arg ADC_SampleTime_19Cycles5: Sample time equal to 19.5 cycles
mbed_official 155:8435094ec241 1133 * @arg ADC_SampleTime_61Cycles5: Sample time equal to 61.5 cycles
mbed_official 155:8435094ec241 1134 * @arg ADC_SampleTime_181Cycles5: Sample time equal to 181.5 cycles
mbed_official 155:8435094ec241 1135 * @arg ADC_SampleTime_601Cycles5: Sample time equal to 601.5 cycles
mbed_official 155:8435094ec241 1136 * @retval None
mbed_official 155:8435094ec241 1137 */
mbed_official 155:8435094ec241 1138 void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
mbed_official 155:8435094ec241 1139 {
mbed_official 155:8435094ec241 1140 uint32_t tmpreg1 = 0, tmpreg2 = 0;
mbed_official 155:8435094ec241 1141 /* Check the parameters */
mbed_official 155:8435094ec241 1142 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1143 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 1144 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
mbed_official 155:8435094ec241 1145
mbed_official 155:8435094ec241 1146 /* Regular sequence configuration */
mbed_official 155:8435094ec241 1147 /* For Rank 1 to 4 */
mbed_official 155:8435094ec241 1148 if (Rank < 5)
mbed_official 155:8435094ec241 1149 {
mbed_official 155:8435094ec241 1150 /* Get the old register value */
mbed_official 155:8435094ec241 1151 tmpreg1 = ADCx->SQR1;
mbed_official 155:8435094ec241 1152 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1153 tmpreg2 = 0x1F << (6 * (Rank ));
mbed_official 155:8435094ec241 1154 /* Clear the old SQx bits for the selected rank */
mbed_official 155:8435094ec241 1155 tmpreg1 &= ~tmpreg2;
mbed_official 155:8435094ec241 1156 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1157 tmpreg2 = (uint32_t)(ADC_Channel) << (6 * (Rank));
mbed_official 155:8435094ec241 1158 /* Set the SQx bits for the selected rank */
mbed_official 155:8435094ec241 1159 tmpreg1 |= tmpreg2;
mbed_official 155:8435094ec241 1160 /* Store the new register value */
mbed_official 155:8435094ec241 1161 ADCx->SQR1 = tmpreg1;
mbed_official 155:8435094ec241 1162 }
mbed_official 155:8435094ec241 1163 /* For Rank 5 to 9 */
mbed_official 155:8435094ec241 1164 else if (Rank < 10)
mbed_official 155:8435094ec241 1165 {
mbed_official 155:8435094ec241 1166 /* Get the old register value */
mbed_official 155:8435094ec241 1167 tmpreg1 = ADCx->SQR2;
mbed_official 155:8435094ec241 1168 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1169 tmpreg2 = ADC_SQR2_SQ5 << (6 * (Rank - 5));
mbed_official 155:8435094ec241 1170 /* Clear the old SQx bits for the selected rank */
mbed_official 155:8435094ec241 1171 tmpreg1 &= ~tmpreg2;
mbed_official 155:8435094ec241 1172 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1173 tmpreg2 = (uint32_t)(ADC_Channel) << (6 * (Rank - 5));
mbed_official 155:8435094ec241 1174 /* Set the SQx bits for the selected rank */
mbed_official 155:8435094ec241 1175 tmpreg1 |= tmpreg2;
mbed_official 155:8435094ec241 1176 /* Store the new register value */
mbed_official 155:8435094ec241 1177 ADCx->SQR2 = tmpreg1;
mbed_official 155:8435094ec241 1178 }
mbed_official 155:8435094ec241 1179 /* For Rank 10 to 14 */
mbed_official 155:8435094ec241 1180 else if (Rank < 15)
mbed_official 155:8435094ec241 1181 {
mbed_official 155:8435094ec241 1182 /* Get the old register value */
mbed_official 155:8435094ec241 1183 tmpreg1 = ADCx->SQR3;
mbed_official 155:8435094ec241 1184 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1185 tmpreg2 = ADC_SQR3_SQ10 << (6 * (Rank - 10));
mbed_official 155:8435094ec241 1186 /* Clear the old SQx bits for the selected rank */
mbed_official 155:8435094ec241 1187 tmpreg1 &= ~tmpreg2;
mbed_official 155:8435094ec241 1188 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1189 tmpreg2 = (uint32_t)(ADC_Channel) << (6 * (Rank - 10));
mbed_official 155:8435094ec241 1190 /* Set the SQx bits for the selected rank */
mbed_official 155:8435094ec241 1191 tmpreg1 |= tmpreg2;
mbed_official 155:8435094ec241 1192 /* Store the new register value */
mbed_official 155:8435094ec241 1193 ADCx->SQR3 = tmpreg1;
mbed_official 155:8435094ec241 1194 }
mbed_official 155:8435094ec241 1195 else
mbed_official 155:8435094ec241 1196 {
mbed_official 155:8435094ec241 1197 /* Get the old register value */
mbed_official 155:8435094ec241 1198 tmpreg1 = ADCx->SQR4;
mbed_official 155:8435094ec241 1199 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1200 tmpreg2 = ADC_SQR3_SQ15 << (6 * (Rank - 15));
mbed_official 155:8435094ec241 1201 /* Clear the old SQx bits for the selected rank */
mbed_official 155:8435094ec241 1202 tmpreg1 &= ~tmpreg2;
mbed_official 155:8435094ec241 1203 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1204 tmpreg2 = (uint32_t)(ADC_Channel) << (6 * (Rank - 15));
mbed_official 155:8435094ec241 1205 /* Set the SQx bits for the selected rank */
mbed_official 155:8435094ec241 1206 tmpreg1 |= tmpreg2;
mbed_official 155:8435094ec241 1207 /* Store the new register value */
mbed_official 155:8435094ec241 1208 ADCx->SQR4 = tmpreg1;
mbed_official 155:8435094ec241 1209 }
mbed_official 155:8435094ec241 1210
mbed_official 155:8435094ec241 1211 /* Channel sampling configuration */
mbed_official 155:8435094ec241 1212 /* if ADC_Channel_10 ... ADC_Channel_18 is selected */
mbed_official 155:8435094ec241 1213 if (ADC_Channel > ADC_Channel_9)
mbed_official 155:8435094ec241 1214 {
mbed_official 155:8435094ec241 1215 /* Get the old register value */
mbed_official 155:8435094ec241 1216 tmpreg1 = ADCx->SMPR2;
mbed_official 155:8435094ec241 1217 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1218 tmpreg2 = ADC_SMPR2_SMP10 << (3 * (ADC_Channel - 10));
mbed_official 155:8435094ec241 1219 /* Clear the old channel sample time */
mbed_official 155:8435094ec241 1220 ADCx->SMPR2 &= ~tmpreg2;
mbed_official 155:8435094ec241 1221 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1222 ADCx->SMPR2 |= (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
mbed_official 155:8435094ec241 1223
mbed_official 155:8435094ec241 1224 }
mbed_official 155:8435094ec241 1225 else /* ADC_Channel include in ADC_Channel_[0..9] */
mbed_official 155:8435094ec241 1226 {
mbed_official 155:8435094ec241 1227 /* Get the old register value */
mbed_official 155:8435094ec241 1228 tmpreg1 = ADCx->SMPR1;
mbed_official 155:8435094ec241 1229 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1230 tmpreg2 = ADC_SMPR1_SMP1 << (3 * (ADC_Channel - 1));
mbed_official 155:8435094ec241 1231 /* Clear the old channel sample time */
mbed_official 155:8435094ec241 1232 ADCx->SMPR1 &= ~tmpreg2;
mbed_official 155:8435094ec241 1233 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1234 ADCx->SMPR1 |= (uint32_t)ADC_SampleTime << (3 * (ADC_Channel));
mbed_official 155:8435094ec241 1235 }
mbed_official 155:8435094ec241 1236 }
mbed_official 155:8435094ec241 1237
mbed_official 155:8435094ec241 1238 /**
mbed_official 155:8435094ec241 1239 * @brief Sets the ADC regular channel sequence lenght.
mbed_official 155:8435094ec241 1240 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
mbed_official 155:8435094ec241 1241 * @param SequenceLength: The Regular sequence length. This parameter must be between 1 to 16.
mbed_official 155:8435094ec241 1242 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1243 * @retval None
mbed_official 155:8435094ec241 1244 */
mbed_official 155:8435094ec241 1245 void ADC_RegularChannelSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t SequencerLength)
mbed_official 155:8435094ec241 1246 {
mbed_official 155:8435094ec241 1247 /* Check the parameters */
mbed_official 155:8435094ec241 1248 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1249
mbed_official 155:8435094ec241 1250 /* Configure the ADC sequence lenght */
mbed_official 155:8435094ec241 1251 ADCx->SQR1 &= ~(uint32_t)ADC_SQR1_L;
mbed_official 155:8435094ec241 1252 ADCx->SQR1 |= (uint32_t)(SequencerLength - 1);
mbed_official 155:8435094ec241 1253 }
mbed_official 155:8435094ec241 1254
mbed_official 155:8435094ec241 1255 /**
mbed_official 155:8435094ec241 1256 * @brief External Trigger Enable and Polarity Selection for regular channels.
mbed_official 155:8435094ec241 1257 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1258 * @param ADC_ExternalTrigConvEvent: ADC external Trigger source.
mbed_official 155:8435094ec241 1259 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1260 * @arg ADC_ExternalTrigger_Event0: External trigger event 0
mbed_official 155:8435094ec241 1261 * @arg ADC_ExternalTrigger_Event1: External trigger event 1
mbed_official 155:8435094ec241 1262 * @arg ADC_ExternalTrigger_Event2: External trigger event 2
mbed_official 155:8435094ec241 1263 * @arg ADC_ExternalTrigger_Event3: External trigger event 3
mbed_official 155:8435094ec241 1264 * @arg ADC_ExternalTrigger_Event4: External trigger event 4
mbed_official 155:8435094ec241 1265 * @arg ADC_ExternalTrigger_Event5: External trigger event 5
mbed_official 155:8435094ec241 1266 * @arg ADC_ExternalTrigger_Event6: External trigger event 6
mbed_official 155:8435094ec241 1267 * @arg ADC_ExternalTrigger_Event7: External trigger event 7
mbed_official 155:8435094ec241 1268 * @arg ADC_ExternalTrigger_Event8: External trigger event 8
mbed_official 155:8435094ec241 1269 * @arg ADC_ExternalTrigger_Event9: External trigger event 9
mbed_official 155:8435094ec241 1270 * @arg ADC_ExternalTrigger_Event10: External trigger event 10
mbed_official 155:8435094ec241 1271 * @arg ADC_ExternalTrigger_Event11: External trigger event 11
mbed_official 155:8435094ec241 1272 * @arg ADC_ExternalTrigger_Event12: External trigger event 12
mbed_official 155:8435094ec241 1273 * @arg ADC_ExternalTrigger_Event13: External trigger event 13
mbed_official 155:8435094ec241 1274 * @arg ADC_ExternalTrigger_Event14: External trigger event 14
mbed_official 155:8435094ec241 1275 * @arg ADC_ExternalTrigger_Event15: External trigger event 15
mbed_official 155:8435094ec241 1276 * @param ADC_ExternalTrigEventEdge: ADC external Trigger Polarity.
mbed_official 155:8435094ec241 1277 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1278 * @arg ADC_ExternalTrigEventEdge_OFF: Hardware trigger detection disabled
mbed_official 155:8435094ec241 1279 * (conversions can be launched by software)
mbed_official 155:8435094ec241 1280 * @arg ADC_ExternalTrigEventEdge_RisingEdge: Hardware trigger detection on the rising edge
mbed_official 155:8435094ec241 1281 * @arg ADC_ExternalTrigEventEdge_FallingEdge: Hardware trigger detection on the falling edge
mbed_official 155:8435094ec241 1282 * @arg ADC_ExternalTrigEventEdge_BothEdge: Hardware trigger detection on both the rising and falling edges
mbed_official 155:8435094ec241 1283 * @retval None
mbed_official 155:8435094ec241 1284 */
mbed_official 155:8435094ec241 1285 void ADC_ExternalTriggerConfig(ADC_TypeDef* ADCx, uint16_t ADC_ExternalTrigConvEvent, uint16_t ADC_ExternalTrigEventEdge)
mbed_official 155:8435094ec241 1286 {
mbed_official 155:8435094ec241 1287 /* Check the parameters */
mbed_official 155:8435094ec241 1288 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1289 assert_param(IS_ADC_EXT_TRIG(ADC_ExternalTrigConvEvent));
mbed_official 155:8435094ec241 1290 assert_param(IS_EXTERNALTRIG_EDGE(ADC_ExternalTrigEventEdge));
mbed_official 155:8435094ec241 1291
mbed_official 155:8435094ec241 1292 /* Disable the selected ADC conversion on external event */
mbed_official 155:8435094ec241 1293 ADCx->CFGR &= ~(ADC_CFGR_EXTEN | ADC_CFGR_EXTSEL);
mbed_official 155:8435094ec241 1294 ADCx->CFGR |= (uint32_t)(ADC_ExternalTrigEventEdge | ADC_ExternalTrigConvEvent);
mbed_official 155:8435094ec241 1295 }
mbed_official 155:8435094ec241 1296
mbed_official 155:8435094ec241 1297 /**
mbed_official 155:8435094ec241 1298 * @brief Enables or disables the selected ADC start conversion .
mbed_official 155:8435094ec241 1299 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1300 * @retval None
mbed_official 155:8435094ec241 1301 */
mbed_official 155:8435094ec241 1302 void ADC_StartConversion(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1303 {
mbed_official 155:8435094ec241 1304 /* Check the parameters */
mbed_official 155:8435094ec241 1305 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1306
mbed_official 155:8435094ec241 1307 /* Set the ADSTART bit */
mbed_official 155:8435094ec241 1308 ADCx->CR |= ADC_CR_ADSTART;
mbed_official 155:8435094ec241 1309 }
mbed_official 155:8435094ec241 1310
mbed_official 155:8435094ec241 1311 /**
mbed_official 155:8435094ec241 1312 * @brief Gets the selected ADC start conversion Status.
mbed_official 155:8435094ec241 1313 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1314 * @retval The new state of ADC start conversion (SET or RESET).
mbed_official 155:8435094ec241 1315 */
mbed_official 155:8435094ec241 1316 FlagStatus ADC_GetStartConversionStatus(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1317 {
mbed_official 155:8435094ec241 1318 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 1319 /* Check the parameters */
mbed_official 155:8435094ec241 1320 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1321 /* Check the status of ADSTART bit */
mbed_official 155:8435094ec241 1322 if ((ADCx->CR & ADC_CR_ADSTART) != (uint32_t)RESET)
mbed_official 155:8435094ec241 1323 {
mbed_official 155:8435094ec241 1324 /* ADSTART bit is set */
mbed_official 155:8435094ec241 1325 bitstatus = SET;
mbed_official 155:8435094ec241 1326 }
mbed_official 155:8435094ec241 1327 else
mbed_official 155:8435094ec241 1328 {
mbed_official 155:8435094ec241 1329 /* ADSTART bit is reset */
mbed_official 155:8435094ec241 1330 bitstatus = RESET;
mbed_official 155:8435094ec241 1331 }
mbed_official 155:8435094ec241 1332 /* Return the ADSTART bit status */
mbed_official 155:8435094ec241 1333 return bitstatus;
mbed_official 155:8435094ec241 1334 }
mbed_official 155:8435094ec241 1335
mbed_official 155:8435094ec241 1336 /**
mbed_official 155:8435094ec241 1337 * @brief Stops the selected ADC ongoing conversion.
mbed_official 155:8435094ec241 1338 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1339 * @retval None
mbed_official 155:8435094ec241 1340 */
mbed_official 155:8435094ec241 1341 void ADC_StopConversion(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1342 {
mbed_official 155:8435094ec241 1343 /* Check the parameters */
mbed_official 155:8435094ec241 1344 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1345
mbed_official 155:8435094ec241 1346 /* Set the ADSTP bit */
mbed_official 155:8435094ec241 1347 ADCx->CR |= ADC_CR_ADSTP;
mbed_official 155:8435094ec241 1348 }
mbed_official 155:8435094ec241 1349
mbed_official 155:8435094ec241 1350
mbed_official 155:8435094ec241 1351 /**
mbed_official 155:8435094ec241 1352 * @brief Configures the discontinuous mode for the selected ADC regular
mbed_official 155:8435094ec241 1353 * group channel.
mbed_official 155:8435094ec241 1354 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1355 * @param Number: specifies the discontinuous mode regular channel
mbed_official 155:8435094ec241 1356 * count value. This number must be between 1 and 8.
mbed_official 155:8435094ec241 1357 * @retval None
mbed_official 155:8435094ec241 1358 */
mbed_official 155:8435094ec241 1359 void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number)
mbed_official 155:8435094ec241 1360 {
mbed_official 155:8435094ec241 1361 uint32_t tmpreg1 = 0;
mbed_official 155:8435094ec241 1362 uint32_t tmpreg2 = 0;
mbed_official 155:8435094ec241 1363 /* Check the parameters */
mbed_official 155:8435094ec241 1364 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1365 assert_param(IS_ADC_REGULAR_DISC_NUMBER(Number));
mbed_official 155:8435094ec241 1366 /* Get the old register value */
mbed_official 155:8435094ec241 1367 tmpreg1 = ADCx->CFGR;
mbed_official 155:8435094ec241 1368 /* Clear the old discontinuous mode channel count */
mbed_official 155:8435094ec241 1369 tmpreg1 &= ~(uint32_t)(ADC_CFGR_DISCNUM);
mbed_official 155:8435094ec241 1370 /* Set the discontinuous mode channel count */
mbed_official 155:8435094ec241 1371 tmpreg2 = Number - 1;
mbed_official 155:8435094ec241 1372 tmpreg1 |= tmpreg2 << 17;
mbed_official 155:8435094ec241 1373 /* Store the new register value */
mbed_official 155:8435094ec241 1374 ADCx->CFGR = tmpreg1;
mbed_official 155:8435094ec241 1375 }
mbed_official 155:8435094ec241 1376
mbed_official 155:8435094ec241 1377 /**
mbed_official 155:8435094ec241 1378 * @brief Enables or disables the discontinuous mode on regular group
mbed_official 155:8435094ec241 1379 * channel for the specified ADC
mbed_official 155:8435094ec241 1380 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1381 * @param NewState: new state of the selected ADC discontinuous mode
mbed_official 155:8435094ec241 1382 * on regular group channel.
mbed_official 155:8435094ec241 1383 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1384 * @retval None
mbed_official 155:8435094ec241 1385 */
mbed_official 155:8435094ec241 1386 void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1387 {
mbed_official 155:8435094ec241 1388 /* Check the parameters */
mbed_official 155:8435094ec241 1389 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1390 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1391 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1392 {
mbed_official 155:8435094ec241 1393 /* Enable the selected ADC regular discontinuous mode */
mbed_official 155:8435094ec241 1394 ADCx->CFGR |= ADC_CFGR_DISCEN;
mbed_official 155:8435094ec241 1395 }
mbed_official 155:8435094ec241 1396 else
mbed_official 155:8435094ec241 1397 {
mbed_official 155:8435094ec241 1398 /* Disable the selected ADC regular discontinuous mode */
mbed_official 155:8435094ec241 1399 ADCx->CFGR &= ~(uint32_t)(ADC_CFGR_DISCEN);
mbed_official 155:8435094ec241 1400 }
mbed_official 155:8435094ec241 1401 }
mbed_official 155:8435094ec241 1402
mbed_official 155:8435094ec241 1403 /**
mbed_official 155:8435094ec241 1404 * @brief Returns the last ADCx conversion result data for regular channel.
mbed_official 155:8435094ec241 1405 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1406 * @retval The Data conversion value.
mbed_official 155:8435094ec241 1407 */
mbed_official 155:8435094ec241 1408 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1409 {
mbed_official 155:8435094ec241 1410 /* Check the parameters */
mbed_official 155:8435094ec241 1411 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1412 /* Return the selected ADC conversion value */
mbed_official 155:8435094ec241 1413 return (uint16_t) ADCx->DR;
mbed_official 155:8435094ec241 1414 }
mbed_official 155:8435094ec241 1415
mbed_official 155:8435094ec241 1416 /**
mbed_official 155:8435094ec241 1417 * @brief Returns the last ADC1, ADC2, ADC3 and ADC4 regular conversions results
mbed_official 155:8435094ec241 1418 * data in the selected dual mode.
mbed_official 155:8435094ec241 1419 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1420 * @retval The Data conversion value.
mbed_official 155:8435094ec241 1421 * @note In dual mode, the value returned by this function is as following
mbed_official 155:8435094ec241 1422 * Data[15:0] : these bits contain the regular data of the Master ADC.
mbed_official 155:8435094ec241 1423 * Data[31:16]: these bits contain the regular data of the Slave ADC.
mbed_official 155:8435094ec241 1424 */
mbed_official 155:8435094ec241 1425 uint32_t ADC_GetDualModeConversionValue(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1426 {
mbed_official 155:8435094ec241 1427 uint32_t tmpreg1 = 0;
mbed_official 155:8435094ec241 1428
mbed_official 155:8435094ec241 1429 /* Check the parameters */
mbed_official 155:8435094ec241 1430 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1431
mbed_official 155:8435094ec241 1432 if((ADCx == ADC1) || (ADCx== ADC2))
mbed_official 155:8435094ec241 1433 {
mbed_official 155:8435094ec241 1434 /* Get the dual mode conversion value */
mbed_official 155:8435094ec241 1435 tmpreg1 = ADC1_2->CDR;
mbed_official 155:8435094ec241 1436 }
mbed_official 155:8435094ec241 1437 else
mbed_official 155:8435094ec241 1438 {
mbed_official 155:8435094ec241 1439 /* Get the dual mode conversion value */
mbed_official 155:8435094ec241 1440 tmpreg1 = ADC3_4->CDR;
mbed_official 155:8435094ec241 1441 }
mbed_official 155:8435094ec241 1442 /* Return the dual mode conversion value */
mbed_official 155:8435094ec241 1443 return (uint32_t) tmpreg1;
mbed_official 155:8435094ec241 1444 }
mbed_official 155:8435094ec241 1445
mbed_official 155:8435094ec241 1446 /**
mbed_official 155:8435094ec241 1447 * @brief Set the ADC channels conversion value offset1
mbed_official 155:8435094ec241 1448 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1449 * @param ADC_Channel: the ADC channel to configure.
mbed_official 155:8435094ec241 1450 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1451 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 1452 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 1453 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 1454 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 1455 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 1456 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 1457 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 1458 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 1459 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 1460 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 1461 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 1462 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 1463 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 1464 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 1465 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 1466 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 1467 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 1468 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 1469 * @param Offset: the offset value for the selected ADC Channel
mbed_official 155:8435094ec241 1470 * This parameter must be a 12bit value.
mbed_official 155:8435094ec241 1471 * @retval None
mbed_official 155:8435094ec241 1472 */
mbed_official 155:8435094ec241 1473 void ADC_SetChannelOffset1(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint16_t Offset)
mbed_official 155:8435094ec241 1474 {
mbed_official 155:8435094ec241 1475 /* Check the parameters */
mbed_official 155:8435094ec241 1476 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1477 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 1478 assert_param(IS_ADC_OFFSET(Offset));
mbed_official 155:8435094ec241 1479
mbed_official 155:8435094ec241 1480 /* Select the Channel */
mbed_official 155:8435094ec241 1481 ADCx->OFR1 &= ~ (uint32_t) ADC_OFR1_OFFSET1_CH;
mbed_official 155:8435094ec241 1482 ADCx->OFR1 |= (uint32_t)((uint32_t)ADC_Channel << 26);
mbed_official 155:8435094ec241 1483
mbed_official 155:8435094ec241 1484 /* Set the data offset */
mbed_official 155:8435094ec241 1485 ADCx->OFR1 &= ~ (uint32_t) ADC_OFR1_OFFSET1;
mbed_official 155:8435094ec241 1486 ADCx->OFR1 |= (uint32_t)Offset;
mbed_official 155:8435094ec241 1487 }
mbed_official 155:8435094ec241 1488
mbed_official 155:8435094ec241 1489 /**
mbed_official 155:8435094ec241 1490 * @brief Set the ADC channels conversion value offset2
mbed_official 155:8435094ec241 1491 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1492 * @param ADC_Channel: the ADC channel to configure.
mbed_official 155:8435094ec241 1493 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1494 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 1495 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 1496 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 1497 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 1498 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 1499 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 1500 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 1501 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 1502 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 1503 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 1504 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 1505 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 1506 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 1507 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 1508 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 1509 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 1510 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 1511 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 1512 * @param Offset: the offset value for the selected ADC Channel
mbed_official 155:8435094ec241 1513 * This parameter must be a 12bit value.
mbed_official 155:8435094ec241 1514 * @retval None
mbed_official 155:8435094ec241 1515 */
mbed_official 155:8435094ec241 1516 void ADC_SetChannelOffset2(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint16_t Offset)
mbed_official 155:8435094ec241 1517 {
mbed_official 155:8435094ec241 1518 /* Check the parameters */
mbed_official 155:8435094ec241 1519 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1520 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 1521 assert_param(IS_ADC_OFFSET(Offset));
mbed_official 155:8435094ec241 1522
mbed_official 155:8435094ec241 1523 /* Select the Channel */
mbed_official 155:8435094ec241 1524 ADCx->OFR2 &= ~ (uint32_t) ADC_OFR2_OFFSET2_CH;
mbed_official 155:8435094ec241 1525 ADCx->OFR2 |= (uint32_t)((uint32_t)ADC_Channel << 26);
mbed_official 155:8435094ec241 1526
mbed_official 155:8435094ec241 1527 /* Set the data offset */
mbed_official 155:8435094ec241 1528 ADCx->OFR2 &= ~ (uint32_t) ADC_OFR2_OFFSET2;
mbed_official 155:8435094ec241 1529 ADCx->OFR2 |= (uint32_t)Offset;
mbed_official 155:8435094ec241 1530 }
mbed_official 155:8435094ec241 1531
mbed_official 155:8435094ec241 1532 /**
mbed_official 155:8435094ec241 1533 * @brief Set the ADC channels conversion value offset3
mbed_official 155:8435094ec241 1534 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1535 * @param ADC_Channel: the ADC channel to configure.
mbed_official 155:8435094ec241 1536 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1537 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 1538 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 1539 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 1540 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 1541 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 1542 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 1543 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 1544 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 1545 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 1546 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 1547 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 1548 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 1549 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 1550 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 1551 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 1552 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 1553 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 1554 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 1555 * @param Offset: the offset value for the selected ADC Channel
mbed_official 155:8435094ec241 1556 * This parameter must be a 12bit value.
mbed_official 155:8435094ec241 1557 * @retval None
mbed_official 155:8435094ec241 1558 */
mbed_official 155:8435094ec241 1559 void ADC_SetChannelOffset3(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint16_t Offset)
mbed_official 155:8435094ec241 1560 {
mbed_official 155:8435094ec241 1561 /* Check the parameters */
mbed_official 155:8435094ec241 1562 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1563 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 1564 assert_param(IS_ADC_OFFSET(Offset));
mbed_official 155:8435094ec241 1565
mbed_official 155:8435094ec241 1566 /* Select the Channel */
mbed_official 155:8435094ec241 1567 ADCx->OFR3 &= ~ (uint32_t) ADC_OFR3_OFFSET3_CH;
mbed_official 155:8435094ec241 1568 ADCx->OFR3 |= (uint32_t)((uint32_t)ADC_Channel << 26);
mbed_official 155:8435094ec241 1569
mbed_official 155:8435094ec241 1570 /* Set the data offset */
mbed_official 155:8435094ec241 1571 ADCx->OFR3 &= ~ (uint32_t) ADC_OFR3_OFFSET3;
mbed_official 155:8435094ec241 1572 ADCx->OFR3 |= (uint32_t)Offset;
mbed_official 155:8435094ec241 1573 }
mbed_official 155:8435094ec241 1574
mbed_official 155:8435094ec241 1575 /**
mbed_official 155:8435094ec241 1576 * @brief Set the ADC channels conversion value offset4
mbed_official 155:8435094ec241 1577 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1578 * @param ADC_Channel: the ADC channel to configure.
mbed_official 155:8435094ec241 1579 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1580 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 1581 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 1582 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 1583 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 1584 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 1585 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 1586 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 1587 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 1588 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 1589 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 1590 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 1591 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 1592 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 1593 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 1594 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 1595 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 1596 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 1597 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 1598 * @param Offset: the offset value for the selected ADC Channel
mbed_official 155:8435094ec241 1599 * This parameter must be a 12bit value.
mbed_official 155:8435094ec241 1600 * @retval None
mbed_official 155:8435094ec241 1601 */
mbed_official 155:8435094ec241 1602 void ADC_SetChannelOffset4(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint16_t Offset)
mbed_official 155:8435094ec241 1603 {
mbed_official 155:8435094ec241 1604 /* Check the parameters */
mbed_official 155:8435094ec241 1605 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1606 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 155:8435094ec241 1607 assert_param(IS_ADC_OFFSET(Offset));
mbed_official 155:8435094ec241 1608
mbed_official 155:8435094ec241 1609 /* Select the Channel */
mbed_official 155:8435094ec241 1610 ADCx->OFR4 &= ~ (uint32_t) ADC_OFR4_OFFSET4_CH;
mbed_official 155:8435094ec241 1611 ADCx->OFR4 |= (uint32_t)((uint32_t)ADC_Channel << 26);
mbed_official 155:8435094ec241 1612
mbed_official 155:8435094ec241 1613 /* Set the data offset */
mbed_official 155:8435094ec241 1614 ADCx->OFR4 &= ~ (uint32_t) ADC_OFR4_OFFSET4;
mbed_official 155:8435094ec241 1615 ADCx->OFR4 |= (uint32_t)Offset;
mbed_official 155:8435094ec241 1616 }
mbed_official 155:8435094ec241 1617
mbed_official 155:8435094ec241 1618 /**
mbed_official 155:8435094ec241 1619 * @brief Enables or disables the Offset1.
mbed_official 155:8435094ec241 1620 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1621 * @param NewState: new state of the ADCx offset1.
mbed_official 155:8435094ec241 1622 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1623 * @retval None
mbed_official 155:8435094ec241 1624 */
mbed_official 155:8435094ec241 1625 void ADC_ChannelOffset1Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1626 {
mbed_official 155:8435094ec241 1627 /* Check the parameters */
mbed_official 155:8435094ec241 1628 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1629 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1630
mbed_official 155:8435094ec241 1631 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1632 {
mbed_official 155:8435094ec241 1633 /* Set the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1634 ADCx->OFR1 |= ADC_OFR1_OFFSET1_EN;
mbed_official 155:8435094ec241 1635 }
mbed_official 155:8435094ec241 1636 else
mbed_official 155:8435094ec241 1637 {
mbed_official 155:8435094ec241 1638 /* Reset the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1639 ADCx->OFR1 &= ~(ADC_OFR1_OFFSET1_EN);
mbed_official 155:8435094ec241 1640 }
mbed_official 155:8435094ec241 1641 }
mbed_official 155:8435094ec241 1642
mbed_official 155:8435094ec241 1643 /**
mbed_official 155:8435094ec241 1644 * @brief Enables or disables the Offset2.
mbed_official 155:8435094ec241 1645 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1646 * @param NewState: new state of the ADCx offset2.
mbed_official 155:8435094ec241 1647 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1648 * @retval None
mbed_official 155:8435094ec241 1649 */
mbed_official 155:8435094ec241 1650 void ADC_ChannelOffset2Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1651 {
mbed_official 155:8435094ec241 1652 /* Check the parameters */
mbed_official 155:8435094ec241 1653 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1654 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1655
mbed_official 155:8435094ec241 1656 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1657 {
mbed_official 155:8435094ec241 1658 /* Set the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1659 ADCx->OFR2 |= ADC_OFR2_OFFSET2_EN;
mbed_official 155:8435094ec241 1660 }
mbed_official 155:8435094ec241 1661 else
mbed_official 155:8435094ec241 1662 {
mbed_official 155:8435094ec241 1663 /* Reset the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1664 ADCx->OFR2 &= ~(ADC_OFR2_OFFSET2_EN);
mbed_official 155:8435094ec241 1665 }
mbed_official 155:8435094ec241 1666 }
mbed_official 155:8435094ec241 1667
mbed_official 155:8435094ec241 1668 /**
mbed_official 155:8435094ec241 1669 * @brief Enables or disables the Offset3.
mbed_official 155:8435094ec241 1670 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1671 * @param NewState: new state of the ADCx offset3.
mbed_official 155:8435094ec241 1672 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1673 * @retval None
mbed_official 155:8435094ec241 1674 */
mbed_official 155:8435094ec241 1675 void ADC_ChannelOffset3Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1676 {
mbed_official 155:8435094ec241 1677 /* Check the parameters */
mbed_official 155:8435094ec241 1678 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1679 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1680
mbed_official 155:8435094ec241 1681 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1682 {
mbed_official 155:8435094ec241 1683 /* Set the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1684 ADCx->OFR3 |= ADC_OFR3_OFFSET3_EN;
mbed_official 155:8435094ec241 1685 }
mbed_official 155:8435094ec241 1686 else
mbed_official 155:8435094ec241 1687 {
mbed_official 155:8435094ec241 1688 /* Reset the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1689 ADCx->OFR3 &= ~(ADC_OFR3_OFFSET3_EN);
mbed_official 155:8435094ec241 1690 }
mbed_official 155:8435094ec241 1691 }
mbed_official 155:8435094ec241 1692
mbed_official 155:8435094ec241 1693 /**
mbed_official 155:8435094ec241 1694 * @brief Enables or disables the Offset4.
mbed_official 155:8435094ec241 1695 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1696 * @param NewState: new state of the ADCx offset4.
mbed_official 155:8435094ec241 1697 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1698 * @retval None
mbed_official 155:8435094ec241 1699 */
mbed_official 155:8435094ec241 1700 void ADC_ChannelOffset4Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1701 {
mbed_official 155:8435094ec241 1702 /* Check the parameters */
mbed_official 155:8435094ec241 1703 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1704 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1705
mbed_official 155:8435094ec241 1706 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1707 {
mbed_official 155:8435094ec241 1708 /* Set the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1709 ADCx->OFR4 |= ADC_OFR4_OFFSET4_EN;
mbed_official 155:8435094ec241 1710 }
mbed_official 155:8435094ec241 1711 else
mbed_official 155:8435094ec241 1712 {
mbed_official 155:8435094ec241 1713 /* Reset the OFFSET1_EN bit */
mbed_official 155:8435094ec241 1714 ADCx->OFR4 &= ~(ADC_OFR4_OFFSET4_EN);
mbed_official 155:8435094ec241 1715 }
mbed_official 155:8435094ec241 1716 }
mbed_official 155:8435094ec241 1717
mbed_official 155:8435094ec241 1718 /**
mbed_official 155:8435094ec241 1719 * @}
mbed_official 155:8435094ec241 1720 */
mbed_official 155:8435094ec241 1721
mbed_official 155:8435094ec241 1722 /** @defgroup ADC_Group5 Regular Channels DMA Configuration functions
mbed_official 155:8435094ec241 1723 * @brief Regular Channels DMA Configuration functions
mbed_official 155:8435094ec241 1724 *
mbed_official 155:8435094ec241 1725 @verbatim
mbed_official 155:8435094ec241 1726 ===============================================================================
mbed_official 155:8435094ec241 1727 ##### Regular Channels DMA Configuration functions #####
mbed_official 155:8435094ec241 1728 ===============================================================================
mbed_official 155:8435094ec241 1729
mbed_official 155:8435094ec241 1730 [..] This section provides functions allowing to configure the DMA for ADC regular
mbed_official 155:8435094ec241 1731 channels. Since converted regular channel values are stored into a unique data register,
mbed_official 155:8435094ec241 1732 it is useful to use DMA for conversion of more than one regular channel. This
mbed_official 155:8435094ec241 1733 avoids the loss of the data already stored in the ADC Data register.
mbed_official 155:8435094ec241 1734
mbed_official 155:8435094ec241 1735 (#) ADC_DMACmd() function is used to enable the ADC DMA mode, after each
mbed_official 155:8435094ec241 1736 conversion of a regular channel, a DMA request is generated.
mbed_official 155:8435094ec241 1737 (#) ADC_DMAConfig() function is used to select between the one shot DMA mode
mbed_official 155:8435094ec241 1738 or the circular DMA mode
mbed_official 155:8435094ec241 1739
mbed_official 155:8435094ec241 1740 @endverbatim
mbed_official 155:8435094ec241 1741 * @{
mbed_official 155:8435094ec241 1742 */
mbed_official 155:8435094ec241 1743
mbed_official 155:8435094ec241 1744 /**
mbed_official 155:8435094ec241 1745 * @brief Enables or disables the specified ADC DMA request.
mbed_official 155:8435094ec241 1746 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1747 * @param NewState: new state of the selected ADC DMA transfer.
mbed_official 155:8435094ec241 1748 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1749 * @retval None
mbed_official 155:8435094ec241 1750 */
mbed_official 155:8435094ec241 1751 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1752 {
mbed_official 155:8435094ec241 1753 /* Check the parameters */
mbed_official 155:8435094ec241 1754 assert_param(IS_ADC_DMA_PERIPH(ADCx));
mbed_official 155:8435094ec241 1755 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1756 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1757 {
mbed_official 155:8435094ec241 1758 /* Enable the selected ADC DMA request */
mbed_official 155:8435094ec241 1759 ADCx->CFGR |= ADC_CFGR_DMAEN;
mbed_official 155:8435094ec241 1760 }
mbed_official 155:8435094ec241 1761 else
mbed_official 155:8435094ec241 1762 {
mbed_official 155:8435094ec241 1763 /* Disable the selected ADC DMA request */
mbed_official 155:8435094ec241 1764 ADCx->CFGR &= ~(uint32_t)ADC_CFGR_DMAEN;
mbed_official 155:8435094ec241 1765 }
mbed_official 155:8435094ec241 1766 }
mbed_official 155:8435094ec241 1767
mbed_official 155:8435094ec241 1768 /**
mbed_official 155:8435094ec241 1769 * @brief Configure ADC DMA mode.
mbed_official 155:8435094ec241 1770 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1771 * @param ADC_DMAMode: select the ADC DMA mode.
mbed_official 155:8435094ec241 1772 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1773 * @arg ADC_DMAMode_OneShot: ADC DMA Oneshot mode
mbed_official 155:8435094ec241 1774 * @arg ADC_DMAMode_Circular: ADC DMA circular mode
mbed_official 155:8435094ec241 1775 * @retval None
mbed_official 155:8435094ec241 1776 */
mbed_official 155:8435094ec241 1777 void ADC_DMAConfig(ADC_TypeDef* ADCx, uint32_t ADC_DMAMode)
mbed_official 155:8435094ec241 1778 {
mbed_official 155:8435094ec241 1779 /* Check the parameters */
mbed_official 155:8435094ec241 1780 assert_param(IS_ADC_DMA_PERIPH(ADCx));
mbed_official 155:8435094ec241 1781 assert_param(IS_ADC_DMA_MODE(ADC_DMAMode));
mbed_official 155:8435094ec241 1782
mbed_official 155:8435094ec241 1783 /* Set or reset the DMACFG bit */
mbed_official 155:8435094ec241 1784 ADCx->CFGR &= ~(uint32_t)ADC_CFGR_DMACFG;
mbed_official 155:8435094ec241 1785 ADCx->CFGR |= ADC_DMAMode;
mbed_official 155:8435094ec241 1786 }
mbed_official 155:8435094ec241 1787
mbed_official 155:8435094ec241 1788 /**
mbed_official 155:8435094ec241 1789 * @}
mbed_official 155:8435094ec241 1790 */
mbed_official 155:8435094ec241 1791
mbed_official 155:8435094ec241 1792 /** @defgroup ADC_Group6 Injected channels Configuration functions
mbed_official 155:8435094ec241 1793 * @brief Injected channels Configuration functions
mbed_official 155:8435094ec241 1794 *
mbed_official 155:8435094ec241 1795 @verbatim
mbed_official 155:8435094ec241 1796 ===============================================================================
mbed_official 155:8435094ec241 1797 ##### Injected channels Configuration functions #####
mbed_official 155:8435094ec241 1798 ===============================================================================
mbed_official 155:8435094ec241 1799
mbed_official 155:8435094ec241 1800 [..] This section provide functions allowing to manage the ADC Injected channels,
mbed_official 155:8435094ec241 1801 it is composed of :
mbed_official 155:8435094ec241 1802
mbed_official 155:8435094ec241 1803 (#) Configuration functions for Injected channels sample time
mbed_official 155:8435094ec241 1804 (#) Functions to start and stop the injected conversion
mbed_official 155:8435094ec241 1805 (#) unction to select the discontinuous mode
mbed_official 155:8435094ec241 1806 (#) Function to get the Specified Injected channel conversion data: This subsection
mbed_official 155:8435094ec241 1807 provides an important function in the ADC peripheral since it returns the
mbed_official 155:8435094ec241 1808 converted data of the specific injected channel.
mbed_official 155:8435094ec241 1809
mbed_official 155:8435094ec241 1810 @endverbatim
mbed_official 155:8435094ec241 1811 * @{
mbed_official 155:8435094ec241 1812 */
mbed_official 155:8435094ec241 1813
mbed_official 155:8435094ec241 1814 /**
mbed_official 155:8435094ec241 1815 * @brief Configures for the selected ADC injected channel its corresponding
mbed_official 155:8435094ec241 1816 * sample time.
mbed_official 155:8435094ec241 1817 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1818 * @param ADC_Channel: the ADC channel to configure.
mbed_official 155:8435094ec241 1819 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1820 * @arg ADC_InjectedChannel_1: ADC Channel1 selected
mbed_official 155:8435094ec241 1821 * @arg ADC_InjectedChannel_2: ADC Channel2 selected
mbed_official 155:8435094ec241 1822 * @arg ADC_InjectedChannel_3: ADC Channel3 selected
mbed_official 155:8435094ec241 1823 * @arg ADC_InjectedChannel_4: ADC Channel4 selected
mbed_official 155:8435094ec241 1824 * @arg ADC_InjectedChannel_5: ADC Channel5 selected
mbed_official 155:8435094ec241 1825 * @arg ADC_InjectedChannel_6: ADC Channel6 selected
mbed_official 155:8435094ec241 1826 * @arg ADC_InjectedChannel_7: ADC Channel7 selected
mbed_official 155:8435094ec241 1827 * @arg ADC_InjectedChannel_8: ADC Channel8 selected
mbed_official 155:8435094ec241 1828 * @arg ADC_InjectedChannel_9: ADC Channel9 selected
mbed_official 155:8435094ec241 1829 * @arg ADC_InjectedChannel_10: ADC Channel10 selected
mbed_official 155:8435094ec241 1830 * @arg ADC_InjectedChannel_11: ADC Channel11 selected
mbed_official 155:8435094ec241 1831 * @arg ADC_InjectedChannel_12: ADC Channel12 selected
mbed_official 155:8435094ec241 1832 * @arg ADC_InjectedChannel_13: ADC Channel13 selected
mbed_official 155:8435094ec241 1833 * @arg ADC_InjectedChannel_14: ADC Channel14 selected
mbed_official 155:8435094ec241 1834 * @arg ADC_InjectedChannel_15: ADC Channel15 selected
mbed_official 155:8435094ec241 1835 * @arg ADC_InjectedChannel_16: ADC Channel16 selected
mbed_official 155:8435094ec241 1836 * @arg ADC_InjectedChannel_17: ADC Channel17 selected
mbed_official 155:8435094ec241 1837 * @arg ADC_InjectedChannel_18: ADC Channel18 selected
mbed_official 155:8435094ec241 1838 * @param ADC_SampleTime: The sample time value to be set for the selected channel.
mbed_official 155:8435094ec241 1839 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1840 * @arg ADC_SampleTime_1Cycles5: Sample time equal to 1.5 cycles
mbed_official 155:8435094ec241 1841 * @arg ADC_SampleTime_2Cycles5: Sample time equal to 2.5 cycles
mbed_official 155:8435094ec241 1842 * @arg ADC_SampleTime_4Cycles5: Sample time equal to 4.5 cycles
mbed_official 155:8435094ec241 1843 * @arg ADC_SampleTime_7Cycles5: Sample time equal to 7.5 cycles
mbed_official 155:8435094ec241 1844 * @arg ADC_SampleTime_19Cycles5: Sample time equal to 19.5 cycles
mbed_official 155:8435094ec241 1845 * @arg ADC_SampleTime_61Cycles5: Sample time equal to 61.5 cycles
mbed_official 155:8435094ec241 1846 * @arg ADC_SampleTime_181Cycles5: Sample time equal to 181.5 cycles
mbed_official 155:8435094ec241 1847 * @arg ADC_SampleTime_601Cycles5: Sample time equal to 601.5 cycles
mbed_official 155:8435094ec241 1848 * @retval None
mbed_official 155:8435094ec241 1849 */
mbed_official 155:8435094ec241 1850 void ADC_InjectedChannelSampleTimeConfig(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint8_t ADC_SampleTime)
mbed_official 155:8435094ec241 1851 {
mbed_official 155:8435094ec241 1852 uint32_t tmpreg1 = 0;
mbed_official 155:8435094ec241 1853 /* Check the parameters */
mbed_official 155:8435094ec241 1854 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1855 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
mbed_official 155:8435094ec241 1856 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
mbed_official 155:8435094ec241 1857
mbed_official 155:8435094ec241 1858 /* Channel sampling configuration */
mbed_official 155:8435094ec241 1859 /* if ADC_InjectedChannel_10 ... ADC_InjectedChannel_18 is selected */
mbed_official 155:8435094ec241 1860 if (ADC_InjectedChannel > ADC_InjectedChannel_9)
mbed_official 155:8435094ec241 1861 {
mbed_official 155:8435094ec241 1862 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1863 tmpreg1 = ADC_SMPR2_SMP10 << (3 * (ADC_InjectedChannel - 10));
mbed_official 155:8435094ec241 1864 /* Clear the old channel sample time */
mbed_official 155:8435094ec241 1865 ADCx->SMPR2 &= ~tmpreg1;
mbed_official 155:8435094ec241 1866 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1867 ADCx->SMPR2 |= (uint32_t)ADC_SampleTime << (3 * (ADC_InjectedChannel - 10));
mbed_official 155:8435094ec241 1868
mbed_official 155:8435094ec241 1869 }
mbed_official 155:8435094ec241 1870 else /* ADC_InjectedChannel include in ADC_InjectedChannel_[0..9] */
mbed_official 155:8435094ec241 1871 {
mbed_official 155:8435094ec241 1872 /* Calculate the mask to clear */
mbed_official 155:8435094ec241 1873 tmpreg1 = ADC_SMPR1_SMP1 << (3 * (ADC_InjectedChannel - 1));
mbed_official 155:8435094ec241 1874 /* Clear the old channel sample time */
mbed_official 155:8435094ec241 1875 ADCx->SMPR1 &= ~tmpreg1;
mbed_official 155:8435094ec241 1876 /* Calculate the mask to set */
mbed_official 155:8435094ec241 1877 ADCx->SMPR1 |= (uint32_t)ADC_SampleTime << (3 * (ADC_InjectedChannel));
mbed_official 155:8435094ec241 1878 }
mbed_official 155:8435094ec241 1879 }
mbed_official 155:8435094ec241 1880
mbed_official 155:8435094ec241 1881 /**
mbed_official 155:8435094ec241 1882 * @brief Enables or disables the selected ADC start of the injected
mbed_official 155:8435094ec241 1883 * channels conversion.
mbed_official 155:8435094ec241 1884 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1885 * @param NewState: new state of the selected ADC software start injected conversion.
mbed_official 155:8435094ec241 1886 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1887 * @retval None
mbed_official 155:8435094ec241 1888 */
mbed_official 155:8435094ec241 1889 void ADC_StartInjectedConversion(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1890 {
mbed_official 155:8435094ec241 1891 /* Check the parameters */
mbed_official 155:8435094ec241 1892 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1893
mbed_official 155:8435094ec241 1894 /* Enable the selected ADC conversion for injected group on external event and start the selected
mbed_official 155:8435094ec241 1895 ADC injected conversion */
mbed_official 155:8435094ec241 1896 ADCx->CR |= ADC_CR_JADSTART;
mbed_official 155:8435094ec241 1897 }
mbed_official 155:8435094ec241 1898
mbed_official 155:8435094ec241 1899 /**
mbed_official 155:8435094ec241 1900 * @brief Stops the selected ADC ongoing injected conversion.
mbed_official 155:8435094ec241 1901 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1902 * @retval None
mbed_official 155:8435094ec241 1903 */
mbed_official 155:8435094ec241 1904 void ADC_StopInjectedConversion(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1905 {
mbed_official 155:8435094ec241 1906 /* Check the parameters */
mbed_official 155:8435094ec241 1907 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1908
mbed_official 155:8435094ec241 1909 /* Set the JADSTP bit */
mbed_official 155:8435094ec241 1910 ADCx->CR |= ADC_CR_JADSTP;
mbed_official 155:8435094ec241 1911 }
mbed_official 155:8435094ec241 1912
mbed_official 155:8435094ec241 1913 /**
mbed_official 155:8435094ec241 1914 * @brief Gets the selected ADC Software start injected conversion Status.
mbed_official 155:8435094ec241 1915 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1916 * @retval The new state of ADC start injected conversion (SET or RESET).
mbed_official 155:8435094ec241 1917 */
mbed_official 155:8435094ec241 1918 FlagStatus ADC_GetStartInjectedConversionStatus(ADC_TypeDef* ADCx)
mbed_official 155:8435094ec241 1919 {
mbed_official 155:8435094ec241 1920 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 1921 /* Check the parameters */
mbed_official 155:8435094ec241 1922 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1923
mbed_official 155:8435094ec241 1924 /* Check the status of JADSTART bit */
mbed_official 155:8435094ec241 1925 if ((ADCx->CR & ADC_CR_JADSTART) != (uint32_t)RESET)
mbed_official 155:8435094ec241 1926 {
mbed_official 155:8435094ec241 1927 /* JADSTART bit is set */
mbed_official 155:8435094ec241 1928 bitstatus = SET;
mbed_official 155:8435094ec241 1929 }
mbed_official 155:8435094ec241 1930 else
mbed_official 155:8435094ec241 1931 {
mbed_official 155:8435094ec241 1932 /* JADSTART bit is reset */
mbed_official 155:8435094ec241 1933 bitstatus = RESET;
mbed_official 155:8435094ec241 1934 }
mbed_official 155:8435094ec241 1935 /* Return the JADSTART bit status */
mbed_official 155:8435094ec241 1936 return bitstatus;
mbed_official 155:8435094ec241 1937 }
mbed_official 155:8435094ec241 1938
mbed_official 155:8435094ec241 1939 /**
mbed_official 155:8435094ec241 1940 * @brief Enables or disables the selected ADC automatic injected group
mbed_official 155:8435094ec241 1941 * conversion after regular one.
mbed_official 155:8435094ec241 1942 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1943 * @param NewState: new state of the selected ADC auto injected conversion
mbed_official 155:8435094ec241 1944 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1945 * @retval None
mbed_official 155:8435094ec241 1946 */
mbed_official 155:8435094ec241 1947 void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1948 {
mbed_official 155:8435094ec241 1949 /* Check the parameters */
mbed_official 155:8435094ec241 1950 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1951 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1952 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1953 {
mbed_official 155:8435094ec241 1954 /* Enable the selected ADC automatic injected group conversion */
mbed_official 155:8435094ec241 1955 ADCx->CFGR |= ADC_CFGR_JAUTO;
mbed_official 155:8435094ec241 1956 }
mbed_official 155:8435094ec241 1957 else
mbed_official 155:8435094ec241 1958 {
mbed_official 155:8435094ec241 1959 /* Disable the selected ADC automatic injected group conversion */
mbed_official 155:8435094ec241 1960 ADCx->CFGR &= ~ADC_CFGR_JAUTO;
mbed_official 155:8435094ec241 1961 }
mbed_official 155:8435094ec241 1962 }
mbed_official 155:8435094ec241 1963
mbed_official 155:8435094ec241 1964 /**
mbed_official 155:8435094ec241 1965 * @brief Enables or disables the discontinuous mode for injected group
mbed_official 155:8435094ec241 1966 * channel for the specified ADC
mbed_official 155:8435094ec241 1967 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1968 * @param NewState: new state of the selected ADC discontinuous mode
mbed_official 155:8435094ec241 1969 * on injected group channel.
mbed_official 155:8435094ec241 1970 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 1971 * @retval None
mbed_official 155:8435094ec241 1972 */
mbed_official 155:8435094ec241 1973 void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 155:8435094ec241 1974 {
mbed_official 155:8435094ec241 1975 /* Check the parameters */
mbed_official 155:8435094ec241 1976 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 1977 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 1978 if (NewState != DISABLE)
mbed_official 155:8435094ec241 1979 {
mbed_official 155:8435094ec241 1980 /* Enable the selected ADC injected discontinuous mode */
mbed_official 155:8435094ec241 1981 ADCx->CFGR |= ADC_CFGR_JDISCEN;
mbed_official 155:8435094ec241 1982 }
mbed_official 155:8435094ec241 1983 else
mbed_official 155:8435094ec241 1984 {
mbed_official 155:8435094ec241 1985 /* Disable the selected ADC injected discontinuous mode */
mbed_official 155:8435094ec241 1986 ADCx->CFGR &= ~ADC_CFGR_JDISCEN;
mbed_official 155:8435094ec241 1987 }
mbed_official 155:8435094ec241 1988 }
mbed_official 155:8435094ec241 1989
mbed_official 155:8435094ec241 1990 /**
mbed_official 155:8435094ec241 1991 * @brief Returns the ADC injected channel conversion result
mbed_official 155:8435094ec241 1992 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 1993 * @param ADC_InjectedSequence: the converted ADC injected sequence.
mbed_official 155:8435094ec241 1994 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 1995 * @arg ADC_InjectedSequence_1: Injected Sequence1 selected
mbed_official 155:8435094ec241 1996 * @arg ADC_InjectedSequence_2: Injected Sequence2 selected
mbed_official 155:8435094ec241 1997 * @arg ADC_InjectedSequence_3: Injected Sequence3 selected
mbed_official 155:8435094ec241 1998 * @arg ADC_InjectedSequence_4: Injected Sequence4 selected
mbed_official 155:8435094ec241 1999 * @retval The Data conversion value.
mbed_official 155:8435094ec241 2000 */
mbed_official 155:8435094ec241 2001 uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedSequence)
mbed_official 155:8435094ec241 2002 {
mbed_official 155:8435094ec241 2003 __IO uint32_t tmp = 0;
mbed_official 155:8435094ec241 2004
mbed_official 155:8435094ec241 2005 /* Check the parameters */
mbed_official 155:8435094ec241 2006 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2007 assert_param(IS_ADC_INJECTED_SEQUENCE(ADC_InjectedSequence));
mbed_official 155:8435094ec241 2008
mbed_official 155:8435094ec241 2009 tmp = (uint32_t)ADCx;
mbed_official 155:8435094ec241 2010 tmp += ((ADC_InjectedSequence - 1 )<< 2) + JDR_Offset;
mbed_official 155:8435094ec241 2011
mbed_official 155:8435094ec241 2012 /* Returns the selected injected channel conversion data value */
mbed_official 155:8435094ec241 2013 return (uint16_t) (*(__IO uint32_t*) tmp);
mbed_official 155:8435094ec241 2014 }
mbed_official 155:8435094ec241 2015
mbed_official 155:8435094ec241 2016 /**
mbed_official 155:8435094ec241 2017 * @}
mbed_official 155:8435094ec241 2018 */
mbed_official 155:8435094ec241 2019
mbed_official 155:8435094ec241 2020 /** @defgroup ADC_Group7 Interrupts and flags management functions
mbed_official 155:8435094ec241 2021 * @brief Interrupts and flags management functions
mbed_official 155:8435094ec241 2022 *
mbed_official 155:8435094ec241 2023 @verbatim
mbed_official 155:8435094ec241 2024 ===============================================================================
mbed_official 155:8435094ec241 2025 ##### Interrupts and flags management functions #####
mbed_official 155:8435094ec241 2026 ===============================================================================
mbed_official 155:8435094ec241 2027
mbed_official 155:8435094ec241 2028 [..] This section provides functions allowing to configure the ADC Interrupts, get
mbed_official 155:8435094ec241 2029 the status and clear flags and Interrupts pending bits.
mbed_official 155:8435094ec241 2030
mbed_official 155:8435094ec241 2031 [..] The ADC provide 11 Interrupts sources and 11 Flags which can be divided into 3 groups:
mbed_official 155:8435094ec241 2032
mbed_official 155:8435094ec241 2033 (#) Flags and Interrupts for ADC regular channels
mbed_official 155:8435094ec241 2034 (##)Flags
mbed_official 155:8435094ec241 2035 (+) ADC_FLAG_RDY: ADC Ready flag
mbed_official 155:8435094ec241 2036 (+) ADC_FLAG_EOSMP: ADC End of Sampling flag
mbed_official 155:8435094ec241 2037 (+) ADC_FLAG_EOC: ADC End of Regular Conversion flag.
mbed_official 155:8435094ec241 2038 (+) ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2039 (+) ADC_FLAG_OVR: ADC overrun flag
mbed_official 155:8435094ec241 2040
mbed_official 155:8435094ec241 2041 (##) Interrupts
mbed_official 155:8435094ec241 2042 (+) ADC_IT_RDY: ADC Ready interrupt source
mbed_official 155:8435094ec241 2043 (+) ADC_IT_EOSMP: ADC End of Sampling interrupt source
mbed_official 155:8435094ec241 2044 (+) ADC_IT_EOC: ADC End of Regular Conversion interrupt source
mbed_official 155:8435094ec241 2045 (+) ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt
mbed_official 155:8435094ec241 2046 (+) ADC_IT_OVR: ADC overrun interrupt source
mbed_official 155:8435094ec241 2047
mbed_official 155:8435094ec241 2048
mbed_official 155:8435094ec241 2049 (#) Flags and Interrupts for ADC regular channels
mbed_official 155:8435094ec241 2050 (##)Flags
mbed_official 155:8435094ec241 2051 (+) ADC_FLAG_JEOC: ADC Ready flag
mbed_official 155:8435094ec241 2052 (+) ADC_FLAG_JEOS: ADC End of Sampling flag
mbed_official 155:8435094ec241 2053 (+) ADC_FLAG_JQOVF: ADC End of Regular Conversion flag.
mbed_official 155:8435094ec241 2054
mbed_official 155:8435094ec241 2055 (##) Interrupts
mbed_official 155:8435094ec241 2056 (+) ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
mbed_official 155:8435094ec241 2057 (+) ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
mbed_official 155:8435094ec241 2058 (+) ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
mbed_official 155:8435094ec241 2059
mbed_official 155:8435094ec241 2060 (#) General Flags and Interrupts for the ADC
mbed_official 155:8435094ec241 2061 (##)Flags
mbed_official 155:8435094ec241 2062 (+) ADC_FLAG_AWD1: ADC Analog watchdog 1 flag
mbed_official 155:8435094ec241 2063 (+) ADC_FLAG_AWD2: ADC Analog watchdog 2 flag
mbed_official 155:8435094ec241 2064 (+) ADC_FLAG_AWD3: ADC Analog watchdog 3 flag
mbed_official 155:8435094ec241 2065
mbed_official 155:8435094ec241 2066 (##)Flags
mbed_official 155:8435094ec241 2067 (+) ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
mbed_official 155:8435094ec241 2068 (+) ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
mbed_official 155:8435094ec241 2069 (+) ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
mbed_official 155:8435094ec241 2070
mbed_official 155:8435094ec241 2071 (#) Flags for ADC dual mode
mbed_official 155:8435094ec241 2072 (##)Flags for Master
mbed_official 155:8435094ec241 2073 (+) ADC_FLAG_MSTRDY: ADC master Ready (ADRDY) flag
mbed_official 155:8435094ec241 2074 (+) ADC_FLAG_MSTEOSMP: ADC master End of Sampling flag
mbed_official 155:8435094ec241 2075 (+) ADC_FLAG_MSTEOC: ADC master End of Regular Conversion flag
mbed_official 155:8435094ec241 2076 (+) ADC_FLAG_MSTEOS: ADC master End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2077 (+) ADC_FLAG_MSTOVR: ADC master overrun flag
mbed_official 155:8435094ec241 2078 (+) ADC_FLAG_MSTJEOC: ADC master End of Injected Conversion flag
mbed_official 155:8435094ec241 2079 (+) ADC_FLAG_MSTJEOS: ADC master End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2080 (+) ADC_FLAG_MSTAWD1: ADC master Analog watchdog 1 flag
mbed_official 155:8435094ec241 2081 (+) ADC_FLAG_MSTAWD2: ADC master Analog watchdog 2 flag
mbed_official 155:8435094ec241 2082 (+) ADC_FLAG_MSTAWD3: ADC master Analog watchdog 3 flag
mbed_official 155:8435094ec241 2083 (+) ADC_FLAG_MSTJQOVF: ADC master Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2084
mbed_official 155:8435094ec241 2085 (##) Flags for Slave
mbed_official 155:8435094ec241 2086 (+) ADC_FLAG_SLVRDY: ADC slave Ready (ADRDY) flag
mbed_official 155:8435094ec241 2087 (+) ADC_FLAG_SLVEOSMP: ADC slave End of Sampling flag
mbed_official 155:8435094ec241 2088 (+) ADC_FLAG_SLVEOC: ADC slave End of Regular Conversion flag
mbed_official 155:8435094ec241 2089 (+) ADC_FLAG_SLVEOS: ADC slave End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2090 (+) ADC_FLAG_SLVOVR: ADC slave overrun flag
mbed_official 155:8435094ec241 2091 (+) ADC_FLAG_SLVJEOC: ADC slave End of Injected Conversion flag
mbed_official 155:8435094ec241 2092 (+) ADC_FLAG_SLVJEOS: ADC slave End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2093 (+) ADC_FLAG_SLVAWD1: ADC slave Analog watchdog 1 flag
mbed_official 155:8435094ec241 2094 (+) ADC_FLAG_SLVAWD2: ADC slave Analog watchdog 2 flag
mbed_official 155:8435094ec241 2095 (+) ADC_FLAG_SLVAWD3: ADC slave Analog watchdog 3 flag
mbed_official 155:8435094ec241 2096 (+) ADC_FLAG_SLVJQOVF: ADC slave Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2097
mbed_official 155:8435094ec241 2098 The user should identify which mode will be used in his application to manage
mbed_official 155:8435094ec241 2099 the ADC controller events: Polling mode or Interrupt mode.
mbed_official 155:8435094ec241 2100
mbed_official 155:8435094ec241 2101 In the Polling Mode it is advised to use the following functions:
mbed_official 155:8435094ec241 2102 - ADC_GetFlagStatus() : to check if flags events occur.
mbed_official 155:8435094ec241 2103 - ADC_ClearFlag() : to clear the flags events.
mbed_official 155:8435094ec241 2104
mbed_official 155:8435094ec241 2105 In the Interrupt Mode it is advised to use the following functions:
mbed_official 155:8435094ec241 2106 - ADC_ITConfig() : to enable or disable the interrupt source.
mbed_official 155:8435094ec241 2107 - ADC_GetITStatus() : to check if Interrupt occurs.
mbed_official 155:8435094ec241 2108 - ADC_ClearITPendingBit() : to clear the Interrupt pending Bit
mbed_official 155:8435094ec241 2109 (corresponding Flag).
mbed_official 155:8435094ec241 2110 @endverbatim
mbed_official 155:8435094ec241 2111 * @{
mbed_official 155:8435094ec241 2112 */
mbed_official 155:8435094ec241 2113
mbed_official 155:8435094ec241 2114 /**
mbed_official 155:8435094ec241 2115 * @brief Enables or disables the specified ADC interrupts.
mbed_official 155:8435094ec241 2116 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
mbed_official 155:8435094ec241 2117 * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
mbed_official 155:8435094ec241 2118 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 2119 * @arg ADC_IT_RDY: ADC Ready (ADRDY) interrupt source
mbed_official 155:8435094ec241 2120 * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
mbed_official 155:8435094ec241 2121 * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
mbed_official 155:8435094ec241 2122 * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
mbed_official 155:8435094ec241 2123 * @arg ADC_IT_OVR: ADC overrun interrupt source
mbed_official 155:8435094ec241 2124 * @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
mbed_official 155:8435094ec241 2125 * @arg ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
mbed_official 155:8435094ec241 2126 * @arg ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
mbed_official 155:8435094ec241 2127 * @arg ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
mbed_official 155:8435094ec241 2128 * @arg ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
mbed_official 155:8435094ec241 2129 * @arg ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
mbed_official 155:8435094ec241 2130 * @param NewState: new state of the specified ADC interrupts.
mbed_official 155:8435094ec241 2131 * This parameter can be: ENABLE or DISABLE.
mbed_official 155:8435094ec241 2132 * @retval None
mbed_official 155:8435094ec241 2133 */
mbed_official 155:8435094ec241 2134 void ADC_ITConfig(ADC_TypeDef* ADCx, uint32_t ADC_IT, FunctionalState NewState)
mbed_official 155:8435094ec241 2135 {
mbed_official 155:8435094ec241 2136 /* Check the parameters */
mbed_official 155:8435094ec241 2137 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2138 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 155:8435094ec241 2139 assert_param(IS_ADC_IT(ADC_IT));
mbed_official 155:8435094ec241 2140
mbed_official 155:8435094ec241 2141 if (NewState != DISABLE)
mbed_official 155:8435094ec241 2142 {
mbed_official 155:8435094ec241 2143 /* Enable the selected ADC interrupts */
mbed_official 155:8435094ec241 2144 ADCx->IER |= ADC_IT;
mbed_official 155:8435094ec241 2145 }
mbed_official 155:8435094ec241 2146 else
mbed_official 155:8435094ec241 2147 {
mbed_official 155:8435094ec241 2148 /* Disable the selected ADC interrupts */
mbed_official 155:8435094ec241 2149 ADCx->IER &= (~(uint32_t)ADC_IT);
mbed_official 155:8435094ec241 2150 }
mbed_official 155:8435094ec241 2151 }
mbed_official 155:8435094ec241 2152
mbed_official 155:8435094ec241 2153 /**
mbed_official 155:8435094ec241 2154 * @brief Checks whether the specified ADC flag is set or not.
mbed_official 155:8435094ec241 2155 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 2156 * @param ADC_FLAG: specifies the flag to check.
mbed_official 155:8435094ec241 2157 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2158 * @arg ADC_FLAG_RDY: ADC Ready (ADRDY) flag
mbed_official 155:8435094ec241 2159 * @arg ADC_FLAG_EOSMP: ADC End of Sampling flag
mbed_official 155:8435094ec241 2160 * @arg ADC_FLAG_EOC: ADC End of Regular Conversion flag
mbed_official 155:8435094ec241 2161 * @arg ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2162 * @arg ADC_FLAG_OVR: ADC overrun flag
mbed_official 155:8435094ec241 2163 * @arg ADC_FLAG_JEOC: ADC End of Injected Conversion flag
mbed_official 155:8435094ec241 2164 * @arg ADC_FLAG_JEOS: ADC End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2165 * @arg ADC_FLAG_AWD1: ADC Analog watchdog 1 flag
mbed_official 155:8435094ec241 2166 * @arg ADC_FLAG_AWD2: ADC Analog watchdog 2 flag
mbed_official 155:8435094ec241 2167 * @arg ADC_FLAG_AWD3: ADC Analog watchdog 3 flag
mbed_official 155:8435094ec241 2168 * @arg ADC_FLAG_JQOVF: ADC Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2169 * @retval The new state of ADC_FLAG (SET or RESET).
mbed_official 155:8435094ec241 2170 */
mbed_official 155:8435094ec241 2171 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
mbed_official 155:8435094ec241 2172 {
mbed_official 155:8435094ec241 2173 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 2174 /* Check the parameters */
mbed_official 155:8435094ec241 2175 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2176 assert_param(IS_ADC_GET_FLAG(ADC_FLAG));
mbed_official 155:8435094ec241 2177
mbed_official 155:8435094ec241 2178 /* Check the status of the specified ADC flag */
mbed_official 155:8435094ec241 2179 if ((ADCx->ISR & ADC_FLAG) != (uint32_t)RESET)
mbed_official 155:8435094ec241 2180 {
mbed_official 155:8435094ec241 2181 /* ADC_FLAG is set */
mbed_official 155:8435094ec241 2182 bitstatus = SET;
mbed_official 155:8435094ec241 2183 }
mbed_official 155:8435094ec241 2184 else
mbed_official 155:8435094ec241 2185 {
mbed_official 155:8435094ec241 2186 /* ADC_FLAG is reset */
mbed_official 155:8435094ec241 2187 bitstatus = RESET;
mbed_official 155:8435094ec241 2188 }
mbed_official 155:8435094ec241 2189 /* Return the ADC_FLAG status */
mbed_official 155:8435094ec241 2190 return bitstatus;
mbed_official 155:8435094ec241 2191 }
mbed_official 155:8435094ec241 2192
mbed_official 155:8435094ec241 2193 /**
mbed_official 155:8435094ec241 2194 * @brief Clears the ADCx's pending flags.
mbed_official 155:8435094ec241 2195 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 2196 * @param ADC_FLAG: specifies the flag to clear.
mbed_official 155:8435094ec241 2197 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 2198 * @arg ADC_FLAG_RDY: ADC Ready (ADRDY) flag
mbed_official 155:8435094ec241 2199 * @arg ADC_FLAG_EOSMP: ADC End of Sampling flag
mbed_official 155:8435094ec241 2200 * @arg ADC_FLAG_EOC: ADC End of Regular Conversion flag
mbed_official 155:8435094ec241 2201 * @arg ADC_FLAG_EOS: ADC End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2202 * @arg ADC_FLAG_OVR: ADC overrun flag
mbed_official 155:8435094ec241 2203 * @arg ADC_FLAG_JEOC: ADC End of Injected Conversion flag
mbed_official 155:8435094ec241 2204 * @arg ADC_FLAG_JEOS: ADC End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2205 * @arg ADC_FLAG_AWD1: ADC Analog watchdog 1 flag
mbed_official 155:8435094ec241 2206 * @arg ADC_FLAG_AWD2: ADC Analog watchdog 2 flag
mbed_official 155:8435094ec241 2207 * @arg ADC_FLAG_AWD3: ADC Analog watchdog 3 flag
mbed_official 155:8435094ec241 2208 * @arg ADC_FLAG_JQOVF: ADC Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2209 * @retval None
mbed_official 155:8435094ec241 2210 */
mbed_official 155:8435094ec241 2211 void ADC_ClearFlag(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
mbed_official 155:8435094ec241 2212 {
mbed_official 155:8435094ec241 2213 /* Check the parameters */
mbed_official 155:8435094ec241 2214 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2215 assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG));
mbed_official 155:8435094ec241 2216 /* Clear the selected ADC flags */
mbed_official 155:8435094ec241 2217 ADCx->ISR = (uint32_t)ADC_FLAG;
mbed_official 155:8435094ec241 2218 }
mbed_official 155:8435094ec241 2219
mbed_official 155:8435094ec241 2220 /**
mbed_official 155:8435094ec241 2221 * @brief Checks whether the specified ADC flag is set or not.
mbed_official 155:8435094ec241 2222 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 2223 * @param ADC_FLAG: specifies the master or slave flag to check.
mbed_official 155:8435094ec241 2224 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2225 * @arg ADC_FLAG_MSTRDY: ADC master Ready (ADRDY) flag
mbed_official 155:8435094ec241 2226 * @arg ADC_FLAG_MSTEOSMP: ADC master End of Sampling flag
mbed_official 155:8435094ec241 2227 * @arg ADC_FLAG_MSTEOC: ADC master End of Regular Conversion flag
mbed_official 155:8435094ec241 2228 * @arg ADC_FLAG_MSTEOS: ADC master End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2229 * @arg ADC_FLAG_MSTOVR: ADC master overrun flag
mbed_official 155:8435094ec241 2230 * @arg ADC_FLAG_MSTJEOC: ADC master End of Injected Conversion flag
mbed_official 155:8435094ec241 2231 * @arg ADC_FLAG_MSTJEOS: ADC master End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2232 * @arg ADC_FLAG_MSTAWD1: ADC master Analog watchdog 1 flag
mbed_official 155:8435094ec241 2233 * @arg ADC_FLAG_MSTAWD2: ADC master Analog watchdog 2 flag
mbed_official 155:8435094ec241 2234 * @arg ADC_FLAG_MSTAWD3: ADC master Analog watchdog 3 flag
mbed_official 155:8435094ec241 2235 * @arg ADC_FLAG_MSTJQOVF: ADC master Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2236 * @arg ADC_FLAG_SLVRDY: ADC slave Ready (ADRDY) flag
mbed_official 155:8435094ec241 2237 * @arg ADC_FLAG_SLVEOSMP: ADC slave End of Sampling flag
mbed_official 155:8435094ec241 2238 * @arg ADC_FLAG_SLVEOC: ADC slave End of Regular Conversion flag
mbed_official 155:8435094ec241 2239 * @arg ADC_FLAG_SLVEOS: ADC slave End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2240 * @arg ADC_FLAG_SLVOVR: ADC slave overrun flag
mbed_official 155:8435094ec241 2241 * @arg ADC_FLAG_SLVJEOC: ADC slave End of Injected Conversion flag
mbed_official 155:8435094ec241 2242 * @arg ADC_FLAG_SLVJEOS: ADC slave End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2243 * @arg ADC_FLAG_SLVAWD1: ADC slave Analog watchdog 1 flag
mbed_official 155:8435094ec241 2244 * @arg ADC_FLAG_SLVAWD2: ADC slave Analog watchdog 2 flag
mbed_official 155:8435094ec241 2245 * @arg ADC_FLAG_SLVAWD3: ADC slave Analog watchdog 3 flag
mbed_official 155:8435094ec241 2246 * @arg ADC_FLAG_SLVJQOVF: ADC slave Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2247 * @retval The new state of ADC_FLAG (SET or RESET).
mbed_official 155:8435094ec241 2248 */
mbed_official 155:8435094ec241 2249 FlagStatus ADC_GetCommonFlagStatus(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
mbed_official 155:8435094ec241 2250 {
mbed_official 155:8435094ec241 2251 uint32_t tmpreg1 = 0;
mbed_official 155:8435094ec241 2252 FlagStatus bitstatus = RESET;
mbed_official 155:8435094ec241 2253
mbed_official 155:8435094ec241 2254 /* Check the parameters */
mbed_official 155:8435094ec241 2255 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2256 assert_param(IS_ADC_GET_COMMONFLAG(ADC_FLAG));
mbed_official 155:8435094ec241 2257
mbed_official 155:8435094ec241 2258 if((ADCx == ADC1) || (ADCx == ADC2))
mbed_official 155:8435094ec241 2259 {
mbed_official 155:8435094ec241 2260 tmpreg1 = ADC1_2->CSR;
mbed_official 155:8435094ec241 2261 }
mbed_official 155:8435094ec241 2262 else
mbed_official 155:8435094ec241 2263 {
mbed_official 155:8435094ec241 2264 tmpreg1 = ADC3_4->CSR;
mbed_official 155:8435094ec241 2265 }
mbed_official 155:8435094ec241 2266 /* Check the status of the specified ADC flag */
mbed_official 155:8435094ec241 2267 if ((tmpreg1 & ADC_FLAG) != (uint32_t)RESET)
mbed_official 155:8435094ec241 2268 {
mbed_official 155:8435094ec241 2269 /* ADC_FLAG is set */
mbed_official 155:8435094ec241 2270 bitstatus = SET;
mbed_official 155:8435094ec241 2271 }
mbed_official 155:8435094ec241 2272 else
mbed_official 155:8435094ec241 2273 {
mbed_official 155:8435094ec241 2274 /* ADC_FLAG is reset */
mbed_official 155:8435094ec241 2275 bitstatus = RESET;
mbed_official 155:8435094ec241 2276 }
mbed_official 155:8435094ec241 2277 /* Return the ADC_FLAG status */
mbed_official 155:8435094ec241 2278 return bitstatus;
mbed_official 155:8435094ec241 2279 }
mbed_official 155:8435094ec241 2280
mbed_official 155:8435094ec241 2281 /**
mbed_official 155:8435094ec241 2282 * @brief Clears the ADCx's pending flags.
mbed_official 155:8435094ec241 2283 * @param ADCx: where x can be 1, 2, 3 or 4 to select the ADC peripheral.
mbed_official 155:8435094ec241 2284 * @param ADC_FLAG: specifies the master or slave flag to clear.
mbed_official 155:8435094ec241 2285 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2286 * @arg ADC_FLAG_MSTRDY: ADC master Ready (ADRDY) flag
mbed_official 155:8435094ec241 2287 * @arg ADC_FLAG_MSTEOSMP: ADC master End of Sampling flag
mbed_official 155:8435094ec241 2288 * @arg ADC_FLAG_MSTEOC: ADC master End of Regular Conversion flag
mbed_official 155:8435094ec241 2289 * @arg ADC_FLAG_MSTEOS: ADC master End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2290 * @arg ADC_FLAG_MSTOVR: ADC master overrun flag
mbed_official 155:8435094ec241 2291 * @arg ADC_FLAG_MSTJEOC: ADC master End of Injected Conversion flag
mbed_official 155:8435094ec241 2292 * @arg ADC_FLAG_MSTJEOS: ADC master End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2293 * @arg ADC_FLAG_MSTAWD1: ADC master Analog watchdog 1 flag
mbed_official 155:8435094ec241 2294 * @arg ADC_FLAG_MSTAWD2: ADC master Analog watchdog 2 flag
mbed_official 155:8435094ec241 2295 * @arg ADC_FLAG_MSTAWD3: ADC master Analog watchdog 3 flag
mbed_official 155:8435094ec241 2296 * @arg ADC_FLAG_MSTJQOVF: ADC master Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2297 * @arg ADC_FLAG_SLVRDY: ADC slave Ready (ADRDY) flag
mbed_official 155:8435094ec241 2298 * @arg ADC_FLAG_SLVEOSMP: ADC slave End of Sampling flag
mbed_official 155:8435094ec241 2299 * @arg ADC_FLAG_SLVEOC: ADC slave End of Regular Conversion flag
mbed_official 155:8435094ec241 2300 * @arg ADC_FLAG_SLVEOS: ADC slave End of Regular sequence of Conversions flag
mbed_official 155:8435094ec241 2301 * @arg ADC_FLAG_SLVOVR: ADC slave overrun flag
mbed_official 155:8435094ec241 2302 * @arg ADC_FLAG_SLVJEOC: ADC slave End of Injected Conversion flag
mbed_official 155:8435094ec241 2303 * @arg ADC_FLAG_SLVJEOS: ADC slave End of Injected sequence of Conversions flag
mbed_official 155:8435094ec241 2304 * @arg ADC_FLAG_SLVAWD1: ADC slave Analog watchdog 1 flag
mbed_official 155:8435094ec241 2305 * @arg ADC_FLAG_SLVAWD2: ADC slave Analog watchdog 2 flag
mbed_official 155:8435094ec241 2306 * @arg ADC_FLAG_SLVAWD3: ADC slave Analog watchdog 3 flag
mbed_official 155:8435094ec241 2307 * @arg ADC_FLAG_SLVJQOVF: ADC slave Injected Context Queue Overflow flag
mbed_official 155:8435094ec241 2308 * @retval None
mbed_official 155:8435094ec241 2309 */
mbed_official 155:8435094ec241 2310 void ADC_ClearCommonFlag(ADC_TypeDef* ADCx, uint32_t ADC_FLAG)
mbed_official 155:8435094ec241 2311 {
mbed_official 155:8435094ec241 2312 /* Check the parameters */
mbed_official 155:8435094ec241 2313 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2314 assert_param(IS_ADC_CLEAR_COMMONFLAG(ADC_FLAG));
mbed_official 155:8435094ec241 2315
mbed_official 155:8435094ec241 2316 if((ADCx == ADC1) || (ADCx == ADC2))
mbed_official 155:8435094ec241 2317 {
mbed_official 155:8435094ec241 2318 /* Clear the selected ADC flags */
mbed_official 155:8435094ec241 2319 ADC1_2->CSR |= (uint32_t)ADC_FLAG;
mbed_official 155:8435094ec241 2320 }
mbed_official 155:8435094ec241 2321 else
mbed_official 155:8435094ec241 2322 {
mbed_official 155:8435094ec241 2323 /* Clear the selected ADC flags */
mbed_official 155:8435094ec241 2324 ADC3_4->CSR |= (uint32_t)ADC_FLAG;
mbed_official 155:8435094ec241 2325 }
mbed_official 155:8435094ec241 2326 }
mbed_official 155:8435094ec241 2327
mbed_official 155:8435094ec241 2328 /**
mbed_official 155:8435094ec241 2329 * @brief Checks whether the specified ADC interrupt has occurred or not.
mbed_official 155:8435094ec241 2330 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
mbed_official 155:8435094ec241 2331 * @param ADC_IT: specifies the ADC interrupt source to check.
mbed_official 155:8435094ec241 2332 * This parameter can be one of the following values:
mbed_official 155:8435094ec241 2333 * @arg ADC_IT_RDY: ADC Ready (ADRDY) interrupt source
mbed_official 155:8435094ec241 2334 * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
mbed_official 155:8435094ec241 2335 * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
mbed_official 155:8435094ec241 2336 * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
mbed_official 155:8435094ec241 2337 * @arg ADC_IT_OVR: ADC overrun interrupt source
mbed_official 155:8435094ec241 2338 * @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
mbed_official 155:8435094ec241 2339 * @arg ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
mbed_official 155:8435094ec241 2340 * @arg ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
mbed_official 155:8435094ec241 2341 * @arg ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
mbed_official 155:8435094ec241 2342 * @arg ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
mbed_official 155:8435094ec241 2343 * @arg ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
mbed_official 155:8435094ec241 2344 * @retval The new state of ADC_IT (SET or RESET).
mbed_official 155:8435094ec241 2345 */
mbed_official 155:8435094ec241 2346 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint32_t ADC_IT)
mbed_official 155:8435094ec241 2347 {
mbed_official 155:8435094ec241 2348 ITStatus bitstatus = RESET;
mbed_official 155:8435094ec241 2349 uint16_t itstatus = 0x0, itenable = 0x0;
mbed_official 155:8435094ec241 2350 /* Check the parameters */
mbed_official 155:8435094ec241 2351 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2352 assert_param(IS_ADC_GET_IT(ADC_IT));
mbed_official 155:8435094ec241 2353
mbed_official 155:8435094ec241 2354 itstatus = ADCx->ISR & ADC_IT;
mbed_official 155:8435094ec241 2355
mbed_official 155:8435094ec241 2356 itenable = ADCx->IER & ADC_IT;
mbed_official 155:8435094ec241 2357 if ((itstatus != (uint32_t)RESET) && (itenable != (uint32_t)RESET))
mbed_official 155:8435094ec241 2358 {
mbed_official 155:8435094ec241 2359 bitstatus = SET;
mbed_official 155:8435094ec241 2360 }
mbed_official 155:8435094ec241 2361 else
mbed_official 155:8435094ec241 2362 {
mbed_official 155:8435094ec241 2363 bitstatus = RESET;
mbed_official 155:8435094ec241 2364 }
mbed_official 155:8435094ec241 2365 return bitstatus;
mbed_official 155:8435094ec241 2366 }
mbed_official 155:8435094ec241 2367
mbed_official 155:8435094ec241 2368 /**
mbed_official 155:8435094ec241 2369 * @brief Clears the ADCx's interrupt pending bits.
mbed_official 155:8435094ec241 2370 * @param ADCx: where x can be 1, 2 or 3 to select the ADC peripheral.
mbed_official 155:8435094ec241 2371 * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
mbed_official 155:8435094ec241 2372 * This parameter can be any combination of the following values:
mbed_official 155:8435094ec241 2373 * @arg ADC_IT_RDY: ADC Ready (ADRDY) interrupt source
mbed_official 155:8435094ec241 2374 * @arg ADC_IT_EOSMP: ADC End of Sampling interrupt source
mbed_official 155:8435094ec241 2375 * @arg ADC_IT_EOC: ADC End of Regular Conversion interrupt source
mbed_official 155:8435094ec241 2376 * @arg ADC_IT_EOS: ADC End of Regular sequence of Conversions interrupt source
mbed_official 155:8435094ec241 2377 * @arg ADC_IT_OVR: ADC overrun interrupt source
mbed_official 155:8435094ec241 2378 * @arg ADC_IT_JEOC: ADC End of Injected Conversion interrupt source
mbed_official 155:8435094ec241 2379 * @arg ADC_IT_JEOS: ADC End of Injected sequence of Conversions interrupt source
mbed_official 155:8435094ec241 2380 * @arg ADC_IT_AWD1: ADC Analog watchdog 1 interrupt source
mbed_official 155:8435094ec241 2381 * @arg ADC_IT_AWD2: ADC Analog watchdog 2 interrupt source
mbed_official 155:8435094ec241 2382 * @arg ADC_IT_AWD3: ADC Analog watchdog 3 interrupt source
mbed_official 155:8435094ec241 2383 * @arg ADC_IT_JQOVF: ADC Injected Context Queue Overflow interrupt source
mbed_official 155:8435094ec241 2384 * @retval None
mbed_official 155:8435094ec241 2385 */
mbed_official 155:8435094ec241 2386 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint32_t ADC_IT)
mbed_official 155:8435094ec241 2387 {
mbed_official 155:8435094ec241 2388 /* Check the parameters */
mbed_official 155:8435094ec241 2389 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 155:8435094ec241 2390 assert_param(IS_ADC_IT(ADC_IT));
mbed_official 155:8435094ec241 2391 /* Clear the selected ADC interrupt pending bit */
mbed_official 155:8435094ec241 2392 ADCx->ISR = (uint32_t)ADC_IT;
mbed_official 155:8435094ec241 2393 }
mbed_official 155:8435094ec241 2394
mbed_official 155:8435094ec241 2395 /**
mbed_official 155:8435094ec241 2396 * @}
mbed_official 155:8435094ec241 2397 */
mbed_official 155:8435094ec241 2398
mbed_official 155:8435094ec241 2399 /**
mbed_official 155:8435094ec241 2400 * @}
mbed_official 155:8435094ec241 2401 */
mbed_official 155:8435094ec241 2402
mbed_official 155:8435094ec241 2403 /**
mbed_official 155:8435094ec241 2404 * @}
mbed_official 155:8435094ec241 2405 */
mbed_official 155:8435094ec241 2406
mbed_official 155:8435094ec241 2407 /**
mbed_official 155:8435094ec241 2408 * @}
mbed_official 155:8435094ec241 2409 */
mbed_official 155:8435094ec241 2410
mbed_official 155:8435094ec241 2411 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/