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