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