mbed SDK library sources

Fork of mbed-src by mbed official

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jan 30 12:15:05 2014 +0000
Revision:
80:66393a7b209d
Parent:
76:aeb1df146756
Synchronized with git revision dba523f83fe09b7fce11fc1299dd1216e9776359

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

Update of I2C, SPI, SLEEP for NUCLEO_F103RB and L152RE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /**
mbed_official 76:aeb1df146756 2 ******************************************************************************
mbed_official 76:aeb1df146756 3 * @file stm32l1xx_adc.c
mbed_official 76:aeb1df146756 4 * @author MCD Application Team
mbed_official 80:66393a7b209d 5 * @version V1.3.0
mbed_official 80:66393a7b209d 6 * @date 31-January-2014
mbed_official 76:aeb1df146756 7 * @brief This file provides firmware functions to manage the following
mbed_official 76:aeb1df146756 8 * functionalities of the Analog to Digital Convertor (ADC) peripheral:
mbed_official 76:aeb1df146756 9 * + Initialization and Configuration
mbed_official 76:aeb1df146756 10 * + Power saving
mbed_official 76:aeb1df146756 11 * + Analog Watchdog configuration
mbed_official 76:aeb1df146756 12 * + Temperature Sensor & Vrefint (Voltage Reference internal) management
mbed_official 76:aeb1df146756 13 * + Regular Channels Configuration
mbed_official 76:aeb1df146756 14 * + Regular Channels DMA Configuration
mbed_official 76:aeb1df146756 15 * + Injected channels Configuration
mbed_official 76:aeb1df146756 16 * + Interrupts and flags management
mbed_official 76:aeb1df146756 17 *
mbed_official 76:aeb1df146756 18 * @verbatim
mbed_official 76:aeb1df146756 19 ================================================================================
mbed_official 76:aeb1df146756 20 ##### How to use this driver #####
mbed_official 76:aeb1df146756 21 ================================================================================
mbed_official 76:aeb1df146756 22 [..]
mbed_official 76:aeb1df146756 23 (#) Configure the ADC Prescaler, conversion resolution and data alignment
mbed_official 76:aeb1df146756 24 using the ADC_Init() function.
mbed_official 76:aeb1df146756 25 (#) Activate the ADC peripheral using ADC_Cmd() function.
mbed_official 76:aeb1df146756 26
mbed_official 76:aeb1df146756 27 *** Regular channels group configuration ***
mbed_official 76:aeb1df146756 28 ============================================
mbed_official 76:aeb1df146756 29 [..]
mbed_official 76:aeb1df146756 30 (+) To configure the ADC regular channels group features, use
mbed_official 76:aeb1df146756 31 ADC_Init() and ADC_RegularChannelConfig() functions.
mbed_official 76:aeb1df146756 32 (+) To activate the continuous mode, use the ADC_continuousModeCmd()
mbed_official 76:aeb1df146756 33 function.
mbed_official 76:aeb1df146756 34 (+) To configurate and activate the Discontinuous mode, use the
mbed_official 76:aeb1df146756 35 ADC_DiscModeChannelCountConfig() and ADC_DiscModeCmd() functions.
mbed_official 76:aeb1df146756 36 (+) To read the ADC converted values, use the ADC_GetConversionValue()
mbed_official 76:aeb1df146756 37 function.
mbed_official 76:aeb1df146756 38
mbed_official 76:aeb1df146756 39 *** DMA for Regular channels group features configuration ***
mbed_official 76:aeb1df146756 40 =============================================================
mbed_official 76:aeb1df146756 41 [..]
mbed_official 76:aeb1df146756 42 (+) To enable the DMA mode for regular channels group, use the
mbed_official 76:aeb1df146756 43 ADC_DMACmd() function.
mbed_official 76:aeb1df146756 44 (+) To enable the generation of DMA requests continuously at the end
mbed_official 76:aeb1df146756 45 of the last DMA transfer, use the ADC_DMARequestAfterLastTransferCmd()
mbed_official 76:aeb1df146756 46 function.
mbed_official 76:aeb1df146756 47
mbed_official 76:aeb1df146756 48 *** Injected channels group configuration ***
mbed_official 76:aeb1df146756 49 =============================================
mbed_official 76:aeb1df146756 50 [..]
mbed_official 76:aeb1df146756 51 (+) To configure the ADC Injected channels group features, use
mbed_official 76:aeb1df146756 52 ADC_InjectedChannelConfig() and ADC_InjectedSequencerLengthConfig()
mbed_official 76:aeb1df146756 53 functions.
mbed_official 76:aeb1df146756 54 (+) To activate the continuous mode, use the ADC_continuousModeCmd()
mbed_official 76:aeb1df146756 55 function.
mbed_official 76:aeb1df146756 56 (+) To activate the Injected Discontinuous mode, use the
mbed_official 76:aeb1df146756 57 ADC_InjectedDiscModeCmd() function.
mbed_official 76:aeb1df146756 58 (+) To activate the AutoInjected mode, use the ADC_AutoInjectedConvCmd()
mbed_official 76:aeb1df146756 59 function.
mbed_official 76:aeb1df146756 60 (+) To read the ADC converted values, use the ADC_GetInjectedConversionValue()
mbed_official 76:aeb1df146756 61 function.
mbed_official 76:aeb1df146756 62
mbed_official 76:aeb1df146756 63 @endverbatim
mbed_official 76:aeb1df146756 64 *
mbed_official 76:aeb1df146756 65 ******************************************************************************
mbed_official 76:aeb1df146756 66 * @attention
mbed_official 76:aeb1df146756 67 *
mbed_official 80:66393a7b209d 68 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
mbed_official 76:aeb1df146756 69 *
mbed_official 76:aeb1df146756 70 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
mbed_official 76:aeb1df146756 71 * You may not use this file except in compliance with the License.
mbed_official 76:aeb1df146756 72 * You may obtain a copy of the License at:
mbed_official 76:aeb1df146756 73 *
mbed_official 76:aeb1df146756 74 * http://www.st.com/software_license_agreement_liberty_v2
mbed_official 76:aeb1df146756 75 *
mbed_official 76:aeb1df146756 76 * Unless required by applicable law or agreed to in writing, software
mbed_official 76:aeb1df146756 77 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 76:aeb1df146756 78 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 76:aeb1df146756 79 * See the License for the specific language governing permissions and
mbed_official 76:aeb1df146756 80 * limitations under the License.
mbed_official 76:aeb1df146756 81 *
mbed_official 76:aeb1df146756 82 ******************************************************************************
mbed_official 76:aeb1df146756 83 */
mbed_official 76:aeb1df146756 84
mbed_official 76:aeb1df146756 85 /* Includes ------------------------------------------------------------------*/
mbed_official 76:aeb1df146756 86 #include "stm32l1xx_adc.h"
mbed_official 76:aeb1df146756 87 #include "stm32l1xx_rcc.h"
mbed_official 76:aeb1df146756 88
mbed_official 76:aeb1df146756 89 /** @addtogroup STM32L1xx_StdPeriph_Driver
mbed_official 76:aeb1df146756 90 * @{
mbed_official 76:aeb1df146756 91 */
mbed_official 76:aeb1df146756 92
mbed_official 76:aeb1df146756 93 /** @defgroup ADC
mbed_official 76:aeb1df146756 94 * @brief ADC driver modules
mbed_official 76:aeb1df146756 95 * @{
mbed_official 76:aeb1df146756 96 */
mbed_official 76:aeb1df146756 97
mbed_official 76:aeb1df146756 98 /* Private typedef -----------------------------------------------------------*/
mbed_official 76:aeb1df146756 99 /* Private define ------------------------------------------------------------*/
mbed_official 76:aeb1df146756 100 /* ADC DISCNUM mask */
mbed_official 76:aeb1df146756 101 #define CR1_DISCNUM_RESET ((uint32_t)0xFFFF1FFF)
mbed_official 76:aeb1df146756 102
mbed_official 76:aeb1df146756 103 /* ADC AWDCH mask */
mbed_official 76:aeb1df146756 104 #define CR1_AWDCH_RESET ((uint32_t)0xFFFFFFE0)
mbed_official 76:aeb1df146756 105
mbed_official 76:aeb1df146756 106 /* ADC Analog watchdog enable mode mask */
mbed_official 76:aeb1df146756 107 #define CR1_AWDMODE_RESET ((uint32_t)0xFF3FFDFF)
mbed_official 76:aeb1df146756 108
mbed_official 76:aeb1df146756 109 /* CR1 register Mask */
mbed_official 76:aeb1df146756 110 #define CR1_CLEAR_MASK ((uint32_t)0xFCFFFEFF)
mbed_official 76:aeb1df146756 111
mbed_official 76:aeb1df146756 112 /* ADC DELAY mask */
mbed_official 76:aeb1df146756 113 #define CR2_DELS_RESET ((uint32_t)0xFFFFFF0F)
mbed_official 76:aeb1df146756 114
mbed_official 76:aeb1df146756 115 /* ADC JEXTEN mask */
mbed_official 76:aeb1df146756 116 #define CR2_JEXTEN_RESET ((uint32_t)0xFFCFFFFF)
mbed_official 76:aeb1df146756 117
mbed_official 76:aeb1df146756 118 /* ADC JEXTSEL mask */
mbed_official 76:aeb1df146756 119 #define CR2_JEXTSEL_RESET ((uint32_t)0xFFF0FFFF)
mbed_official 76:aeb1df146756 120
mbed_official 76:aeb1df146756 121 /* CR2 register Mask */
mbed_official 76:aeb1df146756 122 #define CR2_CLEAR_MASK ((uint32_t)0xC0FFF7FD)
mbed_official 76:aeb1df146756 123
mbed_official 76:aeb1df146756 124 /* ADC SQx mask */
mbed_official 76:aeb1df146756 125 #define SQR5_SQ_SET ((uint32_t)0x0000001F)
mbed_official 76:aeb1df146756 126 #define SQR4_SQ_SET ((uint32_t)0x0000001F)
mbed_official 76:aeb1df146756 127 #define SQR3_SQ_SET ((uint32_t)0x0000001F)
mbed_official 76:aeb1df146756 128 #define SQR2_SQ_SET ((uint32_t)0x0000001F)
mbed_official 76:aeb1df146756 129 #define SQR1_SQ_SET ((uint32_t)0x0000001F)
mbed_official 76:aeb1df146756 130
mbed_official 76:aeb1df146756 131 /* ADC L Mask */
mbed_official 76:aeb1df146756 132 #define SQR1_L_RESET ((uint32_t)0xFE0FFFFF)
mbed_official 76:aeb1df146756 133
mbed_official 76:aeb1df146756 134 /* ADC JSQx mask */
mbed_official 76:aeb1df146756 135 #define JSQR_JSQ_SET ((uint32_t)0x0000001F)
mbed_official 76:aeb1df146756 136
mbed_official 76:aeb1df146756 137 /* ADC JL mask */
mbed_official 76:aeb1df146756 138 #define JSQR_JL_SET ((uint32_t)0x00300000)
mbed_official 76:aeb1df146756 139 #define JSQR_JL_RESET ((uint32_t)0xFFCFFFFF)
mbed_official 76:aeb1df146756 140
mbed_official 76:aeb1df146756 141 /* ADC SMPx mask */
mbed_official 76:aeb1df146756 142 #define SMPR1_SMP_SET ((uint32_t)0x00000007)
mbed_official 76:aeb1df146756 143 #define SMPR2_SMP_SET ((uint32_t)0x00000007)
mbed_official 76:aeb1df146756 144 #define SMPR3_SMP_SET ((uint32_t)0x00000007)
mbed_official 76:aeb1df146756 145 #define SMPR0_SMP_SET ((uint32_t)0x00000007)
mbed_official 76:aeb1df146756 146
mbed_official 76:aeb1df146756 147 /* ADC JDRx registers offset */
mbed_official 76:aeb1df146756 148 #define JDR_OFFSET ((uint8_t)0x30)
mbed_official 76:aeb1df146756 149
mbed_official 76:aeb1df146756 150 /* ADC CCR register Mask */
mbed_official 76:aeb1df146756 151 #define CR_CLEAR_MASK ((uint32_t)0xFFFCFFFF)
mbed_official 76:aeb1df146756 152
mbed_official 76:aeb1df146756 153 /* Private macro -------------------------------------------------------------*/
mbed_official 76:aeb1df146756 154 /* Private variables ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 155 /* Private function prototypes -----------------------------------------------*/
mbed_official 76:aeb1df146756 156 /* Private functions ---------------------------------------------------------*/
mbed_official 76:aeb1df146756 157
mbed_official 76:aeb1df146756 158 /** @defgroup ADC_Private_Functions
mbed_official 76:aeb1df146756 159 * @{
mbed_official 76:aeb1df146756 160 */
mbed_official 76:aeb1df146756 161
mbed_official 76:aeb1df146756 162 /** @defgroup ADC_Group1 Initialization and Configuration functions
mbed_official 76:aeb1df146756 163 * @brief Initialization and Configuration functions.
mbed_official 76:aeb1df146756 164 *
mbed_official 76:aeb1df146756 165 @verbatim
mbed_official 76:aeb1df146756 166 ===============================================================================
mbed_official 76:aeb1df146756 167 ##### Initialization and Configuration functions #####
mbed_official 76:aeb1df146756 168 ===============================================================================
mbed_official 76:aeb1df146756 169 [..] This section provides functions allowing to:
mbed_official 76:aeb1df146756 170 (+) Initialize and configure the ADC Prescaler.
mbed_official 76:aeb1df146756 171 (+) ADC Conversion Resolution (12bit..6bit).
mbed_official 76:aeb1df146756 172 (+) Scan Conversion Mode (multichannel or one channel) for regular group.
mbed_official 76:aeb1df146756 173 (+) ADC Continuous Conversion Mode (Continuous or Single conversion) for
mbed_official 76:aeb1df146756 174 regular group.
mbed_official 76:aeb1df146756 175 (+) External trigger Edge and source of regular group.
mbed_official 76:aeb1df146756 176 (+) Converted data alignment (left or right).
mbed_official 76:aeb1df146756 177 (+) The number of ADC conversions that will be done using the sequencer
mbed_official 76:aeb1df146756 178 for regular channel group.
mbed_official 76:aeb1df146756 179 (+) Enable or disable the ADC peripheral.
mbed_official 76:aeb1df146756 180
mbed_official 76:aeb1df146756 181 @endverbatim
mbed_official 76:aeb1df146756 182 * @{
mbed_official 76:aeb1df146756 183 */
mbed_official 76:aeb1df146756 184
mbed_official 76:aeb1df146756 185 /**
mbed_official 76:aeb1df146756 186 * @brief Deinitializes ADC1 peripheral registers to their default reset values.
mbed_official 76:aeb1df146756 187 * @param None
mbed_official 76:aeb1df146756 188 * @retval None
mbed_official 76:aeb1df146756 189 */
mbed_official 76:aeb1df146756 190 void ADC_DeInit(ADC_TypeDef* ADCx)
mbed_official 76:aeb1df146756 191 {
mbed_official 76:aeb1df146756 192 /* Check the parameters */
mbed_official 76:aeb1df146756 193 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 194
mbed_official 76:aeb1df146756 195 if(ADCx == ADC1)
mbed_official 76:aeb1df146756 196 {
mbed_official 76:aeb1df146756 197 /* Enable ADC1 reset state */
mbed_official 76:aeb1df146756 198 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, ENABLE);
mbed_official 76:aeb1df146756 199 /* Release ADC1 from reset state */
mbed_official 76:aeb1df146756 200 RCC_APB2PeriphResetCmd(RCC_APB2Periph_ADC1, DISABLE);
mbed_official 76:aeb1df146756 201 }
mbed_official 76:aeb1df146756 202 }
mbed_official 76:aeb1df146756 203
mbed_official 76:aeb1df146756 204 /**
mbed_official 76:aeb1df146756 205 * @brief Initializes the ADCx peripheral according to the specified parameters
mbed_official 76:aeb1df146756 206 * in the ADC_InitStruct.
mbed_official 76:aeb1df146756 207 * @note This function is used to configure the global features of the ADC (
mbed_official 76:aeb1df146756 208 * Resolution and Data Alignment), however, the rest of the configuration
mbed_official 76:aeb1df146756 209 * parameters are specific to the regular channels group (scan mode
mbed_official 76:aeb1df146756 210 * activation, continuous mode activation, External trigger source and
mbed_official 76:aeb1df146756 211 * edge, number of conversion in the regular channels group sequencer).
mbed_official 76:aeb1df146756 212 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 76:aeb1df146756 213 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure that contains
mbed_official 76:aeb1df146756 214 * the configuration information for the specified ADC peripheral.
mbed_official 76:aeb1df146756 215 * @retval None
mbed_official 76:aeb1df146756 216 */
mbed_official 76:aeb1df146756 217 void ADC_Init(ADC_TypeDef* ADCx, ADC_InitTypeDef* ADC_InitStruct)
mbed_official 76:aeb1df146756 218 {
mbed_official 76:aeb1df146756 219 uint32_t tmpreg1 = 0;
mbed_official 76:aeb1df146756 220 uint8_t tmpreg2 = 0;
mbed_official 76:aeb1df146756 221
mbed_official 76:aeb1df146756 222 /* Check the parameters */
mbed_official 76:aeb1df146756 223 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 224 assert_param(IS_ADC_RESOLUTION(ADC_InitStruct->ADC_Resolution));
mbed_official 76:aeb1df146756 225 assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ScanConvMode));
mbed_official 76:aeb1df146756 226 assert_param(IS_FUNCTIONAL_STATE(ADC_InitStruct->ADC_ContinuousConvMode));
mbed_official 76:aeb1df146756 227 assert_param(IS_ADC_EXT_TRIG_EDGE(ADC_InitStruct->ADC_ExternalTrigConvEdge));
mbed_official 76:aeb1df146756 228 assert_param(IS_ADC_EXT_TRIG(ADC_InitStruct->ADC_ExternalTrigConv));
mbed_official 76:aeb1df146756 229 assert_param(IS_ADC_DATA_ALIGN(ADC_InitStruct->ADC_DataAlign));
mbed_official 76:aeb1df146756 230 assert_param(IS_ADC_REGULAR_LENGTH(ADC_InitStruct->ADC_NbrOfConversion));
mbed_official 76:aeb1df146756 231
mbed_official 76:aeb1df146756 232 /*---------------------------- ADCx CR1 Configuration -----------------*/
mbed_official 76:aeb1df146756 233 /* Get the ADCx CR1 value */
mbed_official 76:aeb1df146756 234 tmpreg1 = ADCx->CR1;
mbed_official 76:aeb1df146756 235 /* Clear RES and SCAN bits */
mbed_official 76:aeb1df146756 236 tmpreg1 &= CR1_CLEAR_MASK;
mbed_official 76:aeb1df146756 237 /* Configure ADCx: scan conversion mode and resolution */
mbed_official 76:aeb1df146756 238 /* Set SCAN bit according to ADC_ScanConvMode value */
mbed_official 76:aeb1df146756 239 /* Set RES bit according to ADC_Resolution value */
mbed_official 76:aeb1df146756 240 tmpreg1 |= (uint32_t)(((uint32_t)ADC_InitStruct->ADC_ScanConvMode << 8) | ADC_InitStruct->ADC_Resolution);
mbed_official 76:aeb1df146756 241 /* Write to ADCx CR1 */
mbed_official 76:aeb1df146756 242 ADCx->CR1 = tmpreg1;
mbed_official 76:aeb1df146756 243
mbed_official 76:aeb1df146756 244 /*---------------------------- ADCx CR2 Configuration -----------------*/
mbed_official 76:aeb1df146756 245 /* Get the ADCx CR2 value */
mbed_official 76:aeb1df146756 246 tmpreg1 = ADCx->CR2;
mbed_official 76:aeb1df146756 247 /* Clear CONT, ALIGN, EXTEN and EXTSEL bits */
mbed_official 76:aeb1df146756 248 tmpreg1 &= CR2_CLEAR_MASK;
mbed_official 76:aeb1df146756 249 /* Configure ADCx: external trigger event and edge, data alignment and continuous conversion mode */
mbed_official 76:aeb1df146756 250 /* Set ALIGN bit according to ADC_DataAlign value */
mbed_official 76:aeb1df146756 251 /* Set EXTEN bits according to ADC_ExternalTrigConvEdge value */
mbed_official 76:aeb1df146756 252 /* Set EXTSEL bits according to ADC_ExternalTrigConv value */
mbed_official 76:aeb1df146756 253 /* Set CONT bit according to ADC_ContinuousConvMode value */
mbed_official 76:aeb1df146756 254 tmpreg1 |= (uint32_t)(ADC_InitStruct->ADC_DataAlign | ADC_InitStruct->ADC_ExternalTrigConv |
mbed_official 76:aeb1df146756 255 ADC_InitStruct->ADC_ExternalTrigConvEdge | ((uint32_t)ADC_InitStruct->ADC_ContinuousConvMode << 1));
mbed_official 76:aeb1df146756 256 /* Write to ADCx CR2 */
mbed_official 76:aeb1df146756 257 ADCx->CR2 = tmpreg1;
mbed_official 76:aeb1df146756 258
mbed_official 76:aeb1df146756 259 /*---------------------------- ADCx SQR1 Configuration -----------------*/
mbed_official 76:aeb1df146756 260 /* Get the ADCx SQR1 value */
mbed_official 76:aeb1df146756 261 tmpreg1 = ADCx->SQR1;
mbed_official 76:aeb1df146756 262 /* Clear L bits */
mbed_official 76:aeb1df146756 263 tmpreg1 &= SQR1_L_RESET;
mbed_official 76:aeb1df146756 264 /* Configure ADCx: regular channel sequence length */
mbed_official 76:aeb1df146756 265 /* Set L bits according to ADC_NbrOfConversion value */
mbed_official 76:aeb1df146756 266 tmpreg2 |= (uint8_t)(ADC_InitStruct->ADC_NbrOfConversion - (uint8_t)1);
mbed_official 76:aeb1df146756 267 tmpreg1 |= ((uint32_t)tmpreg2 << 20);
mbed_official 76:aeb1df146756 268 /* Write to ADCx SQR1 */
mbed_official 76:aeb1df146756 269 ADCx->SQR1 = tmpreg1;
mbed_official 76:aeb1df146756 270 }
mbed_official 76:aeb1df146756 271
mbed_official 76:aeb1df146756 272 /**
mbed_official 76:aeb1df146756 273 * @brief Fills each ADC_InitStruct member with its default value.
mbed_official 76:aeb1df146756 274 * @note This function is used to initialize the global features of the ADC (
mbed_official 76:aeb1df146756 275 * Resolution and Data Alignment), however, the rest of the configuration
mbed_official 76:aeb1df146756 276 * parameters are specific to the regular channels group (scan mode
mbed_official 76:aeb1df146756 277 * activation, continuous mode activation, External trigger source and
mbed_official 76:aeb1df146756 278 * edge, number of conversion in the regular channels group sequencer).
mbed_official 76:aeb1df146756 279 * @param ADC_InitStruct: pointer to an ADC_InitTypeDef structure which will
mbed_official 76:aeb1df146756 280 * be initialized.
mbed_official 76:aeb1df146756 281 * @retval None
mbed_official 76:aeb1df146756 282 */
mbed_official 76:aeb1df146756 283 void ADC_StructInit(ADC_InitTypeDef* ADC_InitStruct)
mbed_official 76:aeb1df146756 284 {
mbed_official 76:aeb1df146756 285 /* Reset ADC init structure parameters values */
mbed_official 76:aeb1df146756 286 /* Initialize the ADC_Resolution member */
mbed_official 76:aeb1df146756 287 ADC_InitStruct->ADC_Resolution = ADC_Resolution_12b;
mbed_official 76:aeb1df146756 288
mbed_official 76:aeb1df146756 289 /* Initialize the ADC_ScanConvMode member */
mbed_official 76:aeb1df146756 290 ADC_InitStruct->ADC_ScanConvMode = DISABLE;
mbed_official 76:aeb1df146756 291
mbed_official 76:aeb1df146756 292 /* Initialize the ADC_ContinuousConvMode member */
mbed_official 76:aeb1df146756 293 ADC_InitStruct->ADC_ContinuousConvMode = DISABLE;
mbed_official 76:aeb1df146756 294
mbed_official 76:aeb1df146756 295 /* Initialize the ADC_ExternalTrigConvEdge member */
mbed_official 76:aeb1df146756 296 ADC_InitStruct->ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
mbed_official 76:aeb1df146756 297
mbed_official 76:aeb1df146756 298 /* Initialize the ADC_ExternalTrigConv member */
mbed_official 76:aeb1df146756 299 ADC_InitStruct->ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;
mbed_official 76:aeb1df146756 300
mbed_official 76:aeb1df146756 301 /* Initialize the ADC_DataAlign member */
mbed_official 76:aeb1df146756 302 ADC_InitStruct->ADC_DataAlign = ADC_DataAlign_Right;
mbed_official 76:aeb1df146756 303
mbed_official 76:aeb1df146756 304 /* Initialize the ADC_NbrOfConversion member */
mbed_official 76:aeb1df146756 305 ADC_InitStruct->ADC_NbrOfConversion = 1;
mbed_official 76:aeb1df146756 306 }
mbed_official 76:aeb1df146756 307
mbed_official 76:aeb1df146756 308 /**
mbed_official 76:aeb1df146756 309 * @brief Initializes the ADCs peripherals according to the specified parameters
mbed_official 76:aeb1df146756 310 * in the ADC_CommonInitStruct.
mbed_official 76:aeb1df146756 311 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
mbed_official 76:aeb1df146756 312 * that contains the configuration information (Prescaler) for ADC1 peripheral.
mbed_official 76:aeb1df146756 313 * @retval None
mbed_official 76:aeb1df146756 314 */
mbed_official 76:aeb1df146756 315 void ADC_CommonInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct)
mbed_official 76:aeb1df146756 316 {
mbed_official 76:aeb1df146756 317 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 318
mbed_official 76:aeb1df146756 319 /* Check the parameters */
mbed_official 76:aeb1df146756 320 assert_param(IS_ADC_PRESCALER(ADC_CommonInitStruct->ADC_Prescaler));
mbed_official 76:aeb1df146756 321
mbed_official 76:aeb1df146756 322 /*---------------------------- ADC CCR Configuration -----------------*/
mbed_official 76:aeb1df146756 323 /* Get the ADC CCR value */
mbed_official 76:aeb1df146756 324 tmpreg = ADC->CCR;
mbed_official 76:aeb1df146756 325
mbed_official 76:aeb1df146756 326 /* Clear ADCPRE bit */
mbed_official 76:aeb1df146756 327 tmpreg &= CR_CLEAR_MASK;
mbed_official 76:aeb1df146756 328
mbed_official 76:aeb1df146756 329 /* Configure ADCx: ADC prescaler according to ADC_Prescaler */
mbed_official 76:aeb1df146756 330 tmpreg |= (uint32_t)(ADC_CommonInitStruct->ADC_Prescaler);
mbed_official 76:aeb1df146756 331
mbed_official 76:aeb1df146756 332 /* Write to ADC CCR */
mbed_official 76:aeb1df146756 333 ADC->CCR = tmpreg;
mbed_official 76:aeb1df146756 334 }
mbed_official 76:aeb1df146756 335
mbed_official 76:aeb1df146756 336 /**
mbed_official 76:aeb1df146756 337 * @brief Fills each ADC_CommonInitStruct member with its default value.
mbed_official 76:aeb1df146756 338 * @param ADC_CommonInitStruct: pointer to an ADC_CommonInitTypeDef structure
mbed_official 76:aeb1df146756 339 * which will be initialized.
mbed_official 76:aeb1df146756 340 * @retval None
mbed_official 76:aeb1df146756 341 */
mbed_official 76:aeb1df146756 342 void ADC_CommonStructInit(ADC_CommonInitTypeDef* ADC_CommonInitStruct)
mbed_official 76:aeb1df146756 343 {
mbed_official 76:aeb1df146756 344 /* Reset ADC init structure parameters values */
mbed_official 76:aeb1df146756 345 /* Initialize the ADC_Prescaler member */
mbed_official 76:aeb1df146756 346 ADC_CommonInitStruct->ADC_Prescaler = ADC_Prescaler_Div1;
mbed_official 76:aeb1df146756 347 }
mbed_official 76:aeb1df146756 348
mbed_official 76:aeb1df146756 349 /**
mbed_official 76:aeb1df146756 350 * @brief Enables or disables the specified ADC peripheral.
mbed_official 76:aeb1df146756 351 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 352 * @param NewState: new state of the ADCx peripheral.
mbed_official 76:aeb1df146756 353 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 354 * @retval None
mbed_official 76:aeb1df146756 355 */
mbed_official 76:aeb1df146756 356 void ADC_Cmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 357 {
mbed_official 76:aeb1df146756 358 /* Check the parameters */
mbed_official 76:aeb1df146756 359 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 360 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 361
mbed_official 76:aeb1df146756 362 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 363 {
mbed_official 76:aeb1df146756 364 /* Set the ADON bit to wake up the ADC from power down mode */
mbed_official 76:aeb1df146756 365 ADCx->CR2 |= (uint32_t)ADC_CR2_ADON;
mbed_official 76:aeb1df146756 366 }
mbed_official 76:aeb1df146756 367 else
mbed_official 76:aeb1df146756 368 {
mbed_official 76:aeb1df146756 369 /* Disable the selected ADC peripheral */
mbed_official 76:aeb1df146756 370 ADCx->CR2 &= (uint32_t)(~ADC_CR2_ADON);
mbed_official 76:aeb1df146756 371 }
mbed_official 76:aeb1df146756 372 }
mbed_official 76:aeb1df146756 373
mbed_official 76:aeb1df146756 374 /**
mbed_official 76:aeb1df146756 375 * @brief Selects the specified ADC Channels Bank.
mbed_official 76:aeb1df146756 376 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 377 * @param ADC_Bank: ADC Channels Bank.
mbed_official 76:aeb1df146756 378 * @arg ADC_Bank_A: ADC Channels Bank A.
mbed_official 76:aeb1df146756 379 * @arg ADC_Bank_B: ADC Channels Bank B.
mbed_official 76:aeb1df146756 380 * @retval None
mbed_official 76:aeb1df146756 381 */
mbed_official 76:aeb1df146756 382 void ADC_BankSelection(ADC_TypeDef* ADCx, uint8_t ADC_Bank)
mbed_official 76:aeb1df146756 383 {
mbed_official 76:aeb1df146756 384 /* Check the parameters */
mbed_official 76:aeb1df146756 385 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 386 assert_param(IS_ADC_BANK(ADC_Bank));
mbed_official 76:aeb1df146756 387
mbed_official 76:aeb1df146756 388 if (ADC_Bank != ADC_Bank_A)
mbed_official 76:aeb1df146756 389 {
mbed_official 76:aeb1df146756 390 /* Set the ADC_CFG bit to select the ADC Bank B channels */
mbed_official 76:aeb1df146756 391 ADCx->CR2 |= (uint32_t)ADC_CR2_CFG;
mbed_official 76:aeb1df146756 392 }
mbed_official 76:aeb1df146756 393 else
mbed_official 76:aeb1df146756 394 {
mbed_official 76:aeb1df146756 395 /* Reset the ADC_CFG bit to select the ADC Bank A channels */
mbed_official 76:aeb1df146756 396 ADCx->CR2 &= (uint32_t)(~ADC_CR2_CFG);
mbed_official 76:aeb1df146756 397 }
mbed_official 76:aeb1df146756 398 }
mbed_official 76:aeb1df146756 399
mbed_official 76:aeb1df146756 400 /**
mbed_official 76:aeb1df146756 401 * @}
mbed_official 76:aeb1df146756 402 */
mbed_official 76:aeb1df146756 403
mbed_official 76:aeb1df146756 404 /** @defgroup ADC_Group2 Power saving functions
mbed_official 76:aeb1df146756 405 * @brief Power saving functions
mbed_official 76:aeb1df146756 406 *
mbed_official 76:aeb1df146756 407 @verbatim
mbed_official 76:aeb1df146756 408 ===============================================================================
mbed_official 76:aeb1df146756 409 ##### Power saving functions #####
mbed_official 76:aeb1df146756 410 ===============================================================================
mbed_official 76:aeb1df146756 411 [..] This section provides functions allowing to reduce power consumption.
mbed_official 76:aeb1df146756 412 [..] The two function must be combined to get the maximal benefits:
mbed_official 76:aeb1df146756 413 When the ADC frequency is higher than the CPU one, it is recommended to:
mbed_official 76:aeb1df146756 414 (#) Insert a freeze delay :
mbed_official 76:aeb1df146756 415 ==> using ADC_DelaySelectionConfig(ADC1, ADC_DelayLength_Freeze).
mbed_official 76:aeb1df146756 416 (#) Enable the power down in Idle and Delay phases :
mbed_official 76:aeb1df146756 417 ==> using ADC_PowerDownCmd(ADC1, ADC_PowerDown_Idle_Delay, ENABLE).
mbed_official 76:aeb1df146756 418
mbed_official 76:aeb1df146756 419 @endverbatim
mbed_official 76:aeb1df146756 420 * @{
mbed_official 76:aeb1df146756 421 */
mbed_official 76:aeb1df146756 422
mbed_official 76:aeb1df146756 423 /**
mbed_official 76:aeb1df146756 424 * @brief Enables or disables the ADC Power Down during Delay and/or Idle phase.
mbed_official 76:aeb1df146756 425 * @note ADC power-on and power-off can be managed by hardware to cut the
mbed_official 76:aeb1df146756 426 * consumption when the ADC is not converting.
mbed_official 76:aeb1df146756 427 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 428 * @param ADC_PowerDown: The ADC power down configuration.
mbed_official 76:aeb1df146756 429 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 430 * @arg ADC_PowerDown_Delay: ADC is powered down during delay phase.
mbed_official 76:aeb1df146756 431 * @arg ADC_PowerDown_Idle: ADC is powered down during Idle phase.
mbed_official 76:aeb1df146756 432 * @arg ADC_PowerDown_Idle_Delay: ADC is powered down during Delay and Idle phases.
mbed_official 76:aeb1df146756 433 * @note The ADC can be powered down:
mbed_official 76:aeb1df146756 434 * @note During the hardware delay insertion (using the ADC_PowerDown_Delay
mbed_official 76:aeb1df146756 435 * parameter).
mbed_official 76:aeb1df146756 436 * => The ADC is powered up again at the end of the delay.
mbed_official 76:aeb1df146756 437 * @note During the ADC is waiting for a trigger event ( using the
mbed_official 76:aeb1df146756 438 * ADC_PowerDown_Idle parameter).
mbed_official 76:aeb1df146756 439 * => The ADC is powered up at the next trigger event.
mbed_official 76:aeb1df146756 440 * @note During the hardware delay insertion or the ADC is waiting for a
mbed_official 76:aeb1df146756 441 * trigger event (using the ADC_PowerDown_Idle_Delay parameter).
mbed_official 76:aeb1df146756 442 * => The ADC is powered up only at the end of the delay and at the
mbed_official 76:aeb1df146756 443 * next trigger event.
mbed_official 76:aeb1df146756 444 * @param NewState: new state of the ADCx power down.
mbed_official 76:aeb1df146756 445 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 446 * @retval None
mbed_official 76:aeb1df146756 447 */
mbed_official 76:aeb1df146756 448 void ADC_PowerDownCmd(ADC_TypeDef* ADCx, uint32_t ADC_PowerDown, FunctionalState NewState)
mbed_official 76:aeb1df146756 449 {
mbed_official 76:aeb1df146756 450 /* Check the parameters */
mbed_official 76:aeb1df146756 451 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 452 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 453 assert_param(IS_ADC_POWER_DOWN(ADC_PowerDown));
mbed_official 76:aeb1df146756 454
mbed_official 76:aeb1df146756 455 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 456 {
mbed_official 76:aeb1df146756 457 /* Enable the ADC power-down during Delay and/or Idle phase */
mbed_official 76:aeb1df146756 458 ADCx->CR1 |= ADC_PowerDown;
mbed_official 76:aeb1df146756 459 }
mbed_official 76:aeb1df146756 460 else
mbed_official 76:aeb1df146756 461 {
mbed_official 76:aeb1df146756 462 /* Disable The ADC power-down during Delay and/or Idle phase */
mbed_official 76:aeb1df146756 463 ADCx->CR1 &= (uint32_t)~ADC_PowerDown;
mbed_official 76:aeb1df146756 464 }
mbed_official 76:aeb1df146756 465 }
mbed_official 76:aeb1df146756 466
mbed_official 76:aeb1df146756 467 /**
mbed_official 76:aeb1df146756 468 * @brief Defines the length of the delay which is applied after a conversion
mbed_official 76:aeb1df146756 469 * or a sequence of conversion.
mbed_official 76:aeb1df146756 470 * @note When the CPU clock is not fast enough to manage the data rate, a
mbed_official 76:aeb1df146756 471 * Hardware delay can be introduced between ADC conversions to reduce
mbed_official 76:aeb1df146756 472 * this data rate.
mbed_official 76:aeb1df146756 473 * @note The Hardware delay is inserted after :
mbed_official 76:aeb1df146756 474 * - each regular conversion.
mbed_official 76:aeb1df146756 475 * - after each sequence of injected conversions.
mbed_official 76:aeb1df146756 476 * @note No Hardware delay is inserted between conversions of different groups.
mbed_official 76:aeb1df146756 477 * @note When the hardware delay is not enough, the Freeze Delay Mode can be
mbed_official 76:aeb1df146756 478 * selected and a new conversion can start only if all the previous data
mbed_official 76:aeb1df146756 479 * of the same group have been treated:
mbed_official 76:aeb1df146756 480 * - for a regular conversion: once the ADC conversion data register has
mbed_official 76:aeb1df146756 481 * been read (using ADC_GetConversionValue() function) or if the EOC
mbed_official 76:aeb1df146756 482 * Flag has been cleared (using ADC_ClearFlag() function).
mbed_official 76:aeb1df146756 483 * - for an injected conversion: when the JEOC bit has been cleared
mbed_official 76:aeb1df146756 484 * (using ADC_ClearFlag() function).
mbed_official 76:aeb1df146756 485 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 486 * @param ADC_DelayLength: The length of delay which is applied after a
mbed_official 76:aeb1df146756 487 * conversion or a sequence of conversion.
mbed_official 76:aeb1df146756 488 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 489 * @arg ADC_DelayLength_None: No delay.
mbed_official 76:aeb1df146756 490 * @arg ADC_DelayLength_Freeze: Delay until the converted data has been read.
mbed_official 76:aeb1df146756 491 * @arg ADC_DelayLength_7Cycles: Delay length equal to 7 APB clock cycles.
mbed_official 76:aeb1df146756 492 * @arg ADC_DelayLength_15Cycles: Delay length equal to 15 APB clock cycles
mbed_official 76:aeb1df146756 493 * @arg ADC_DelayLength_31Cycles: Delay length equal to 31 APB clock cycles
mbed_official 76:aeb1df146756 494 * @arg ADC_DelayLength_63Cycles: Delay length equal to 63 APB clock cycles
mbed_official 76:aeb1df146756 495 * @arg ADC_DelayLength_127Cycles: Delay length equal to 127 APB clock cycles
mbed_official 76:aeb1df146756 496 * @arg ADC_DelayLength_255Cycles: Delay length equal to 255 APB clock cycles
mbed_official 76:aeb1df146756 497 * @retval None
mbed_official 76:aeb1df146756 498 */
mbed_official 76:aeb1df146756 499 void ADC_DelaySelectionConfig(ADC_TypeDef* ADCx, uint8_t ADC_DelayLength)
mbed_official 76:aeb1df146756 500 {
mbed_official 76:aeb1df146756 501 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 502
mbed_official 76:aeb1df146756 503 /* Check the parameters */
mbed_official 76:aeb1df146756 504 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 505 assert_param(IS_ADC_DELAY_LENGTH(ADC_DelayLength));
mbed_official 76:aeb1df146756 506
mbed_official 76:aeb1df146756 507 /* Get the old register value */
mbed_official 76:aeb1df146756 508 tmpreg = ADCx->CR2;
mbed_official 76:aeb1df146756 509 /* Clear the old delay length */
mbed_official 76:aeb1df146756 510 tmpreg &= CR2_DELS_RESET;
mbed_official 76:aeb1df146756 511 /* Set the delay length */
mbed_official 76:aeb1df146756 512 tmpreg |= ADC_DelayLength;
mbed_official 76:aeb1df146756 513 /* Store the new register value */
mbed_official 76:aeb1df146756 514 ADCx->CR2 = tmpreg;
mbed_official 76:aeb1df146756 515
mbed_official 76:aeb1df146756 516 }
mbed_official 76:aeb1df146756 517
mbed_official 76:aeb1df146756 518 /**
mbed_official 76:aeb1df146756 519 * @}
mbed_official 76:aeb1df146756 520 */
mbed_official 76:aeb1df146756 521
mbed_official 76:aeb1df146756 522 /** @defgroup ADC_Group3 Analog Watchdog configuration functions
mbed_official 76:aeb1df146756 523 * @brief Analog Watchdog configuration functions.
mbed_official 76:aeb1df146756 524 *
mbed_official 76:aeb1df146756 525 @verbatim
mbed_official 76:aeb1df146756 526 ===============================================================================
mbed_official 76:aeb1df146756 527 ##### Analog Watchdog configuration functions #####
mbed_official 76:aeb1df146756 528 ===============================================================================
mbed_official 76:aeb1df146756 529 [..] This section provides functions allowing to configure the Analog Watchdog
mbed_official 76:aeb1df146756 530 (AWD) feature in the ADC.
mbed_official 76:aeb1df146756 531 [..] A typical configuration Analog Watchdog is done following these steps :
mbed_official 76:aeb1df146756 532 (#) the ADC guarded channel(s) is (are) selected using the
mbed_official 76:aeb1df146756 533 ADC_AnalogWatchdogSingleChannelConfig() function.
mbed_official 76:aeb1df146756 534 (#) The Analog watchdog lower and higher threshold are configured using
mbed_official 76:aeb1df146756 535 the ADC_AnalogWatchdogThresholdsConfig() function.
mbed_official 76:aeb1df146756 536 (#) The Analog watchdog is enabled and configured to enable the check,
mbed_official 76:aeb1df146756 537 on one or more channels, using the ADC_AnalogWatchdogCmd() function.
mbed_official 76:aeb1df146756 538
mbed_official 76:aeb1df146756 539 @endverbatim
mbed_official 76:aeb1df146756 540 * @{
mbed_official 76:aeb1df146756 541 */
mbed_official 76:aeb1df146756 542
mbed_official 76:aeb1df146756 543 /**
mbed_official 76:aeb1df146756 544 * @brief Enables or disables the analog watchdog on single/all regular
mbed_official 76:aeb1df146756 545 * or injected channels.
mbed_official 76:aeb1df146756 546 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 547 * @param ADC_AnalogWatchdog: the ADC analog watchdog configuration.
mbed_official 76:aeb1df146756 548 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 549 * @arg ADC_AnalogWatchdog_SingleRegEnable: Analog watchdog on a single
mbed_official 76:aeb1df146756 550 * regular channel.
mbed_official 76:aeb1df146756 551 * @arg ADC_AnalogWatchdog_SingleInjecEnable: Analog watchdog on a single
mbed_official 76:aeb1df146756 552 * injected channel.
mbed_official 76:aeb1df146756 553 * @arg ADC_AnalogWatchdog_SingleRegOrInjecEnable: Analog watchdog on a
mbed_official 76:aeb1df146756 554 * single regular or injected channel.
mbed_official 76:aeb1df146756 555 * @arg ADC_AnalogWatchdog_AllRegEnable: Analog watchdog on all regular
mbed_official 76:aeb1df146756 556 * channel.
mbed_official 76:aeb1df146756 557 * @arg ADC_AnalogWatchdog_AllInjecEnable: Analog watchdog on all injected
mbed_official 76:aeb1df146756 558 * channel.
mbed_official 76:aeb1df146756 559 * @arg ADC_AnalogWatchdog_AllRegAllInjecEnable: Analog watchdog on all
mbed_official 76:aeb1df146756 560 * regular and injected channels.
mbed_official 76:aeb1df146756 561 * @arg ADC_AnalogWatchdog_None: No channel guarded by the analog watchdog.
mbed_official 76:aeb1df146756 562 * @retval None
mbed_official 76:aeb1df146756 563 */
mbed_official 76:aeb1df146756 564 void ADC_AnalogWatchdogCmd(ADC_TypeDef* ADCx, uint32_t ADC_AnalogWatchdog)
mbed_official 76:aeb1df146756 565 {
mbed_official 76:aeb1df146756 566 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 567
mbed_official 76:aeb1df146756 568 /* Check the parameters */
mbed_official 76:aeb1df146756 569 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 570 assert_param(IS_ADC_ANALOG_WATCHDOG(ADC_AnalogWatchdog));
mbed_official 76:aeb1df146756 571
mbed_official 76:aeb1df146756 572 /* Get the old register value */
mbed_official 76:aeb1df146756 573 tmpreg = ADCx->CR1;
mbed_official 76:aeb1df146756 574 /* Clear AWDEN, JAWDEN and AWDSGL bits */
mbed_official 76:aeb1df146756 575 tmpreg &= CR1_AWDMODE_RESET;
mbed_official 76:aeb1df146756 576 /* Set the analog watchdog enable mode */
mbed_official 76:aeb1df146756 577 tmpreg |= ADC_AnalogWatchdog;
mbed_official 76:aeb1df146756 578 /* Store the new register value */
mbed_official 76:aeb1df146756 579 ADCx->CR1 = tmpreg;
mbed_official 76:aeb1df146756 580 }
mbed_official 76:aeb1df146756 581
mbed_official 76:aeb1df146756 582 /**
mbed_official 76:aeb1df146756 583 * @brief Configures the high and low thresholds of the analog watchdog.
mbed_official 76:aeb1df146756 584 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 585 * @param HighThreshold: the ADC analog watchdog High threshold value.
mbed_official 76:aeb1df146756 586 * This parameter must be a 12bit value.
mbed_official 76:aeb1df146756 587 * @param LowThreshold: the ADC analog watchdog Low threshold value.
mbed_official 76:aeb1df146756 588 * This parameter must be a 12bit value.
mbed_official 76:aeb1df146756 589 * @retval None
mbed_official 76:aeb1df146756 590 */
mbed_official 76:aeb1df146756 591 void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold,
mbed_official 76:aeb1df146756 592 uint16_t LowThreshold)
mbed_official 76:aeb1df146756 593 {
mbed_official 76:aeb1df146756 594 /* Check the parameters */
mbed_official 76:aeb1df146756 595 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 596 assert_param(IS_ADC_THRESHOLD(HighThreshold));
mbed_official 76:aeb1df146756 597 assert_param(IS_ADC_THRESHOLD(LowThreshold));
mbed_official 76:aeb1df146756 598
mbed_official 76:aeb1df146756 599 /* Set the ADCx high threshold */
mbed_official 76:aeb1df146756 600 ADCx->HTR = HighThreshold;
mbed_official 76:aeb1df146756 601 /* Set the ADCx low threshold */
mbed_official 76:aeb1df146756 602 ADCx->LTR = LowThreshold;
mbed_official 76:aeb1df146756 603 }
mbed_official 76:aeb1df146756 604
mbed_official 76:aeb1df146756 605 /**
mbed_official 76:aeb1df146756 606 * @brief Configures the analog watchdog guarded single channel.
mbed_official 76:aeb1df146756 607 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 608 * @param ADC_Channel: the ADC channel to configure for the analog watchdog.
mbed_official 76:aeb1df146756 609 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 610 * @arg ADC_Channel_0: ADC Channel0 selected
mbed_official 76:aeb1df146756 611 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 76:aeb1df146756 612 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 76:aeb1df146756 613 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 76:aeb1df146756 614 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 76:aeb1df146756 615 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 76:aeb1df146756 616 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 76:aeb1df146756 617 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 76:aeb1df146756 618 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 76:aeb1df146756 619 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 76:aeb1df146756 620 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 76:aeb1df146756 621 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 76:aeb1df146756 622 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 76:aeb1df146756 623 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 76:aeb1df146756 624 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 76:aeb1df146756 625 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 76:aeb1df146756 626 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 76:aeb1df146756 627 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 76:aeb1df146756 628 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 76:aeb1df146756 629 * @arg ADC_Channel_19: ADC Channel19 selected
mbed_official 76:aeb1df146756 630 * @arg ADC_Channel_20: ADC Channel20 selected
mbed_official 76:aeb1df146756 631 * @arg ADC_Channel_21: ADC Channel21 selected
mbed_official 76:aeb1df146756 632 * @arg ADC_Channel_22: ADC Channel22 selected
mbed_official 76:aeb1df146756 633 * @arg ADC_Channel_23: ADC Channel23 selected
mbed_official 76:aeb1df146756 634 * @arg ADC_Channel_24: ADC Channel24 selected
mbed_official 76:aeb1df146756 635 * @arg ADC_Channel_25: ADC Channel25 selected
mbed_official 76:aeb1df146756 636 * @arg ADC_Channel_27: ADC Channel27 selected
mbed_official 76:aeb1df146756 637 * @arg ADC_Channel_28: ADC Channel28 selected
mbed_official 76:aeb1df146756 638 * @arg ADC_Channel_29: ADC Channel29 selected
mbed_official 76:aeb1df146756 639 * @arg ADC_Channel_30: ADC Channel30 selected
mbed_official 76:aeb1df146756 640 * @arg ADC_Channel_31: ADC Channel31 selected
mbed_official 76:aeb1df146756 641 * @arg ADC_Channel_0b: ADC Channel0b selected
mbed_official 76:aeb1df146756 642 * @arg ADC_Channel_1b: ADC Channel1b selected
mbed_official 76:aeb1df146756 643 * @arg ADC_Channel_2b: ADC Channel2b selected
mbed_official 76:aeb1df146756 644 * @arg ADC_Channel_3b: ADC Channel3b selected
mbed_official 76:aeb1df146756 645 * @arg ADC_Channel_6b: ADC Channel6b selected
mbed_official 76:aeb1df146756 646 * @arg ADC_Channel_7b: ADC Channel7b selected
mbed_official 76:aeb1df146756 647 * @arg ADC_Channel_8b: ADC Channel8b selected
mbed_official 76:aeb1df146756 648 * @arg ADC_Channel_9b: ADC Channel9b selected
mbed_official 76:aeb1df146756 649 * @arg ADC_Channel_10b: ADC Channel10b selected
mbed_official 76:aeb1df146756 650 * @arg ADC_Channel_11b: ADC Channel11b selected
mbed_official 76:aeb1df146756 651 * @arg ADC_Channel_12b: ADC Channel12b selected
mbed_official 76:aeb1df146756 652 * @retval None
mbed_official 76:aeb1df146756 653 */
mbed_official 76:aeb1df146756 654 void ADC_AnalogWatchdogSingleChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel)
mbed_official 76:aeb1df146756 655 {
mbed_official 76:aeb1df146756 656 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 657
mbed_official 76:aeb1df146756 658 /* Check the parameters */
mbed_official 76:aeb1df146756 659 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 660 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 76:aeb1df146756 661
mbed_official 76:aeb1df146756 662 /* Get the old register value */
mbed_official 76:aeb1df146756 663 tmpreg = ADCx->CR1;
mbed_official 76:aeb1df146756 664 /* Clear the Analog watchdog channel select bits */
mbed_official 76:aeb1df146756 665 tmpreg &= CR1_AWDCH_RESET;
mbed_official 76:aeb1df146756 666 /* Set the Analog watchdog channel */
mbed_official 76:aeb1df146756 667 tmpreg |= ADC_Channel;
mbed_official 76:aeb1df146756 668 /* Store the new register value */
mbed_official 76:aeb1df146756 669 ADCx->CR1 = tmpreg;
mbed_official 76:aeb1df146756 670 }
mbed_official 76:aeb1df146756 671
mbed_official 76:aeb1df146756 672 /**
mbed_official 76:aeb1df146756 673 * @}
mbed_official 76:aeb1df146756 674 */
mbed_official 76:aeb1df146756 675
mbed_official 76:aeb1df146756 676 /** @defgroup ADC_Group4 Temperature Sensor & Vrefint (Voltage Reference internal) management function
mbed_official 76:aeb1df146756 677 * @brief Temperature Sensor & Vrefint (Voltage Reference internal) management function.
mbed_official 76:aeb1df146756 678 *
mbed_official 76:aeb1df146756 679 @verbatim
mbed_official 76:aeb1df146756 680 =========================================================================================
mbed_official 76:aeb1df146756 681 ##### Temperature Sensor and Vrefint (Voltage Reference internal) management function #####
mbed_official 76:aeb1df146756 682 =========================================================================================
mbed_official 76:aeb1df146756 683 [..] This section provides a function allowing to enable/ disable the internal
mbed_official 76:aeb1df146756 684 connections between the ADC and the Temperature Sensor and the Vrefint
mbed_official 76:aeb1df146756 685 source.
mbed_official 76:aeb1df146756 686 [..] A typical configuration to get the Temperature sensor and Vrefint channels
mbed_official 76:aeb1df146756 687 voltages is done following these steps :
mbed_official 76:aeb1df146756 688 (#) Enable the internal connection of Temperature sensor and Vrefint sources
mbed_official 76:aeb1df146756 689 with the ADC channels using ADC_TempSensorVrefintCmd() function.
mbed_official 76:aeb1df146756 690 (#) select the ADC_Channel_TempSensor and/or ADC_Channel_Vrefint using
mbed_official 76:aeb1df146756 691 ADC_RegularChannelConfig() or ADC_InjectedChannelConfig() functions.
mbed_official 76:aeb1df146756 692 (#) Get the voltage values, using ADC_GetConversionValue() or
mbed_official 76:aeb1df146756 693 ADC_GetInjectedConversionValue().
mbed_official 76:aeb1df146756 694 @endverbatim
mbed_official 76:aeb1df146756 695 * @{
mbed_official 76:aeb1df146756 696 */
mbed_official 76:aeb1df146756 697
mbed_official 76:aeb1df146756 698 /**
mbed_official 76:aeb1df146756 699 * @brief Enables or disables the temperature sensor and Vrefint channel.
mbed_official 76:aeb1df146756 700 * @param NewState: new state of the temperature sensor and Vref int channels.
mbed_official 76:aeb1df146756 701 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 702 * @retval None
mbed_official 76:aeb1df146756 703 */
mbed_official 76:aeb1df146756 704 void ADC_TempSensorVrefintCmd(FunctionalState NewState)
mbed_official 76:aeb1df146756 705 {
mbed_official 76:aeb1df146756 706 /* Check the parameters */
mbed_official 76:aeb1df146756 707 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 708
mbed_official 76:aeb1df146756 709 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 710 {
mbed_official 76:aeb1df146756 711 /* Enable the temperature sensor and Vrefint channel*/
mbed_official 76:aeb1df146756 712 ADC->CCR |= (uint32_t)ADC_CCR_TSVREFE;
mbed_official 76:aeb1df146756 713 }
mbed_official 76:aeb1df146756 714 else
mbed_official 76:aeb1df146756 715 {
mbed_official 76:aeb1df146756 716 /* Disable the temperature sensor and Vrefint channel*/
mbed_official 76:aeb1df146756 717 ADC->CCR &= (uint32_t)(~ADC_CCR_TSVREFE);
mbed_official 76:aeb1df146756 718 }
mbed_official 76:aeb1df146756 719 }
mbed_official 76:aeb1df146756 720
mbed_official 76:aeb1df146756 721 /**
mbed_official 76:aeb1df146756 722 * @}
mbed_official 76:aeb1df146756 723 */
mbed_official 76:aeb1df146756 724
mbed_official 76:aeb1df146756 725 /** @defgroup ADC_Group5 Regular Channels Configuration functions
mbed_official 76:aeb1df146756 726 * @brief Regular Channels Configuration functions.
mbed_official 76:aeb1df146756 727 *
mbed_official 76:aeb1df146756 728 @verbatim
mbed_official 76:aeb1df146756 729 ===============================================================================
mbed_official 76:aeb1df146756 730 ##### Regular Channels Configuration functions #####
mbed_official 76:aeb1df146756 731 ===============================================================================
mbed_official 76:aeb1df146756 732 [..] This section provides functions allowing to manage the ADC regular channels,
mbed_official 76:aeb1df146756 733 it is composed of 2 sub sections :
mbed_official 76:aeb1df146756 734 (#) Configuration and management functions for regular channels: This
mbed_official 76:aeb1df146756 735 subsection provides functions allowing to configure the ADC regular
mbed_official 76:aeb1df146756 736 channels :
mbed_official 76:aeb1df146756 737 (++) Configure the rank in the regular group sequencer for each channel.
mbed_official 76:aeb1df146756 738 (++) Configure the sampling time for each channel.
mbed_official 76:aeb1df146756 739 (++) select the conversion Trigger for regular channels.
mbed_official 76:aeb1df146756 740 (++) select the desired EOC event behavior configuration.
mbed_official 76:aeb1df146756 741 (++) Activate the continuous Mode (*).
mbed_official 76:aeb1df146756 742 (++) Activate the Discontinuous Mode.
mbed_official 76:aeb1df146756 743 -@@- Please Note that the following features for regular channels are
mbed_official 76:aeb1df146756 744 configurated using the ADC_Init() function :
mbed_official 76:aeb1df146756 745 (+@@) scan mode activation.
mbed_official 76:aeb1df146756 746 (+@@) continuous mode activation (**).
mbed_official 76:aeb1df146756 747 (+@@) External trigger source.
mbed_official 76:aeb1df146756 748 (+@@) External trigger edge.
mbed_official 76:aeb1df146756 749 (+@@) number of conversion in the regular channels group sequencer.
mbed_official 76:aeb1df146756 750 -@@- (*) and (**) are performing the same configuration.
mbed_official 76:aeb1df146756 751 (#) Get the conversion data: This subsection provides an important function
mbed_official 76:aeb1df146756 752 in the ADC peripheral since it returns the converted data of the current
mbed_official 76:aeb1df146756 753 regular channel. When the Conversion value is read, the EOC Flag is
mbed_official 76:aeb1df146756 754 automatically cleared.
mbed_official 76:aeb1df146756 755 @endverbatim
mbed_official 76:aeb1df146756 756 * @{
mbed_official 76:aeb1df146756 757 */
mbed_official 76:aeb1df146756 758
mbed_official 76:aeb1df146756 759 /**
mbed_official 76:aeb1df146756 760 * @brief Configures for the selected ADC regular channel its corresponding
mbed_official 76:aeb1df146756 761 * rank in the sequencer and its sampling time.
mbed_official 76:aeb1df146756 762 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 76:aeb1df146756 763 * @param ADC_Channel: the ADC channel to configure.
mbed_official 76:aeb1df146756 764 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 765 * @arg ADC_Channel_0: ADC Channel0 selected
mbed_official 76:aeb1df146756 766 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 76:aeb1df146756 767 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 76:aeb1df146756 768 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 76:aeb1df146756 769 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 76:aeb1df146756 770 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 76:aeb1df146756 771 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 76:aeb1df146756 772 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 76:aeb1df146756 773 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 76:aeb1df146756 774 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 76:aeb1df146756 775 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 76:aeb1df146756 776 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 76:aeb1df146756 777 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 76:aeb1df146756 778 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 76:aeb1df146756 779 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 76:aeb1df146756 780 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 76:aeb1df146756 781 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 76:aeb1df146756 782 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 76:aeb1df146756 783 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 76:aeb1df146756 784 * @arg ADC_Channel_19: ADC Channel19 selected
mbed_official 76:aeb1df146756 785 * @arg ADC_Channel_20: ADC Channel20 selected
mbed_official 76:aeb1df146756 786 * @arg ADC_Channel_21: ADC Channel21 selected
mbed_official 76:aeb1df146756 787 * @arg ADC_Channel_22: ADC Channel22 selected
mbed_official 76:aeb1df146756 788 * @arg ADC_Channel_23: ADC Channel23 selected
mbed_official 76:aeb1df146756 789 * @arg ADC_Channel_24: ADC Channel24 selected
mbed_official 76:aeb1df146756 790 * @arg ADC_Channel_25: ADC Channel25 selected
mbed_official 76:aeb1df146756 791 * @arg ADC_Channel_27: ADC Channel27 selected
mbed_official 76:aeb1df146756 792 * @arg ADC_Channel_28: ADC Channel28 selected
mbed_official 76:aeb1df146756 793 * @arg ADC_Channel_29: ADC Channel29 selected
mbed_official 76:aeb1df146756 794 * @arg ADC_Channel_30: ADC Channel30 selected
mbed_official 76:aeb1df146756 795 * @arg ADC_Channel_31: ADC Channel31 selected
mbed_official 76:aeb1df146756 796 * @arg ADC_Channel_0b: ADC Channel0b selected
mbed_official 76:aeb1df146756 797 * @arg ADC_Channel_1b: ADC Channel1b selected
mbed_official 76:aeb1df146756 798 * @arg ADC_Channel_2b: ADC Channel2b selected
mbed_official 76:aeb1df146756 799 * @arg ADC_Channel_3b: ADC Channel3b selected
mbed_official 76:aeb1df146756 800 * @arg ADC_Channel_6b: ADC Channel6b selected
mbed_official 76:aeb1df146756 801 * @arg ADC_Channel_7b: ADC Channel7b selected
mbed_official 76:aeb1df146756 802 * @arg ADC_Channel_8b: ADC Channel8b selected
mbed_official 76:aeb1df146756 803 * @arg ADC_Channel_9b: ADC Channel9b selected
mbed_official 76:aeb1df146756 804 * @arg ADC_Channel_10b: ADC Channel10b selected
mbed_official 76:aeb1df146756 805 * @arg ADC_Channel_11b: ADC Channel11b selected
mbed_official 76:aeb1df146756 806 * @arg ADC_Channel_12b: ADC Channel12b selected
mbed_official 76:aeb1df146756 807 * @param Rank: The rank in the regular group sequencer. This parameter
mbed_official 76:aeb1df146756 808 * must be between 1 to 28.
mbed_official 76:aeb1df146756 809 * @param ADC_SampleTime: The sample time value to be set for the selected
mbed_official 76:aeb1df146756 810 * channel.
mbed_official 76:aeb1df146756 811 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 812 * @arg ADC_SampleTime_4Cycles: Sample time equal to 4 cycles
mbed_official 76:aeb1df146756 813 * @arg ADC_SampleTime_9Cycles: Sample time equal to 9 cycles
mbed_official 76:aeb1df146756 814 * @arg ADC_SampleTime_16Cycles: Sample time equal to 16 cycles
mbed_official 76:aeb1df146756 815 * @arg ADC_SampleTime_24Cycles: Sample time equal to 24 cycles
mbed_official 76:aeb1df146756 816 * @arg ADC_SampleTime_48Cycles: Sample time equal to 48 cycles
mbed_official 76:aeb1df146756 817 * @arg ADC_SampleTime_96Cycles: Sample time equal to 96 cycles
mbed_official 76:aeb1df146756 818 * @arg ADC_SampleTime_192Cycles: Sample time equal to 192 cycles
mbed_official 76:aeb1df146756 819 * @arg ADC_SampleTime_384Cycles: Sample time equal to 384 cycles
mbed_official 76:aeb1df146756 820 * @retval None
mbed_official 76:aeb1df146756 821 */
mbed_official 76:aeb1df146756 822 void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
mbed_official 76:aeb1df146756 823 {
mbed_official 76:aeb1df146756 824 uint32_t tmpreg1 = 0, tmpreg2 = 0;
mbed_official 76:aeb1df146756 825
mbed_official 76:aeb1df146756 826 /* Check the parameters */
mbed_official 76:aeb1df146756 827 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 828 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 76:aeb1df146756 829 assert_param(IS_ADC_REGULAR_RANK(Rank));
mbed_official 76:aeb1df146756 830 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
mbed_official 76:aeb1df146756 831
mbed_official 76:aeb1df146756 832 /* If ADC_Channel_30 or ADC_Channel_31 is selected */
mbed_official 76:aeb1df146756 833 if (ADC_Channel > ADC_Channel_29)
mbed_official 76:aeb1df146756 834 {
mbed_official 76:aeb1df146756 835 /* Get the old register value */
mbed_official 76:aeb1df146756 836 tmpreg1 = ADCx->SMPR0;
mbed_official 76:aeb1df146756 837 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 838 tmpreg2 = SMPR0_SMP_SET << (3 * (ADC_Channel - 30));
mbed_official 76:aeb1df146756 839 /* Clear the old sample time */
mbed_official 76:aeb1df146756 840 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 841 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 842 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 30));
mbed_official 76:aeb1df146756 843 /* Set the new sample time */
mbed_official 76:aeb1df146756 844 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 845 /* Store the new register value */
mbed_official 76:aeb1df146756 846 ADCx->SMPR0 = tmpreg1;
mbed_official 76:aeb1df146756 847 }
mbed_official 76:aeb1df146756 848 /* If ADC_Channel_20 ... ADC_Channel_29 is selected */
mbed_official 76:aeb1df146756 849 else if (ADC_Channel > ADC_Channel_19)
mbed_official 76:aeb1df146756 850 {
mbed_official 76:aeb1df146756 851 /* Get the old register value */
mbed_official 76:aeb1df146756 852 tmpreg1 = ADCx->SMPR1;
mbed_official 76:aeb1df146756 853 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 854 tmpreg2 = SMPR1_SMP_SET << (3 * (ADC_Channel - 20));
mbed_official 76:aeb1df146756 855 /* Clear the old sample time */
mbed_official 76:aeb1df146756 856 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 857 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 858 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 20));
mbed_official 76:aeb1df146756 859 /* Set the new sample time */
mbed_official 76:aeb1df146756 860 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 861 /* Store the new register value */
mbed_official 76:aeb1df146756 862 ADCx->SMPR1 = tmpreg1;
mbed_official 76:aeb1df146756 863 }
mbed_official 76:aeb1df146756 864 /* If ADC_Channel_10 ... ADC_Channel_19 is selected */
mbed_official 76:aeb1df146756 865 else if (ADC_Channel > ADC_Channel_9)
mbed_official 76:aeb1df146756 866 {
mbed_official 76:aeb1df146756 867 /* Get the old register value */
mbed_official 76:aeb1df146756 868 tmpreg1 = ADCx->SMPR2;
mbed_official 76:aeb1df146756 869 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 870 tmpreg2 = SMPR2_SMP_SET << (3 * (ADC_Channel - 10));
mbed_official 76:aeb1df146756 871 /* Clear the old sample time */
mbed_official 76:aeb1df146756 872 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 873 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 874 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
mbed_official 76:aeb1df146756 875 /* Set the new sample time */
mbed_official 76:aeb1df146756 876 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 877 /* Store the new register value */
mbed_official 76:aeb1df146756 878 ADCx->SMPR2 = tmpreg1;
mbed_official 76:aeb1df146756 879 }
mbed_official 76:aeb1df146756 880 else /* ADC_Channel include in ADC_Channel_[0..9] */
mbed_official 76:aeb1df146756 881 {
mbed_official 76:aeb1df146756 882 /* Get the old register value */
mbed_official 76:aeb1df146756 883 tmpreg1 = ADCx->SMPR3;
mbed_official 76:aeb1df146756 884 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 885 tmpreg2 = SMPR3_SMP_SET << (3 * ADC_Channel);
mbed_official 76:aeb1df146756 886 /* Clear the old sample time */
mbed_official 76:aeb1df146756 887 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 888 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 889 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
mbed_official 76:aeb1df146756 890 /* Set the new sample time */
mbed_official 76:aeb1df146756 891 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 892 /* Store the new register value */
mbed_official 76:aeb1df146756 893 ADCx->SMPR3 = tmpreg1;
mbed_official 76:aeb1df146756 894 }
mbed_official 76:aeb1df146756 895 /* For Rank 1 to 6 */
mbed_official 76:aeb1df146756 896 if (Rank < 7)
mbed_official 76:aeb1df146756 897 {
mbed_official 76:aeb1df146756 898 /* Get the old register value */
mbed_official 76:aeb1df146756 899 tmpreg1 = ADCx->SQR5;
mbed_official 76:aeb1df146756 900 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 901 tmpreg2 = SQR5_SQ_SET << (5 * (Rank - 1));
mbed_official 76:aeb1df146756 902 /* Clear the old SQx bits for the selected rank */
mbed_official 76:aeb1df146756 903 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 904 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 905 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 1));
mbed_official 76:aeb1df146756 906 /* Set the SQx bits for the selected rank */
mbed_official 76:aeb1df146756 907 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 908 /* Store the new register value */
mbed_official 76:aeb1df146756 909 ADCx->SQR5 = tmpreg1;
mbed_official 76:aeb1df146756 910 }
mbed_official 76:aeb1df146756 911 /* For Rank 7 to 12 */
mbed_official 76:aeb1df146756 912 else if (Rank < 13)
mbed_official 76:aeb1df146756 913 {
mbed_official 76:aeb1df146756 914 /* Get the old register value */
mbed_official 76:aeb1df146756 915 tmpreg1 = ADCx->SQR4;
mbed_official 76:aeb1df146756 916 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 917 tmpreg2 = SQR4_SQ_SET << (5 * (Rank - 7));
mbed_official 76:aeb1df146756 918 /* Clear the old SQx bits for the selected rank */
mbed_official 76:aeb1df146756 919 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 920 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 921 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 7));
mbed_official 76:aeb1df146756 922 /* Set the SQx bits for the selected rank */
mbed_official 76:aeb1df146756 923 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 924 /* Store the new register value */
mbed_official 76:aeb1df146756 925 ADCx->SQR4 = tmpreg1;
mbed_official 76:aeb1df146756 926 }
mbed_official 76:aeb1df146756 927 /* For Rank 13 to 18 */
mbed_official 76:aeb1df146756 928 else if (Rank < 19)
mbed_official 76:aeb1df146756 929 {
mbed_official 76:aeb1df146756 930 /* Get the old register value */
mbed_official 76:aeb1df146756 931 tmpreg1 = ADCx->SQR3;
mbed_official 76:aeb1df146756 932 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 933 tmpreg2 = SQR3_SQ_SET << (5 * (Rank - 13));
mbed_official 76:aeb1df146756 934 /* Clear the old SQx bits for the selected rank */
mbed_official 76:aeb1df146756 935 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 936 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 937 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 13));
mbed_official 76:aeb1df146756 938 /* Set the SQx bits for the selected rank */
mbed_official 76:aeb1df146756 939 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 940 /* Store the new register value */
mbed_official 76:aeb1df146756 941 ADCx->SQR3 = tmpreg1;
mbed_official 76:aeb1df146756 942 }
mbed_official 76:aeb1df146756 943
mbed_official 76:aeb1df146756 944 /* For Rank 19 to 24 */
mbed_official 76:aeb1df146756 945 else if (Rank < 25)
mbed_official 76:aeb1df146756 946 {
mbed_official 76:aeb1df146756 947 /* Get the old register value */
mbed_official 76:aeb1df146756 948 tmpreg1 = ADCx->SQR2;
mbed_official 76:aeb1df146756 949 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 950 tmpreg2 = SQR2_SQ_SET << (5 * (Rank - 19));
mbed_official 76:aeb1df146756 951 /* Clear the old SQx bits for the selected rank */
mbed_official 76:aeb1df146756 952 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 953 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 954 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 19));
mbed_official 76:aeb1df146756 955 /* Set the SQx bits for the selected rank */
mbed_official 76:aeb1df146756 956 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 957 /* Store the new register value */
mbed_official 76:aeb1df146756 958 ADCx->SQR2 = tmpreg1;
mbed_official 76:aeb1df146756 959 }
mbed_official 76:aeb1df146756 960
mbed_official 76:aeb1df146756 961 /* For Rank 25 to 28 */
mbed_official 76:aeb1df146756 962 else
mbed_official 76:aeb1df146756 963 {
mbed_official 76:aeb1df146756 964 /* Get the old register value */
mbed_official 76:aeb1df146756 965 tmpreg1 = ADCx->SQR1;
mbed_official 76:aeb1df146756 966 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 967 tmpreg2 = SQR1_SQ_SET << (5 * (Rank - 25));
mbed_official 76:aeb1df146756 968 /* Clear the old SQx bits for the selected rank */
mbed_official 76:aeb1df146756 969 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 970 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 971 tmpreg2 = (uint32_t)ADC_Channel << (5 * (Rank - 25));
mbed_official 76:aeb1df146756 972 /* Set the SQx bits for the selected rank */
mbed_official 76:aeb1df146756 973 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 974 /* Store the new register value */
mbed_official 76:aeb1df146756 975 ADCx->SQR1 = tmpreg1;
mbed_official 76:aeb1df146756 976 }
mbed_official 76:aeb1df146756 977 }
mbed_official 76:aeb1df146756 978
mbed_official 76:aeb1df146756 979 /**
mbed_official 76:aeb1df146756 980 * @brief Enables the selected ADC software start conversion of the regular channels.
mbed_official 76:aeb1df146756 981 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 982 * @retval None
mbed_official 76:aeb1df146756 983 */
mbed_official 76:aeb1df146756 984 void ADC_SoftwareStartConv(ADC_TypeDef* ADCx)
mbed_official 76:aeb1df146756 985 {
mbed_official 76:aeb1df146756 986 /* Check the parameters */
mbed_official 76:aeb1df146756 987 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 988
mbed_official 76:aeb1df146756 989 /* Enable the selected ADC conversion for regular group */
mbed_official 76:aeb1df146756 990 ADCx->CR2 |= (uint32_t)ADC_CR2_SWSTART;
mbed_official 76:aeb1df146756 991 }
mbed_official 76:aeb1df146756 992
mbed_official 76:aeb1df146756 993 /**
mbed_official 76:aeb1df146756 994 * @brief Gets the selected ADC Software start regular conversion Status.
mbed_official 76:aeb1df146756 995 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 996 * @retval The new state of ADC software start conversion (SET or RESET).
mbed_official 76:aeb1df146756 997 */
mbed_official 76:aeb1df146756 998 FlagStatus ADC_GetSoftwareStartConvStatus(ADC_TypeDef* ADCx)
mbed_official 76:aeb1df146756 999 {
mbed_official 76:aeb1df146756 1000 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1001
mbed_official 76:aeb1df146756 1002 /* Check the parameters */
mbed_official 76:aeb1df146756 1003 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1004
mbed_official 76:aeb1df146756 1005 /* Check the status of SWSTART bit */
mbed_official 76:aeb1df146756 1006 if ((ADCx->CR2 & ADC_CR2_SWSTART) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 1007 {
mbed_official 76:aeb1df146756 1008 /* SWSTART bit is set */
mbed_official 76:aeb1df146756 1009 bitstatus = SET;
mbed_official 76:aeb1df146756 1010 }
mbed_official 76:aeb1df146756 1011 else
mbed_official 76:aeb1df146756 1012 {
mbed_official 76:aeb1df146756 1013 /* SWSTART bit is reset */
mbed_official 76:aeb1df146756 1014 bitstatus = RESET;
mbed_official 76:aeb1df146756 1015 }
mbed_official 76:aeb1df146756 1016 /* Return the SWSTART bit status */
mbed_official 76:aeb1df146756 1017 return bitstatus;
mbed_official 76:aeb1df146756 1018 }
mbed_official 76:aeb1df146756 1019
mbed_official 76:aeb1df146756 1020 /**
mbed_official 76:aeb1df146756 1021 * @brief Enables or disables the EOC on each regular channel conversion.
mbed_official 76:aeb1df146756 1022 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1023 * @param NewState: new state of the selected ADC EOC flag rising
mbed_official 76:aeb1df146756 1024 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1025 * @retval None
mbed_official 76:aeb1df146756 1026 */
mbed_official 76:aeb1df146756 1027 void ADC_EOCOnEachRegularChannelCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1028 {
mbed_official 76:aeb1df146756 1029 /* Check the parameters */
mbed_official 76:aeb1df146756 1030 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1031 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1032
mbed_official 76:aeb1df146756 1033 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1034 {
mbed_official 76:aeb1df146756 1035 /* Enable the selected ADC EOC rising on each regular channel conversion */
mbed_official 76:aeb1df146756 1036 ADCx->CR2 |= ADC_CR2_EOCS;
mbed_official 76:aeb1df146756 1037 }
mbed_official 76:aeb1df146756 1038 else
mbed_official 76:aeb1df146756 1039 {
mbed_official 76:aeb1df146756 1040 /* Disable the selected ADC EOC rising on each regular channel conversion */
mbed_official 76:aeb1df146756 1041 ADCx->CR2 &= (uint32_t)~ADC_CR2_EOCS;
mbed_official 76:aeb1df146756 1042 }
mbed_official 76:aeb1df146756 1043 }
mbed_official 76:aeb1df146756 1044
mbed_official 76:aeb1df146756 1045 /**
mbed_official 76:aeb1df146756 1046 * @brief Enables or disables the ADC continuous conversion mode.
mbed_official 76:aeb1df146756 1047 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1048 * @param NewState: new state of the selected ADC continuous conversion mode.
mbed_official 76:aeb1df146756 1049 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1050 * @retval None
mbed_official 76:aeb1df146756 1051 */
mbed_official 76:aeb1df146756 1052 void ADC_ContinuousModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1053 {
mbed_official 76:aeb1df146756 1054 /* Check the parameters */
mbed_official 76:aeb1df146756 1055 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1056 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1057
mbed_official 76:aeb1df146756 1058 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1059 {
mbed_official 76:aeb1df146756 1060 /* Enable the selected ADC continuous conversion mode */
mbed_official 76:aeb1df146756 1061 ADCx->CR2 |= (uint32_t)ADC_CR2_CONT;
mbed_official 76:aeb1df146756 1062 }
mbed_official 76:aeb1df146756 1063 else
mbed_official 76:aeb1df146756 1064 {
mbed_official 76:aeb1df146756 1065 /* Disable the selected ADC continuous conversion mode */
mbed_official 76:aeb1df146756 1066 ADCx->CR2 &= (uint32_t)(~ADC_CR2_CONT);
mbed_official 76:aeb1df146756 1067 }
mbed_official 76:aeb1df146756 1068 }
mbed_official 76:aeb1df146756 1069
mbed_official 76:aeb1df146756 1070 /**
mbed_official 76:aeb1df146756 1071 * @brief Configures the discontinuous mode for the selected ADC regular
mbed_official 76:aeb1df146756 1072 * group channel.
mbed_official 76:aeb1df146756 1073 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1074 * @param Number: specifies the discontinuous mode regular channel count value.
mbed_official 76:aeb1df146756 1075 * This number must be between 1 and 8.
mbed_official 76:aeb1df146756 1076 * @retval None
mbed_official 76:aeb1df146756 1077 */
mbed_official 76:aeb1df146756 1078 void ADC_DiscModeChannelCountConfig(ADC_TypeDef* ADCx, uint8_t Number)
mbed_official 76:aeb1df146756 1079 {
mbed_official 76:aeb1df146756 1080 uint32_t tmpreg1 = 0;
mbed_official 76:aeb1df146756 1081 uint32_t tmpreg2 = 0;
mbed_official 76:aeb1df146756 1082
mbed_official 76:aeb1df146756 1083 /* Check the parameters */
mbed_official 76:aeb1df146756 1084 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1085 assert_param(IS_ADC_REGULAR_DISC_NUMBER(Number));
mbed_official 76:aeb1df146756 1086
mbed_official 76:aeb1df146756 1087 /* Get the old register value */
mbed_official 76:aeb1df146756 1088 tmpreg1 = ADCx->CR1;
mbed_official 76:aeb1df146756 1089 /* Clear the old discontinuous mode channel count */
mbed_official 76:aeb1df146756 1090 tmpreg1 &= CR1_DISCNUM_RESET;
mbed_official 76:aeb1df146756 1091 /* Set the discontinuous mode channel count */
mbed_official 76:aeb1df146756 1092 tmpreg2 = Number - 1;
mbed_official 76:aeb1df146756 1093 tmpreg1 |= tmpreg2 << 13;
mbed_official 76:aeb1df146756 1094 /* Store the new register value */
mbed_official 76:aeb1df146756 1095 ADCx->CR1 = tmpreg1;
mbed_official 76:aeb1df146756 1096 }
mbed_official 76:aeb1df146756 1097
mbed_official 76:aeb1df146756 1098 /**
mbed_official 76:aeb1df146756 1099 * @brief Enables or disables the discontinuous mode on regular group
mbed_official 76:aeb1df146756 1100 * channel for the specified ADC.
mbed_official 76:aeb1df146756 1101 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1102 * @param NewState: new state of the selected ADC discontinuous mode on regular
mbed_official 76:aeb1df146756 1103 * group channel.
mbed_official 76:aeb1df146756 1104 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1105 * @retval None
mbed_official 76:aeb1df146756 1106 */
mbed_official 76:aeb1df146756 1107 void ADC_DiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1108 {
mbed_official 76:aeb1df146756 1109 /* Check the parameters */
mbed_official 76:aeb1df146756 1110 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1111 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1112
mbed_official 76:aeb1df146756 1113 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1114 {
mbed_official 76:aeb1df146756 1115 /* Enable the selected ADC regular discontinuous mode */
mbed_official 76:aeb1df146756 1116 ADCx->CR1 |= (uint32_t)ADC_CR1_DISCEN;
mbed_official 76:aeb1df146756 1117 }
mbed_official 76:aeb1df146756 1118 else
mbed_official 76:aeb1df146756 1119 {
mbed_official 76:aeb1df146756 1120 /* Disable the selected ADC regular discontinuous mode */
mbed_official 76:aeb1df146756 1121 ADCx->CR1 &= (uint32_t)(~ADC_CR1_DISCEN);
mbed_official 76:aeb1df146756 1122 }
mbed_official 76:aeb1df146756 1123 }
mbed_official 76:aeb1df146756 1124
mbed_official 76:aeb1df146756 1125 /**
mbed_official 76:aeb1df146756 1126 * @brief Returns the last ADCx conversion result data for regular channel.
mbed_official 76:aeb1df146756 1127 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1128 * @retval The Data conversion value.
mbed_official 76:aeb1df146756 1129 */
mbed_official 76:aeb1df146756 1130 uint16_t ADC_GetConversionValue(ADC_TypeDef* ADCx)
mbed_official 76:aeb1df146756 1131 {
mbed_official 76:aeb1df146756 1132 /* Check the parameters */
mbed_official 76:aeb1df146756 1133 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1134
mbed_official 76:aeb1df146756 1135 /* Return the selected ADC conversion value */
mbed_official 76:aeb1df146756 1136 return (uint16_t) ADCx->DR;
mbed_official 76:aeb1df146756 1137 }
mbed_official 76:aeb1df146756 1138
mbed_official 76:aeb1df146756 1139 /**
mbed_official 76:aeb1df146756 1140 * @}
mbed_official 76:aeb1df146756 1141 */
mbed_official 76:aeb1df146756 1142
mbed_official 76:aeb1df146756 1143 /** @defgroup ADC_Group6 Regular Channels DMA Configuration functions
mbed_official 76:aeb1df146756 1144 * @brief Regular Channels DMA Configuration functions.
mbed_official 76:aeb1df146756 1145 *
mbed_official 76:aeb1df146756 1146 @verbatim
mbed_official 76:aeb1df146756 1147 ===============================================================================
mbed_official 76:aeb1df146756 1148 ##### Regular Channels DMA Configuration functions #####
mbed_official 76:aeb1df146756 1149 ===============================================================================
mbed_official 76:aeb1df146756 1150 [..] This section provides functions allowing to configure the DMA for ADC regular
mbed_official 76:aeb1df146756 1151 channels.Since converted regular channel values are stored into a unique
mbed_official 76:aeb1df146756 1152 data register, it is useful to use DMA for conversion of more than one
mbed_official 76:aeb1df146756 1153 regular channel. This avoids the loss of the data already stored in the
mbed_official 76:aeb1df146756 1154 ADC Data register.
mbed_official 76:aeb1df146756 1155 When the DMA mode is enabled (using the ADC_DMACmd() function), after each
mbed_official 76:aeb1df146756 1156 conversion of a regular channel, a DMA request is generated.
mbed_official 76:aeb1df146756 1157 [..] Depending on the "DMA disable selection" configuration (using the
mbed_official 76:aeb1df146756 1158 ADC_DMARequestAfterLastTransferCmd() function), at the end of the last DMA
mbed_official 76:aeb1df146756 1159 transfer, two possibilities are allowed:
mbed_official 76:aeb1df146756 1160 (+) No new DMA request is issued to the DMA controller (feature DISABLED).
mbed_official 76:aeb1df146756 1161 (+) Requests can continue to be generated (feature ENABLED).
mbed_official 76:aeb1df146756 1162
mbed_official 76:aeb1df146756 1163 @endverbatim
mbed_official 76:aeb1df146756 1164 * @{
mbed_official 76:aeb1df146756 1165 */
mbed_official 76:aeb1df146756 1166
mbed_official 76:aeb1df146756 1167 /**
mbed_official 76:aeb1df146756 1168 * @brief Enables or disables the specified ADC DMA request.
mbed_official 76:aeb1df146756 1169 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1170 * @param NewState: new state of the selected ADC DMA transfer.
mbed_official 76:aeb1df146756 1171 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1172 * @retval None
mbed_official 76:aeb1df146756 1173 */
mbed_official 76:aeb1df146756 1174 void ADC_DMACmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1175 {
mbed_official 76:aeb1df146756 1176 /* Check the parameters */
mbed_official 76:aeb1df146756 1177 assert_param(IS_ADC_DMA_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1178 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1179
mbed_official 76:aeb1df146756 1180 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1181 {
mbed_official 76:aeb1df146756 1182 /* Enable the selected ADC DMA request */
mbed_official 76:aeb1df146756 1183 ADCx->CR2 |= (uint32_t)ADC_CR2_DMA;
mbed_official 76:aeb1df146756 1184 }
mbed_official 76:aeb1df146756 1185 else
mbed_official 76:aeb1df146756 1186 {
mbed_official 76:aeb1df146756 1187 /* Disable the selected ADC DMA request */
mbed_official 76:aeb1df146756 1188 ADCx->CR2 &= (uint32_t)(~ADC_CR2_DMA);
mbed_official 76:aeb1df146756 1189 }
mbed_official 76:aeb1df146756 1190 }
mbed_official 76:aeb1df146756 1191
mbed_official 76:aeb1df146756 1192
mbed_official 76:aeb1df146756 1193 /**
mbed_official 76:aeb1df146756 1194 * @brief Enables or disables the ADC DMA request after last transfer (Single-ADC mode).
mbed_official 76:aeb1df146756 1195 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1196 * @param NewState: new state of the selected ADC EOC flag rising
mbed_official 76:aeb1df146756 1197 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1198 * @retval None
mbed_official 76:aeb1df146756 1199 */
mbed_official 76:aeb1df146756 1200 void ADC_DMARequestAfterLastTransferCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1201 {
mbed_official 76:aeb1df146756 1202 /* Check the parameters */
mbed_official 76:aeb1df146756 1203 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1204 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1205
mbed_official 76:aeb1df146756 1206 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1207 {
mbed_official 76:aeb1df146756 1208 /* Enable the selected ADC DMA request after last transfer */
mbed_official 76:aeb1df146756 1209 ADCx->CR2 |= ADC_CR2_DDS;
mbed_official 76:aeb1df146756 1210 }
mbed_official 76:aeb1df146756 1211 else
mbed_official 76:aeb1df146756 1212 {
mbed_official 76:aeb1df146756 1213 /* Disable the selected ADC DMA request after last transfer */
mbed_official 76:aeb1df146756 1214 ADCx->CR2 &= (uint32_t)~ADC_CR2_DDS;
mbed_official 76:aeb1df146756 1215 }
mbed_official 76:aeb1df146756 1216 }
mbed_official 76:aeb1df146756 1217
mbed_official 76:aeb1df146756 1218 /**
mbed_official 76:aeb1df146756 1219 * @}
mbed_official 76:aeb1df146756 1220 */
mbed_official 76:aeb1df146756 1221
mbed_official 76:aeb1df146756 1222 /** @defgroup ADC_Group7 Injected channels Configuration functions
mbed_official 76:aeb1df146756 1223 * @brief Injected channels Configuration functions.
mbed_official 76:aeb1df146756 1224 *
mbed_official 76:aeb1df146756 1225 @verbatim
mbed_official 76:aeb1df146756 1226 ===============================================================================
mbed_official 76:aeb1df146756 1227 ##### Injected channels Configuration functions #####
mbed_official 76:aeb1df146756 1228 ===============================================================================
mbed_official 76:aeb1df146756 1229 [..] This section provide functions allowing to configure the ADC Injected channels,
mbed_official 76:aeb1df146756 1230 it is composed of 2 sub sections :
mbed_official 76:aeb1df146756 1231 (#) Configuration functions for Injected channels: This subsection provides
mbed_official 76:aeb1df146756 1232 functions allowing to configure the ADC injected channels :
mbed_official 76:aeb1df146756 1233 (++) Configure the rank in the injected group sequencer for each channel.
mbed_official 76:aeb1df146756 1234 (++) Configure the sampling time for each channel.
mbed_official 76:aeb1df146756 1235 (++) Activate the Auto injected Mode.
mbed_official 76:aeb1df146756 1236 (++) Activate the Discontinuous Mode.
mbed_official 76:aeb1df146756 1237 (++) scan mode activation.
mbed_official 76:aeb1df146756 1238 (++) External/software trigger source.
mbed_official 76:aeb1df146756 1239 (++) External trigger edge.
mbed_official 76:aeb1df146756 1240 (++) injected channels sequencer.
mbed_official 76:aeb1df146756 1241
mbed_official 76:aeb1df146756 1242 (#) Get the Specified Injected channel conversion data: This subsection
mbed_official 76:aeb1df146756 1243 provides an important function in the ADC peripheral since it returns
mbed_official 76:aeb1df146756 1244 the converted data of the specific injected channel.
mbed_official 76:aeb1df146756 1245
mbed_official 76:aeb1df146756 1246 @endverbatim
mbed_official 76:aeb1df146756 1247 * @{
mbed_official 76:aeb1df146756 1248 */
mbed_official 76:aeb1df146756 1249
mbed_official 76:aeb1df146756 1250 /**
mbed_official 76:aeb1df146756 1251 * @brief Configures for the selected ADC injected channel its corresponding
mbed_official 76:aeb1df146756 1252 * rank in the sequencer and its sample time.
mbed_official 76:aeb1df146756 1253 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1254 * @param ADC_Channel: the ADC channel to configure.
mbed_official 76:aeb1df146756 1255 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1256 * @arg ADC_Channel_0: ADC Channel0 selected
mbed_official 76:aeb1df146756 1257 * @arg ADC_Channel_1: ADC Channel1 selected
mbed_official 76:aeb1df146756 1258 * @arg ADC_Channel_2: ADC Channel2 selected
mbed_official 76:aeb1df146756 1259 * @arg ADC_Channel_3: ADC Channel3 selected
mbed_official 76:aeb1df146756 1260 * @arg ADC_Channel_4: ADC Channel4 selected
mbed_official 76:aeb1df146756 1261 * @arg ADC_Channel_5: ADC Channel5 selected
mbed_official 76:aeb1df146756 1262 * @arg ADC_Channel_6: ADC Channel6 selected
mbed_official 76:aeb1df146756 1263 * @arg ADC_Channel_7: ADC Channel7 selected
mbed_official 76:aeb1df146756 1264 * @arg ADC_Channel_8: ADC Channel8 selected
mbed_official 76:aeb1df146756 1265 * @arg ADC_Channel_9: ADC Channel9 selected
mbed_official 76:aeb1df146756 1266 * @arg ADC_Channel_10: ADC Channel10 selected
mbed_official 76:aeb1df146756 1267 * @arg ADC_Channel_11: ADC Channel11 selected
mbed_official 76:aeb1df146756 1268 * @arg ADC_Channel_12: ADC Channel12 selected
mbed_official 76:aeb1df146756 1269 * @arg ADC_Channel_13: ADC Channel13 selected
mbed_official 76:aeb1df146756 1270 * @arg ADC_Channel_14: ADC Channel14 selected
mbed_official 76:aeb1df146756 1271 * @arg ADC_Channel_15: ADC Channel15 selected
mbed_official 76:aeb1df146756 1272 * @arg ADC_Channel_16: ADC Channel16 selected
mbed_official 76:aeb1df146756 1273 * @arg ADC_Channel_17: ADC Channel17 selected
mbed_official 76:aeb1df146756 1274 * @arg ADC_Channel_18: ADC Channel18 selected
mbed_official 76:aeb1df146756 1275 * @arg ADC_Channel_19: ADC Channel19 selected
mbed_official 76:aeb1df146756 1276 * @arg ADC_Channel_20: ADC Channel20 selected
mbed_official 76:aeb1df146756 1277 * @arg ADC_Channel_21: ADC Channel21 selected
mbed_official 76:aeb1df146756 1278 * @arg ADC_Channel_22: ADC Channel22 selected
mbed_official 76:aeb1df146756 1279 * @arg ADC_Channel_23: ADC Channel23 selected
mbed_official 76:aeb1df146756 1280 * @arg ADC_Channel_24: ADC Channel24 selected
mbed_official 76:aeb1df146756 1281 * @arg ADC_Channel_25: ADC Channel25 selected
mbed_official 76:aeb1df146756 1282 * @arg ADC_Channel_27: ADC Channel27 selected
mbed_official 76:aeb1df146756 1283 * @arg ADC_Channel_28: ADC Channel28 selected
mbed_official 76:aeb1df146756 1284 * @arg ADC_Channel_29: ADC Channel29 selected
mbed_official 76:aeb1df146756 1285 * @arg ADC_Channel_30: ADC Channel30 selected
mbed_official 76:aeb1df146756 1286 * @arg ADC_Channel_31: ADC Channel31 selected
mbed_official 76:aeb1df146756 1287 * @arg ADC_Channel_0b: ADC Channel0b selected
mbed_official 76:aeb1df146756 1288 * @arg ADC_Channel_1b: ADC Channel1b selected
mbed_official 76:aeb1df146756 1289 * @arg ADC_Channel_2b: ADC Channel2b selected
mbed_official 76:aeb1df146756 1290 * @arg ADC_Channel_3b: ADC Channel3b selected
mbed_official 76:aeb1df146756 1291 * @arg ADC_Channel_6b: ADC Channel6b selected
mbed_official 76:aeb1df146756 1292 * @arg ADC_Channel_7b: ADC Channel7b selected
mbed_official 76:aeb1df146756 1293 * @arg ADC_Channel_8b: ADC Channel8b selected
mbed_official 76:aeb1df146756 1294 * @arg ADC_Channel_9b: ADC Channel9b selected
mbed_official 76:aeb1df146756 1295 * @arg ADC_Channel_10b: ADC Channel10b selected
mbed_official 76:aeb1df146756 1296 * @arg ADC_Channel_11b: ADC Channel11b selected
mbed_official 76:aeb1df146756 1297 * @arg ADC_Channel_12b: ADC Channel12b selected
mbed_official 76:aeb1df146756 1298 * @param Rank: The rank in the injected group sequencer. This parameter
mbed_official 76:aeb1df146756 1299 * must be between 1 to 4.
mbed_official 76:aeb1df146756 1300 * @param ADC_SampleTime: The sample time value to be set for the selected
mbed_official 76:aeb1df146756 1301 * channel. This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1302 * @arg ADC_SampleTime_4Cycles: Sample time equal to 4 cycles
mbed_official 76:aeb1df146756 1303 * @arg ADC_SampleTime_9Cycles: Sample time equal to 9 cycles
mbed_official 76:aeb1df146756 1304 * @arg ADC_SampleTime_16Cycles: Sample time equal to 16 cycles
mbed_official 76:aeb1df146756 1305 * @arg ADC_SampleTime_24Cycles: Sample time equal to 24 cycles
mbed_official 76:aeb1df146756 1306 * @arg ADC_SampleTime_48Cycles: Sample time equal to 48 cycles
mbed_official 76:aeb1df146756 1307 * @arg ADC_SampleTime_96Cycles: Sample time equal to 96 cycles
mbed_official 76:aeb1df146756 1308 * @arg ADC_SampleTime_192Cycles: Sample time equal to 192 cycles
mbed_official 76:aeb1df146756 1309 * @arg ADC_SampleTime_384Cycles: Sample time equal to 384 cycles
mbed_official 76:aeb1df146756 1310 * @retval None
mbed_official 76:aeb1df146756 1311 */
mbed_official 76:aeb1df146756 1312 void ADC_InjectedChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)
mbed_official 76:aeb1df146756 1313 {
mbed_official 76:aeb1df146756 1314 uint32_t tmpreg1 = 0, tmpreg2 = 0, tmpreg3 = 0;
mbed_official 76:aeb1df146756 1315
mbed_official 76:aeb1df146756 1316 /* Check the parameters */
mbed_official 76:aeb1df146756 1317 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1318 assert_param(IS_ADC_CHANNEL(ADC_Channel));
mbed_official 76:aeb1df146756 1319 assert_param(IS_ADC_INJECTED_RANK(Rank));
mbed_official 76:aeb1df146756 1320 assert_param(IS_ADC_SAMPLE_TIME(ADC_SampleTime));
mbed_official 76:aeb1df146756 1321
mbed_official 76:aeb1df146756 1322 /* If ADC_Channel_30 or ADC_Channel_31 is selected */
mbed_official 76:aeb1df146756 1323 if (ADC_Channel > ADC_Channel_29)
mbed_official 76:aeb1df146756 1324 {
mbed_official 76:aeb1df146756 1325 /* Get the old register value */
mbed_official 76:aeb1df146756 1326 tmpreg1 = ADCx->SMPR0;
mbed_official 76:aeb1df146756 1327 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 1328 tmpreg2 = SMPR0_SMP_SET << (3 * (ADC_Channel - 30));
mbed_official 76:aeb1df146756 1329 /* Clear the old sample time */
mbed_official 76:aeb1df146756 1330 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 1331 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 1332 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 30));
mbed_official 76:aeb1df146756 1333 /* Set the new sample time */
mbed_official 76:aeb1df146756 1334 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 1335 /* Store the new register value */
mbed_official 76:aeb1df146756 1336 ADCx->SMPR0 = tmpreg1;
mbed_official 76:aeb1df146756 1337 }
mbed_official 76:aeb1df146756 1338 /* If ADC_Channel_20 ... ADC_Channel_29 is selected */
mbed_official 76:aeb1df146756 1339 else if (ADC_Channel > ADC_Channel_19)
mbed_official 76:aeb1df146756 1340 {
mbed_official 76:aeb1df146756 1341 /* Get the old register value */
mbed_official 76:aeb1df146756 1342 tmpreg1 = ADCx->SMPR1;
mbed_official 76:aeb1df146756 1343 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 1344 tmpreg2 = SMPR1_SMP_SET << (3 * (ADC_Channel - 20));
mbed_official 76:aeb1df146756 1345 /* Clear the old sample time */
mbed_official 76:aeb1df146756 1346 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 1347 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 1348 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 20));
mbed_official 76:aeb1df146756 1349 /* Set the new sample time */
mbed_official 76:aeb1df146756 1350 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 1351 /* Store the new register value */
mbed_official 76:aeb1df146756 1352 ADCx->SMPR1 = tmpreg1;
mbed_official 76:aeb1df146756 1353 }
mbed_official 76:aeb1df146756 1354 /* If ADC_Channel_10 ... ADC_Channel_19 is selected */
mbed_official 76:aeb1df146756 1355 else if (ADC_Channel > ADC_Channel_9)
mbed_official 76:aeb1df146756 1356 {
mbed_official 76:aeb1df146756 1357 /* Get the old register value */
mbed_official 76:aeb1df146756 1358 tmpreg1 = ADCx->SMPR2;
mbed_official 76:aeb1df146756 1359 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 1360 tmpreg2 = SMPR2_SMP_SET << (3 * (ADC_Channel - 10));
mbed_official 76:aeb1df146756 1361 /* Clear the old sample time */
mbed_official 76:aeb1df146756 1362 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 1363 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 1364 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * (ADC_Channel - 10));
mbed_official 76:aeb1df146756 1365 /* Set the new sample time */
mbed_official 76:aeb1df146756 1366 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 1367 /* Store the new register value */
mbed_official 76:aeb1df146756 1368 ADCx->SMPR2 = tmpreg1;
mbed_official 76:aeb1df146756 1369 }
mbed_official 76:aeb1df146756 1370 else /* ADC_Channel include in ADC_Channel_[0..9] */
mbed_official 76:aeb1df146756 1371 {
mbed_official 76:aeb1df146756 1372 /* Get the old register value */
mbed_official 76:aeb1df146756 1373 tmpreg1 = ADCx->SMPR3;
mbed_official 76:aeb1df146756 1374 /* Calculate the mask to clear */
mbed_official 76:aeb1df146756 1375 tmpreg2 = SMPR3_SMP_SET << (3 * ADC_Channel);
mbed_official 76:aeb1df146756 1376 /* Clear the old sample time */
mbed_official 76:aeb1df146756 1377 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 1378 /* Calculate the mask to set */
mbed_official 76:aeb1df146756 1379 tmpreg2 = (uint32_t)ADC_SampleTime << (3 * ADC_Channel);
mbed_official 76:aeb1df146756 1380 /* Set the new sample time */
mbed_official 76:aeb1df146756 1381 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 1382 /* Store the new register value */
mbed_official 76:aeb1df146756 1383 ADCx->SMPR3 = tmpreg1;
mbed_official 76:aeb1df146756 1384 }
mbed_official 76:aeb1df146756 1385
mbed_official 76:aeb1df146756 1386 /* Rank configuration */
mbed_official 76:aeb1df146756 1387 /* Get the old register value */
mbed_official 76:aeb1df146756 1388 tmpreg1 = ADCx->JSQR;
mbed_official 76:aeb1df146756 1389 /* Get JL value: Number = JL+1 */
mbed_official 76:aeb1df146756 1390 tmpreg3 = (tmpreg1 & JSQR_JL_SET)>> 20;
mbed_official 76:aeb1df146756 1391 /* Calculate the mask to clear: ((Rank-1)+(4- (JL+1))) */
mbed_official 76:aeb1df146756 1392 tmpreg2 = (uint32_t)(JSQR_JSQ_SET << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1))));
mbed_official 76:aeb1df146756 1393 /* Clear the old JSQx bits for the selected rank */
mbed_official 76:aeb1df146756 1394 tmpreg1 &= ~tmpreg2;
mbed_official 76:aeb1df146756 1395 /* Calculate the mask to set: ((Rank-1)+(4- (JL+1))) */
mbed_official 76:aeb1df146756 1396 tmpreg2 = (uint32_t)(((uint32_t)(ADC_Channel)) << (5 * (uint8_t)((Rank + 3) - (tmpreg3 + 1))));
mbed_official 76:aeb1df146756 1397 /* Set the JSQx bits for the selected rank */
mbed_official 76:aeb1df146756 1398 tmpreg1 |= tmpreg2;
mbed_official 76:aeb1df146756 1399 /* Store the new register value */
mbed_official 76:aeb1df146756 1400 ADCx->JSQR = tmpreg1;
mbed_official 76:aeb1df146756 1401 }
mbed_official 76:aeb1df146756 1402
mbed_official 76:aeb1df146756 1403 /**
mbed_official 76:aeb1df146756 1404 * @brief Configures the sequencer length for injected channels.
mbed_official 76:aeb1df146756 1405 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1406 * @param Length: The sequencer length.
mbed_official 76:aeb1df146756 1407 * This parameter must be a number between 1 to 4.
mbed_official 76:aeb1df146756 1408 * @retval None
mbed_official 76:aeb1df146756 1409 */
mbed_official 76:aeb1df146756 1410 void ADC_InjectedSequencerLengthConfig(ADC_TypeDef* ADCx, uint8_t Length)
mbed_official 76:aeb1df146756 1411 {
mbed_official 76:aeb1df146756 1412 uint32_t tmpreg1 = 0;
mbed_official 76:aeb1df146756 1413 uint32_t tmpreg2 = 0;
mbed_official 76:aeb1df146756 1414
mbed_official 76:aeb1df146756 1415 /* Check the parameters */
mbed_official 76:aeb1df146756 1416 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1417 assert_param(IS_ADC_INJECTED_LENGTH(Length));
mbed_official 76:aeb1df146756 1418
mbed_official 76:aeb1df146756 1419 /* Get the old register value */
mbed_official 76:aeb1df146756 1420 tmpreg1 = ADCx->JSQR;
mbed_official 76:aeb1df146756 1421 /* Clear the old injected sequence length JL bits */
mbed_official 76:aeb1df146756 1422 tmpreg1 &= JSQR_JL_RESET;
mbed_official 76:aeb1df146756 1423 /* Set the injected sequence length JL bits */
mbed_official 76:aeb1df146756 1424 tmpreg2 = Length - 1;
mbed_official 76:aeb1df146756 1425 tmpreg1 |= tmpreg2 << 20;
mbed_official 76:aeb1df146756 1426 /* Store the new register value */
mbed_official 76:aeb1df146756 1427 ADCx->JSQR = tmpreg1;
mbed_official 76:aeb1df146756 1428 }
mbed_official 76:aeb1df146756 1429
mbed_official 76:aeb1df146756 1430 /**
mbed_official 76:aeb1df146756 1431 * @brief Set the injected channels conversion value offset.
mbed_official 76:aeb1df146756 1432 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1433 * @param ADC_InjectedChannel: the ADC injected channel to set its offset.
mbed_official 76:aeb1df146756 1434 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1435 * @arg ADC_InjectedChannel_1: Injected Channel1 selected.
mbed_official 76:aeb1df146756 1436 * @arg ADC_InjectedChannel_2: Injected Channel2 selected.
mbed_official 76:aeb1df146756 1437 * @arg ADC_InjectedChannel_3: Injected Channel3 selected.
mbed_official 76:aeb1df146756 1438 * @arg ADC_InjectedChannel_4: Injected Channel4 selected.
mbed_official 76:aeb1df146756 1439 * @param Offset: the offset value for the selected ADC injected channel
mbed_official 76:aeb1df146756 1440 * This parameter must be a 12bit value.
mbed_official 76:aeb1df146756 1441 * @retval None
mbed_official 76:aeb1df146756 1442 */
mbed_official 76:aeb1df146756 1443 void ADC_SetInjectedOffset(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel, uint16_t Offset)
mbed_official 76:aeb1df146756 1444 {
mbed_official 76:aeb1df146756 1445 __IO uint32_t tmp = 0;
mbed_official 76:aeb1df146756 1446
mbed_official 76:aeb1df146756 1447 /* Check the parameters */
mbed_official 76:aeb1df146756 1448 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1449 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
mbed_official 76:aeb1df146756 1450 assert_param(IS_ADC_OFFSET(Offset));
mbed_official 76:aeb1df146756 1451
mbed_official 76:aeb1df146756 1452 tmp = (uint32_t)ADCx;
mbed_official 76:aeb1df146756 1453 tmp += ADC_InjectedChannel;
mbed_official 76:aeb1df146756 1454
mbed_official 76:aeb1df146756 1455 /* Set the selected injected channel data offset */
mbed_official 76:aeb1df146756 1456 *(__IO uint32_t *) tmp = (uint32_t)Offset;
mbed_official 76:aeb1df146756 1457 }
mbed_official 76:aeb1df146756 1458
mbed_official 76:aeb1df146756 1459 /**
mbed_official 76:aeb1df146756 1460 * @brief Configures the ADCx external trigger for injected channels conversion.
mbed_official 76:aeb1df146756 1461 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1462 * @param ADC_ExternalTrigInjecConv: specifies the ADC trigger to start injected
mbed_official 76:aeb1df146756 1463 * conversion. This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1464 * @arg ADC_ExternalTrigInjecConv_T9_CC1: Timer9 capture compare1 selected
mbed_official 76:aeb1df146756 1465 * @arg ADC_ExternalTrigInjecConv_T9_TRGO: Timer9 TRGO event selected
mbed_official 76:aeb1df146756 1466 * @arg ADC_ExternalTrigInjecConv_T2_TRGO: Timer2 TRGO event selected
mbed_official 76:aeb1df146756 1467 * @arg ADC_ExternalTrigInjecConv_T2_CC1: Timer2 capture compare1 selected
mbed_official 76:aeb1df146756 1468 * @arg ADC_ExternalTrigInjecConv_T3_CC4: Timer3 capture compare4 selected
mbed_official 76:aeb1df146756 1469 * @arg ADC_ExternalTrigInjecConv_T4_TRGO: Timer4 TRGO event selected
mbed_official 76:aeb1df146756 1470 * @arg ADC_ExternalTrigInjecConv_T4_CC1: Timer4 capture compare1 selected
mbed_official 76:aeb1df146756 1471 * @arg ADC_ExternalTrigInjecConv_T4_CC2: Timer4 capture compare2 selected
mbed_official 76:aeb1df146756 1472 * @arg ADC_ExternalTrigInjecConv_T4_CC3: Timer4 capture compare3 selected
mbed_official 76:aeb1df146756 1473 * @arg ADC_ExternalTrigInjecConv_T10_CC1: Timer10 capture compare1 selected
mbed_official 76:aeb1df146756 1474 * @arg ADC_ExternalTrigInjecConv_T7_TRGO: Timer7 TRGO event selected
mbed_official 76:aeb1df146756 1475 * @arg ADC_ExternalTrigInjecConv_Ext_IT15: External interrupt line 15 event selected
mbed_official 76:aeb1df146756 1476 * @retval None
mbed_official 76:aeb1df146756 1477 */
mbed_official 76:aeb1df146756 1478 void ADC_ExternalTrigInjectedConvConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConv)
mbed_official 76:aeb1df146756 1479 {
mbed_official 76:aeb1df146756 1480 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 1481
mbed_official 76:aeb1df146756 1482 /* Check the parameters */
mbed_official 76:aeb1df146756 1483 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1484 assert_param(IS_ADC_EXT_INJEC_TRIG(ADC_ExternalTrigInjecConv));
mbed_official 76:aeb1df146756 1485
mbed_official 76:aeb1df146756 1486 /* Get the old register value */
mbed_official 76:aeb1df146756 1487 tmpreg = ADCx->CR2;
mbed_official 76:aeb1df146756 1488 /* Clear the old external event selection for injected group */
mbed_official 76:aeb1df146756 1489 tmpreg &= CR2_JEXTSEL_RESET;
mbed_official 76:aeb1df146756 1490 /* Set the external event selection for injected group */
mbed_official 76:aeb1df146756 1491 tmpreg |= ADC_ExternalTrigInjecConv;
mbed_official 76:aeb1df146756 1492 /* Store the new register value */
mbed_official 76:aeb1df146756 1493 ADCx->CR2 = tmpreg;
mbed_official 76:aeb1df146756 1494 }
mbed_official 76:aeb1df146756 1495
mbed_official 76:aeb1df146756 1496 /**
mbed_official 76:aeb1df146756 1497 * @brief Configures the ADCx external trigger edge for injected channels conversion.
mbed_official 76:aeb1df146756 1498 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1499 * @param ADC_ExternalTrigInjecConvEdge: specifies the ADC external trigger
mbed_official 76:aeb1df146756 1500 * edge to start injected conversion.
mbed_official 76:aeb1df146756 1501 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1502 * @arg ADC_ExternalTrigConvEdge_None: external trigger disabled for
mbed_official 76:aeb1df146756 1503 * injected conversion.
mbed_official 76:aeb1df146756 1504 * @arg ADC_ExternalTrigConvEdge_Rising: detection on rising edge
mbed_official 76:aeb1df146756 1505 * @arg ADC_ExternalTrigConvEdge_Falling: detection on falling edge
mbed_official 76:aeb1df146756 1506 * @arg ADC_ExternalTrigConvEdge_RisingFalling: detection on
mbed_official 76:aeb1df146756 1507 * both rising and falling edge
mbed_official 76:aeb1df146756 1508 * @retval None
mbed_official 76:aeb1df146756 1509 */
mbed_official 76:aeb1df146756 1510 void ADC_ExternalTrigInjectedConvEdgeConfig(ADC_TypeDef* ADCx, uint32_t ADC_ExternalTrigInjecConvEdge)
mbed_official 76:aeb1df146756 1511 {
mbed_official 76:aeb1df146756 1512 uint32_t tmpreg = 0;
mbed_official 76:aeb1df146756 1513
mbed_official 76:aeb1df146756 1514 /* Check the parameters */
mbed_official 76:aeb1df146756 1515 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1516 assert_param(IS_ADC_EXT_INJEC_TRIG_EDGE(ADC_ExternalTrigInjecConvEdge));
mbed_official 76:aeb1df146756 1517
mbed_official 76:aeb1df146756 1518 /* Get the old register value */
mbed_official 76:aeb1df146756 1519 tmpreg = ADCx->CR2;
mbed_official 76:aeb1df146756 1520 /* Clear the old external trigger edge for injected group */
mbed_official 76:aeb1df146756 1521 tmpreg &= CR2_JEXTEN_RESET;
mbed_official 76:aeb1df146756 1522 /* Set the new external trigger edge for injected group */
mbed_official 76:aeb1df146756 1523 tmpreg |= ADC_ExternalTrigInjecConvEdge;
mbed_official 76:aeb1df146756 1524 /* Store the new register value */
mbed_official 76:aeb1df146756 1525 ADCx->CR2 = tmpreg;
mbed_official 76:aeb1df146756 1526 }
mbed_official 76:aeb1df146756 1527
mbed_official 76:aeb1df146756 1528 /**
mbed_official 76:aeb1df146756 1529 * @brief Enables the selected ADC software start conversion of the injected
mbed_official 76:aeb1df146756 1530 * channels.
mbed_official 76:aeb1df146756 1531 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1532 * @retval None
mbed_official 76:aeb1df146756 1533 */
mbed_official 76:aeb1df146756 1534 void ADC_SoftwareStartInjectedConv(ADC_TypeDef* ADCx)
mbed_official 76:aeb1df146756 1535 {
mbed_official 76:aeb1df146756 1536 /* Check the parameters */
mbed_official 76:aeb1df146756 1537 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1538 /* Enable the selected ADC conversion for injected group */
mbed_official 76:aeb1df146756 1539 ADCx->CR2 |= (uint32_t)ADC_CR2_JSWSTART;
mbed_official 76:aeb1df146756 1540 }
mbed_official 76:aeb1df146756 1541
mbed_official 76:aeb1df146756 1542 /**
mbed_official 76:aeb1df146756 1543 * @brief Gets the selected ADC Software start injected conversion Status.
mbed_official 76:aeb1df146756 1544 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1545 * @retval The new state of ADC software start injected conversion (SET or RESET).
mbed_official 76:aeb1df146756 1546 */
mbed_official 76:aeb1df146756 1547 FlagStatus ADC_GetSoftwareStartInjectedConvCmdStatus(ADC_TypeDef* ADCx)
mbed_official 76:aeb1df146756 1548 {
mbed_official 76:aeb1df146756 1549 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1550
mbed_official 76:aeb1df146756 1551 /* Check the parameters */
mbed_official 76:aeb1df146756 1552 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1553
mbed_official 76:aeb1df146756 1554 /* Check the status of JSWSTART bit */
mbed_official 76:aeb1df146756 1555 if ((ADCx->CR2 & ADC_CR2_JSWSTART) != (uint32_t)RESET)
mbed_official 76:aeb1df146756 1556 {
mbed_official 76:aeb1df146756 1557 /* JSWSTART bit is set */
mbed_official 76:aeb1df146756 1558 bitstatus = SET;
mbed_official 76:aeb1df146756 1559 }
mbed_official 76:aeb1df146756 1560 else
mbed_official 76:aeb1df146756 1561 {
mbed_official 76:aeb1df146756 1562 /* JSWSTART bit is reset */
mbed_official 76:aeb1df146756 1563 bitstatus = RESET;
mbed_official 76:aeb1df146756 1564 }
mbed_official 76:aeb1df146756 1565 /* Return the JSWSTART bit status */
mbed_official 76:aeb1df146756 1566 return bitstatus;
mbed_official 76:aeb1df146756 1567 }
mbed_official 76:aeb1df146756 1568
mbed_official 76:aeb1df146756 1569 /**
mbed_official 76:aeb1df146756 1570 * @brief Enables or disables the selected ADC automatic injected group
mbed_official 76:aeb1df146756 1571 * conversion after regular one.
mbed_official 76:aeb1df146756 1572 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1573 * @param NewState: new state of the selected ADC auto injected
mbed_official 76:aeb1df146756 1574 * conversion.
mbed_official 76:aeb1df146756 1575 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1576 * @retval None
mbed_official 76:aeb1df146756 1577 */
mbed_official 76:aeb1df146756 1578 void ADC_AutoInjectedConvCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1579 {
mbed_official 76:aeb1df146756 1580 /* Check the parameters */
mbed_official 76:aeb1df146756 1581 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1582 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1583
mbed_official 76:aeb1df146756 1584 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1585 {
mbed_official 76:aeb1df146756 1586 /* Enable the selected ADC automatic injected group conversion */
mbed_official 76:aeb1df146756 1587 ADCx->CR1 |= (uint32_t)ADC_CR1_JAUTO;
mbed_official 76:aeb1df146756 1588 }
mbed_official 76:aeb1df146756 1589 else
mbed_official 76:aeb1df146756 1590 {
mbed_official 76:aeb1df146756 1591 /* Disable the selected ADC automatic injected group conversion */
mbed_official 76:aeb1df146756 1592 ADCx->CR1 &= (uint32_t)(~ADC_CR1_JAUTO);
mbed_official 76:aeb1df146756 1593 }
mbed_official 76:aeb1df146756 1594 }
mbed_official 76:aeb1df146756 1595
mbed_official 76:aeb1df146756 1596 /**
mbed_official 76:aeb1df146756 1597 * @brief Enables or disables the discontinuous mode for injected group
mbed_official 76:aeb1df146756 1598 * channel for the specified ADC.
mbed_official 76:aeb1df146756 1599 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1600 * @param NewState: new state of the selected ADC discontinuous mode
mbed_official 76:aeb1df146756 1601 * on injected group channel. This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1602 * @retval None
mbed_official 76:aeb1df146756 1603 */
mbed_official 76:aeb1df146756 1604 void ADC_InjectedDiscModeCmd(ADC_TypeDef* ADCx, FunctionalState NewState)
mbed_official 76:aeb1df146756 1605 {
mbed_official 76:aeb1df146756 1606 /* Check the parameters */
mbed_official 76:aeb1df146756 1607 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1608 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1609
mbed_official 76:aeb1df146756 1610 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1611 {
mbed_official 76:aeb1df146756 1612 /* Enable the selected ADC injected discontinuous mode */
mbed_official 76:aeb1df146756 1613 ADCx->CR1 |= (uint32_t)ADC_CR1_JDISCEN;
mbed_official 76:aeb1df146756 1614 }
mbed_official 76:aeb1df146756 1615 else
mbed_official 76:aeb1df146756 1616 {
mbed_official 76:aeb1df146756 1617 /* Disable the selected ADC injected discontinuous mode */
mbed_official 76:aeb1df146756 1618 ADCx->CR1 &= (uint32_t)(~ADC_CR1_JDISCEN);
mbed_official 76:aeb1df146756 1619 }
mbed_official 76:aeb1df146756 1620 }
mbed_official 76:aeb1df146756 1621
mbed_official 76:aeb1df146756 1622 /**
mbed_official 76:aeb1df146756 1623 * @brief Returns the ADC injected channel conversion result.
mbed_official 76:aeb1df146756 1624 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1625 * @param ADC_InjectedChannel: the converted ADC injected channel.
mbed_official 76:aeb1df146756 1626 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1627 * @arg ADC_InjectedChannel_1: Injected Channel1 selected
mbed_official 76:aeb1df146756 1628 * @arg ADC_InjectedChannel_2: Injected Channel2 selected
mbed_official 76:aeb1df146756 1629 * @arg ADC_InjectedChannel_3: Injected Channel3 selected
mbed_official 76:aeb1df146756 1630 * @arg ADC_InjectedChannel_4: Injected Channel4 selected
mbed_official 76:aeb1df146756 1631 * @retval The Data conversion value.
mbed_official 76:aeb1df146756 1632 */
mbed_official 76:aeb1df146756 1633 uint16_t ADC_GetInjectedConversionValue(ADC_TypeDef* ADCx, uint8_t ADC_InjectedChannel)
mbed_official 76:aeb1df146756 1634 {
mbed_official 76:aeb1df146756 1635 __IO uint32_t tmp = 0;
mbed_official 76:aeb1df146756 1636
mbed_official 76:aeb1df146756 1637 /* Check the parameters */
mbed_official 76:aeb1df146756 1638 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1639 assert_param(IS_ADC_INJECTED_CHANNEL(ADC_InjectedChannel));
mbed_official 76:aeb1df146756 1640
mbed_official 76:aeb1df146756 1641 tmp = (uint32_t)ADCx;
mbed_official 76:aeb1df146756 1642 tmp += ADC_InjectedChannel + JDR_OFFSET;
mbed_official 76:aeb1df146756 1643
mbed_official 76:aeb1df146756 1644 /* Returns the selected injected channel conversion data value */
mbed_official 76:aeb1df146756 1645 return (uint16_t) (*(__IO uint32_t*) tmp);
mbed_official 76:aeb1df146756 1646 }
mbed_official 76:aeb1df146756 1647
mbed_official 76:aeb1df146756 1648 /**
mbed_official 76:aeb1df146756 1649 * @}
mbed_official 76:aeb1df146756 1650 */
mbed_official 76:aeb1df146756 1651
mbed_official 76:aeb1df146756 1652 /** @defgroup ADC_Group8 Interrupts and flags management functions
mbed_official 76:aeb1df146756 1653 * @brief Interrupts and flags management functions.
mbed_official 76:aeb1df146756 1654 *
mbed_official 76:aeb1df146756 1655 @verbatim
mbed_official 76:aeb1df146756 1656 ===============================================================================
mbed_official 76:aeb1df146756 1657 ##### Interrupts and flags management functions #####
mbed_official 76:aeb1df146756 1658 ===============================================================================
mbed_official 76:aeb1df146756 1659 [..] This section provides functions allowing to configure the ADC Interrupts
mbed_official 76:aeb1df146756 1660 and get the status and clear flags and Interrupts pending bits.
mbed_official 76:aeb1df146756 1661
mbed_official 76:aeb1df146756 1662 [..] The ADC provide 4 Interrupts sources and 9 Flags which can be divided into
mbed_official 76:aeb1df146756 1663 3 groups:
mbed_official 76:aeb1df146756 1664 *** Flags and Interrupts for ADC regular channels ***
mbed_official 76:aeb1df146756 1665 =====================================================
mbed_official 76:aeb1df146756 1666 [..]
mbed_official 76:aeb1df146756 1667 (+)Flags :
mbed_official 76:aeb1df146756 1668 (##) ADC_FLAG_OVR : Overrun detection when regular converted data are
mbed_official 76:aeb1df146756 1669 lost.
mbed_official 76:aeb1df146756 1670 (##) ADC_FLAG_EOC : Regular channel end of conversion + to indicate
mbed_official 76:aeb1df146756 1671 (depending on EOCS bit, managed by ADC_EOCOnEachRegularChannelCmd() )
mbed_official 76:aeb1df146756 1672 the end of :
mbed_official 76:aeb1df146756 1673 (+++) a regular CHANNEL conversion.
mbed_official 76:aeb1df146756 1674 (+++) sequence of regular GROUP conversions.
mbed_official 76:aeb1df146756 1675
mbed_official 76:aeb1df146756 1676
mbed_official 76:aeb1df146756 1677 (##) ADC_FLAG_STRT: Regular channel start + to indicate when regular
mbed_official 76:aeb1df146756 1678 CHANNEL conversion starts.
mbed_official 76:aeb1df146756 1679 (##) ADC_FLAG_RCNR: Regular channel not ready + to indicate if a new
mbed_official 76:aeb1df146756 1680 regular conversion can be launched.
mbed_official 76:aeb1df146756 1681 (+)Interrupts :
mbed_official 76:aeb1df146756 1682 (##) ADC_IT_OVR : specifies the interrupt source for Overrun detection
mbed_official 76:aeb1df146756 1683 event.
mbed_official 76:aeb1df146756 1684 (##) ADC_IT_EOC : specifies the interrupt source for Regular channel
mbed_official 76:aeb1df146756 1685 end of conversion event.
mbed_official 76:aeb1df146756 1686
mbed_official 76:aeb1df146756 1687 *** Flags and Interrupts for ADC Injected channels ***
mbed_official 76:aeb1df146756 1688 ======================================================
mbed_official 76:aeb1df146756 1689 (+)Flags :
mbed_official 76:aeb1df146756 1690 (##) ADC_FLAG_JEOC : Injected channel end of conversion+ to indicate at
mbed_official 76:aeb1df146756 1691 the end of injected GROUP conversion.
mbed_official 76:aeb1df146756 1692 (##) ADC_FLAG_JSTRT: Injected channel start + to indicate hardware when
mbed_official 76:aeb1df146756 1693 injected GROUP conversion starts.
mbed_official 76:aeb1df146756 1694 (##) ADC_FLAG_JCNR: Injected channel not ready + to indicate if a new
mbed_official 76:aeb1df146756 1695 injected conversion can be launched.
mbed_official 76:aeb1df146756 1696 (+)Interrupts
mbed_official 76:aeb1df146756 1697 (##) ADC_IT_JEOC : specifies the interrupt source for Injected channel
mbed_official 76:aeb1df146756 1698 end of conversion event.
mbed_official 76:aeb1df146756 1699 *** General Flags and Interrupts for the ADC ***
mbed_official 76:aeb1df146756 1700 ================================================
mbed_official 76:aeb1df146756 1701 (+)Flags :
mbed_official 76:aeb1df146756 1702 (##) ADC_FLAG_AWD: Analog watchdog + to indicate if the converted voltage
mbed_official 76:aeb1df146756 1703 crosses the programmed thresholds values.
mbed_official 76:aeb1df146756 1704 (##) ADC_FLAG_ADONS: ADC ON status + to indicate if the ADC is ready
mbed_official 76:aeb1df146756 1705 to convert.
mbed_official 76:aeb1df146756 1706 (+)Interrupts :
mbed_official 76:aeb1df146756 1707 (##) ADC_IT_AWD : specifies the interrupt source for Analog watchdog
mbed_official 76:aeb1df146756 1708 event.
mbed_official 76:aeb1df146756 1709
mbed_official 76:aeb1df146756 1710 [..] The user should identify which mode will be used in his application to
mbed_official 76:aeb1df146756 1711 manage the ADC controller events: Polling mode or Interrupt mode.
mbed_official 76:aeb1df146756 1712
mbed_official 76:aeb1df146756 1713 [..] In the Polling Mode it is advised to use the following functions:
mbed_official 76:aeb1df146756 1714 (+) ADC_GetFlagStatus() : to check if flags events occur.
mbed_official 76:aeb1df146756 1715 (+) ADC_ClearFlag() : to clear the flags events.
mbed_official 76:aeb1df146756 1716
mbed_official 76:aeb1df146756 1717 [..] In the Interrupt Mode it is advised to use the following functions:
mbed_official 76:aeb1df146756 1718 (+) ADC_ITConfig() : to enable or disable the interrupt source.
mbed_official 76:aeb1df146756 1719 (+) ADC_GetITStatus() : to check if Interrupt occurs.
mbed_official 76:aeb1df146756 1720 (+) ADC_ClearITPendingBit() : to clear the Interrupt pending Bit
mbed_official 76:aeb1df146756 1721 (corresponding Flag).
mbed_official 76:aeb1df146756 1722 @endverbatim
mbed_official 76:aeb1df146756 1723 * @{
mbed_official 76:aeb1df146756 1724 */
mbed_official 76:aeb1df146756 1725
mbed_official 76:aeb1df146756 1726 /**
mbed_official 76:aeb1df146756 1727 * @brief Enables or disables the specified ADC interrupts.
mbed_official 76:aeb1df146756 1728 * @param ADCx: where x can be 1 to select the ADC peripheral.
mbed_official 76:aeb1df146756 1729 * @param ADC_IT: specifies the ADC interrupt sources to be enabled or disabled.
mbed_official 76:aeb1df146756 1730 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1731 * @arg ADC_IT_EOC: End of conversion interrupt
mbed_official 76:aeb1df146756 1732 * @arg ADC_IT_AWD: Analog watchdog interrupt
mbed_official 76:aeb1df146756 1733 * @arg ADC_IT_JEOC: End of injected conversion interrupt
mbed_official 76:aeb1df146756 1734 * @arg ADC_IT_OVR: overrun interrupt
mbed_official 76:aeb1df146756 1735 * @param NewState: new state of the specified ADC interrupts.
mbed_official 76:aeb1df146756 1736 * This parameter can be: ENABLE or DISABLE.
mbed_official 76:aeb1df146756 1737 * @retval None
mbed_official 76:aeb1df146756 1738 */
mbed_official 76:aeb1df146756 1739 void ADC_ITConfig(ADC_TypeDef* ADCx, uint16_t ADC_IT, FunctionalState NewState)
mbed_official 76:aeb1df146756 1740 {
mbed_official 76:aeb1df146756 1741 uint32_t itmask = 0;
mbed_official 76:aeb1df146756 1742
mbed_official 76:aeb1df146756 1743 /* Check the parameters */
mbed_official 76:aeb1df146756 1744 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1745 assert_param(IS_FUNCTIONAL_STATE(NewState));
mbed_official 76:aeb1df146756 1746 assert_param(IS_ADC_IT(ADC_IT));
mbed_official 76:aeb1df146756 1747
mbed_official 76:aeb1df146756 1748 /* Get the ADC IT index */
mbed_official 76:aeb1df146756 1749 itmask = (uint8_t)ADC_IT;
mbed_official 76:aeb1df146756 1750 itmask = (uint32_t)0x01 << itmask;
mbed_official 76:aeb1df146756 1751
mbed_official 76:aeb1df146756 1752 if (NewState != DISABLE)
mbed_official 76:aeb1df146756 1753 {
mbed_official 76:aeb1df146756 1754 /* Enable the selected ADC interrupts */
mbed_official 76:aeb1df146756 1755 ADCx->CR1 |= itmask;
mbed_official 76:aeb1df146756 1756 }
mbed_official 76:aeb1df146756 1757 else
mbed_official 76:aeb1df146756 1758 {
mbed_official 76:aeb1df146756 1759 /* Disable the selected ADC interrupts */
mbed_official 76:aeb1df146756 1760 ADCx->CR1 &= (~(uint32_t)itmask);
mbed_official 76:aeb1df146756 1761 }
mbed_official 76:aeb1df146756 1762 }
mbed_official 76:aeb1df146756 1763
mbed_official 76:aeb1df146756 1764 /**
mbed_official 76:aeb1df146756 1765 * @brief Checks whether the specified ADC flag is set or not.
mbed_official 76:aeb1df146756 1766 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1767 * @param ADC_FLAG: specifies the flag to check.
mbed_official 76:aeb1df146756 1768 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1769 * @arg ADC_FLAG_AWD: Analog watchdog flag
mbed_official 76:aeb1df146756 1770 * @arg ADC_FLAG_EOC: End of conversion flag
mbed_official 76:aeb1df146756 1771 * @arg ADC_FLAG_JEOC: End of injected group conversion flag
mbed_official 76:aeb1df146756 1772 * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
mbed_official 76:aeb1df146756 1773 * @arg ADC_FLAG_STRT: Start of regular group conversion flag
mbed_official 76:aeb1df146756 1774 * @arg ADC_FLAG_OVR: Overrun flag
mbed_official 76:aeb1df146756 1775 * @arg ADC_FLAG_ADONS: ADC ON status
mbed_official 76:aeb1df146756 1776 * @arg ADC_FLAG_RCNR: Regular channel not ready
mbed_official 76:aeb1df146756 1777 * @arg ADC_FLAG_JCNR: Injected channel not ready
mbed_official 76:aeb1df146756 1778 * @retval The new state of ADC_FLAG (SET or RESET).
mbed_official 76:aeb1df146756 1779 */
mbed_official 76:aeb1df146756 1780 FlagStatus ADC_GetFlagStatus(ADC_TypeDef* ADCx, uint16_t ADC_FLAG)
mbed_official 76:aeb1df146756 1781 {
mbed_official 76:aeb1df146756 1782 FlagStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1783
mbed_official 76:aeb1df146756 1784 /* Check the parameters */
mbed_official 76:aeb1df146756 1785 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1786 assert_param(IS_ADC_GET_FLAG(ADC_FLAG));
mbed_official 76:aeb1df146756 1787
mbed_official 76:aeb1df146756 1788 /* Check the status of the specified ADC flag */
mbed_official 76:aeb1df146756 1789 if ((ADCx->SR & ADC_FLAG) != (uint8_t)RESET)
mbed_official 76:aeb1df146756 1790 {
mbed_official 76:aeb1df146756 1791 /* ADC_FLAG is set */
mbed_official 76:aeb1df146756 1792 bitstatus = SET;
mbed_official 76:aeb1df146756 1793 }
mbed_official 76:aeb1df146756 1794 else
mbed_official 76:aeb1df146756 1795 {
mbed_official 76:aeb1df146756 1796 /* ADC_FLAG is reset */
mbed_official 76:aeb1df146756 1797 bitstatus = RESET;
mbed_official 76:aeb1df146756 1798 }
mbed_official 76:aeb1df146756 1799 /* Return the ADC_FLAG status */
mbed_official 76:aeb1df146756 1800 return bitstatus;
mbed_official 76:aeb1df146756 1801 }
mbed_official 76:aeb1df146756 1802
mbed_official 76:aeb1df146756 1803 /**
mbed_official 76:aeb1df146756 1804 * @brief Clears the ADCx's pending flags.
mbed_official 76:aeb1df146756 1805 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1806 * @param ADC_FLAG: specifies the flag to clear.
mbed_official 76:aeb1df146756 1807 * This parameter can be any combination of the following values:
mbed_official 76:aeb1df146756 1808 * @arg ADC_FLAG_AWD: Analog watchdog flag
mbed_official 76:aeb1df146756 1809 * @arg ADC_FLAG_EOC: End of conversion flag
mbed_official 76:aeb1df146756 1810 * @arg ADC_FLAG_JEOC: End of injected group conversion flag
mbed_official 76:aeb1df146756 1811 * @arg ADC_FLAG_JSTRT: Start of injected group conversion flag
mbed_official 76:aeb1df146756 1812 * @arg ADC_FLAG_STRT: Start of regular group conversion flag
mbed_official 76:aeb1df146756 1813 * @arg ADC_FLAG_OVR: overrun flag
mbed_official 76:aeb1df146756 1814 * @retval None
mbed_official 76:aeb1df146756 1815 */
mbed_official 76:aeb1df146756 1816 void ADC_ClearFlag(ADC_TypeDef* ADCx, uint16_t ADC_FLAG)
mbed_official 76:aeb1df146756 1817 {
mbed_official 76:aeb1df146756 1818 /* Check the parameters */
mbed_official 76:aeb1df146756 1819 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1820 assert_param(IS_ADC_CLEAR_FLAG(ADC_FLAG));
mbed_official 76:aeb1df146756 1821
mbed_official 76:aeb1df146756 1822 /* Clear the selected ADC flags */
mbed_official 76:aeb1df146756 1823 ADCx->SR = ~(uint32_t)ADC_FLAG;
mbed_official 76:aeb1df146756 1824 }
mbed_official 76:aeb1df146756 1825
mbed_official 76:aeb1df146756 1826 /**
mbed_official 76:aeb1df146756 1827 * @brief Checks whether the specified ADC interrupt has occurred or not.
mbed_official 76:aeb1df146756 1828 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1829 * @param ADC_IT: specifies the ADC interrupt source to check.
mbed_official 76:aeb1df146756 1830 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1831 * @arg ADC_IT_EOC: End of conversion interrupt
mbed_official 76:aeb1df146756 1832 * @arg ADC_IT_AWD: Analog watchdog interrupt
mbed_official 76:aeb1df146756 1833 * @arg ADC_IT_JEOC: End of injected conversion interrupt
mbed_official 76:aeb1df146756 1834 * @arg ADC_IT_OVR: Overrun interrupt
mbed_official 76:aeb1df146756 1835 * @retval The new state of ADC_IT (SET or RESET).
mbed_official 76:aeb1df146756 1836 */
mbed_official 76:aeb1df146756 1837 ITStatus ADC_GetITStatus(ADC_TypeDef* ADCx, uint16_t ADC_IT)
mbed_official 76:aeb1df146756 1838 {
mbed_official 76:aeb1df146756 1839 ITStatus bitstatus = RESET;
mbed_official 76:aeb1df146756 1840 uint32_t itmask = 0, enablestatus = 0;
mbed_official 76:aeb1df146756 1841
mbed_official 76:aeb1df146756 1842 /* Check the parameters */
mbed_official 76:aeb1df146756 1843 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1844 assert_param(IS_ADC_IT(ADC_IT));
mbed_official 76:aeb1df146756 1845
mbed_official 76:aeb1df146756 1846 /* Get the ADC IT index */
mbed_official 76:aeb1df146756 1847 itmask = (uint32_t)((uint32_t)ADC_IT >> 8);
mbed_official 76:aeb1df146756 1848
mbed_official 76:aeb1df146756 1849 /* Get the ADC_IT enable bit status */
mbed_official 76:aeb1df146756 1850 enablestatus = (ADCx->CR1 & ((uint32_t)0x01 << (uint8_t)ADC_IT));
mbed_official 76:aeb1df146756 1851
mbed_official 76:aeb1df146756 1852 /* Check the status of the specified ADC interrupt */
mbed_official 76:aeb1df146756 1853 if (((uint32_t)(ADCx->SR & (uint32_t)itmask) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
mbed_official 76:aeb1df146756 1854 {
mbed_official 76:aeb1df146756 1855 /* ADC_IT is set */
mbed_official 76:aeb1df146756 1856 bitstatus = SET;
mbed_official 76:aeb1df146756 1857 }
mbed_official 76:aeb1df146756 1858 else
mbed_official 76:aeb1df146756 1859 {
mbed_official 76:aeb1df146756 1860 /* ADC_IT is reset */
mbed_official 76:aeb1df146756 1861 bitstatus = RESET;
mbed_official 76:aeb1df146756 1862 }
mbed_official 76:aeb1df146756 1863 /* Return the ADC_IT status */
mbed_official 76:aeb1df146756 1864 return bitstatus;
mbed_official 76:aeb1df146756 1865 }
mbed_official 76:aeb1df146756 1866
mbed_official 76:aeb1df146756 1867 /**
mbed_official 76:aeb1df146756 1868 * @brief Clears the ADCx's interrupt pending bits.
mbed_official 76:aeb1df146756 1869 * @param ADCx: where x can be 1 to select the ADC1 peripheral.
mbed_official 76:aeb1df146756 1870 * @param ADC_IT: specifies the ADC interrupt pending bit to clear.
mbed_official 76:aeb1df146756 1871 * This parameter can be one of the following values:
mbed_official 76:aeb1df146756 1872 * @arg ADC_IT_EOC: End of conversion interrupt
mbed_official 76:aeb1df146756 1873 * @arg ADC_IT_AWD: Analog watchdog interrupt
mbed_official 76:aeb1df146756 1874 * @arg ADC_IT_JEOC: End of injected conversion interrupt
mbed_official 76:aeb1df146756 1875 * @arg ADC_IT_OVR: Overrun interrupt
mbed_official 76:aeb1df146756 1876 * @retval None
mbed_official 76:aeb1df146756 1877 */
mbed_official 76:aeb1df146756 1878 void ADC_ClearITPendingBit(ADC_TypeDef* ADCx, uint16_t ADC_IT)
mbed_official 76:aeb1df146756 1879 {
mbed_official 76:aeb1df146756 1880 uint8_t itmask = 0;
mbed_official 76:aeb1df146756 1881
mbed_official 76:aeb1df146756 1882 /* Check the parameters */
mbed_official 76:aeb1df146756 1883 assert_param(IS_ADC_ALL_PERIPH(ADCx));
mbed_official 76:aeb1df146756 1884 assert_param(IS_ADC_IT(ADC_IT));
mbed_official 76:aeb1df146756 1885
mbed_official 76:aeb1df146756 1886 /* Get the ADC IT index */
mbed_official 76:aeb1df146756 1887 itmask = (uint8_t)(ADC_IT >> 8);
mbed_official 76:aeb1df146756 1888
mbed_official 76:aeb1df146756 1889 /* Clear the selected ADC interrupt pending bits */
mbed_official 76:aeb1df146756 1890 ADCx->SR = ~(uint32_t)itmask;
mbed_official 76:aeb1df146756 1891 }
mbed_official 76:aeb1df146756 1892
mbed_official 76:aeb1df146756 1893 /**
mbed_official 76:aeb1df146756 1894 * @}
mbed_official 76:aeb1df146756 1895 */
mbed_official 76:aeb1df146756 1896
mbed_official 76:aeb1df146756 1897 /**
mbed_official 76:aeb1df146756 1898 * @}
mbed_official 76:aeb1df146756 1899 */
mbed_official 76:aeb1df146756 1900
mbed_official 76:aeb1df146756 1901 /**
mbed_official 76:aeb1df146756 1902 * @}
mbed_official 76:aeb1df146756 1903 */
mbed_official 76:aeb1df146756 1904
mbed_official 76:aeb1df146756 1905 /**
mbed_official 76:aeb1df146756 1906 * @}
mbed_official 76:aeb1df146756 1907 */
mbed_official 76:aeb1df146756 1908
mbed_official 76:aeb1df146756 1909 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/