mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
shaoziyang
Date:
Sat Sep 13 14:25:46 2014 +0000
Revision:
323:9e901b0a5aa1
Parent:
157:90e3acc479a2
test with CLOCK_SETUP = 0

Who changed what in which revision?

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