Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- ******************************************************************************
- * @file stm32f2xx_hal_adc.c
- * @author MCD Application Team
- * @version V1.0.1
- * @date 25-March-2014
- * @brief This file provides firmware functions to manage the following
- * functionalities of the Analog to Digital Convertor (ADC) peripheral:
- * + Initialization and de-initialization functions
- * + IO operation functions
- * + State and errors functions
- *
- @verbatim
- ==============================================================================
- ##### ADC Peripheral features #####
- ==============================================================================
- [..]
- (#) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution.
- (#) Interrupt generation at the end of conversion, end of injected conversion,
- and in case of analog watchdog or overrun events
- (#) Single and continuous conversion modes.
- (#) Scan mode for automatic conversion of channel 0 to channel x.
- (#) Data alignment with in-built data coherency.
- (#) Channel-wise programmable sampling time.
- (#) External trigger option with configurable polarity for both regular and
- injected conversion.
- (#) Dual/Triple mode (on devices with 2 ADCs or more).
- (#) Configurable DMA data storage in Dual/Triple ADC mode.
- (#) Configurable delay between conversions in Dual/Triple interleaved mode.
- (#) ADC conversion type (refer to the datasheets).
- (#) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
- slower speed.
- (#) ADC input range: VREF(minus) = VIN = VREF(plus).
- (#) DMA request generation during regular channel conversion.
- ##### How to use this driver #####
- ==============================================================================
- [..]
- (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
- (##) Enable the ADC interface clock using __ADC_CLK_ENABLE()
- (##) ADC pins configuration
- (+++) Enable the clock for the ADC GPIOs using the following function:
- __GPIOx_CLK_ENABLE()
- (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init()
- (##) In case of using interrupts (e.g. HAL_ADC_Start_IT())
- (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
- (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
- (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler()
- (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
- (+++) Enable the DMAx interface clock using __DMAx_CLK_ENABLE()
- (+++) Configure and enable two DMA streams stream for managing data
- transfer from peripheral to memory (output stream)
- (+++) Associate the initilalized DMA handle to the CRYP DMA handle
- using __HAL_LINKDMA()
- (+++) Configure the priority and enable the NVIC for the transfer complete
- interrupt on the two DMA Streams. The output stream should have higher
- priority than the input stream.
- (#) Configure the ADC Prescaler, conversion resolution and data alignment
- using the HAL_ADC_Init() function.
- (#) Configure the ADC regular channels group features, use HAL_ADC_Init()
- and HAL_ADC_ConfigChannel() functions.
- (#) Three mode of operations are available within this driver :
- *** Polling mode IO operation ***
- =================================
- [..]
- (+) Start the ADC peripheral using HAL_ADC_Start()
- (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
- user can specify the value of timeout according to his end application
- (+) To read the ADC converted values, use the HAL_ADC_GetValue() function.
- (+) Stop the ADC peripheral using HAL_ADC_Stop()
- *** Interrupt mode IO operation ***
- ===================================
- [..]
- (+) Start the ADC peripheral using HAL_ADC_Start_IT()
- (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
- (+) At ADC end of conversion HAL_ADC_ConvCpltCallback() function is executed and user can
- add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
- (+) In case of ADC Error, HAL_ADC_ErrorCallback() function is executed and user can
- add his own code by customization of function pointer HAL_ADC_ErrorCallback
- (+) Stop the ADC peripheral using HAL_ADC_Stop_IT()
- *** DMA mode IO operation ***
- ==============================
- [..]
- (+) Start the ADC peripheral using HAL_ADC_Start_DMA(), at this stage the user specify the length
- of data to be transfered at each end of conversion
- (+) At The end of data transfer by HAL_ADC_ConvCpltCallback() function is executed and user can
- add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
- (+) In case of transfer Error, HAL_ADC_ErrorCallback() function is executed and user can
- add his own code by customization of function pointer HAL_ADC_ErrorCallback
- (+) Stop the ADC peripheral using HAL_ADC_Stop_DMA()
- *** ADC HAL driver macros list ***
- =============================================
- [..]
- Below the list of most used macros in ADC HAL driver.
- (+) __HAL_ADC_ENABLE : Enable the ADC peripheral
- (+) __HAL_ADC_DISABLE : Disable the ADC peripheral
- (+) __HAL_ADC_ENABLE_IT: Enable the ADC end of conversion interrupt
- (+) __HAL_ADC_DISABLE_IT: Disable the ADC end of conversion interrupt
- (+) __HAL_ADC_GET_IT_SOURCE: Check if the specified ADC interrupt source is enabled or disabled
- (+) __HAL_ADC_CLEAR_FLAG: Clear the ADC's pending flags
- (+) __HAL_ADC_GET_FLAG: Get the selected ADC's flag status
- (+) __HAL_ADC_GET_RESOLUTION: Return resolution bits in CR1 register
- [..]
- (@) You can refer to the ADC HAL driver header file for more useful macros
- @endverbatim
- ******************************************************************************
- * @attention
- *
- *
- © COPYRIGHT(c) 2014 STMicroelectronics
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. Neither the name of STMicroelectronics nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- ******************************************************************************
- */
Advertisement
Add Comment
Please, Sign In to add comment