Guest User

ADC

a guest
Aug 14th, 2015
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.08 KB | None | 0 0
  1. /**
  2. ******************************************************************************
  3. * @file stm32f2xx_hal_adc.c
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-March-2014
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the Analog to Digital Convertor (ADC) peripheral:
  9. * + Initialization and de-initialization functions
  10. * + IO operation functions
  11. * + State and errors functions
  12. *
  13. @verbatim
  14. ==============================================================================
  15. ##### ADC Peripheral features #####
  16. ==============================================================================
  17. [..]
  18. (#) 12-bit, 10-bit, 8-bit or 6-bit configurable resolution.
  19. (#) Interrupt generation at the end of conversion, end of injected conversion,
  20. and in case of analog watchdog or overrun events
  21. (#) Single and continuous conversion modes.
  22. (#) Scan mode for automatic conversion of channel 0 to channel x.
  23. (#) Data alignment with in-built data coherency.
  24. (#) Channel-wise programmable sampling time.
  25. (#) External trigger option with configurable polarity for both regular and
  26. injected conversion.
  27. (#) Dual/Triple mode (on devices with 2 ADCs or more).
  28. (#) Configurable DMA data storage in Dual/Triple ADC mode.
  29. (#) Configurable delay between conversions in Dual/Triple interleaved mode.
  30. (#) ADC conversion type (refer to the datasheets).
  31. (#) ADC supply requirements: 2.4 V to 3.6 V at full speed and down to 1.8 V at
  32. slower speed.
  33. (#) ADC input range: VREF(minus) = VIN = VREF(plus).
  34. (#) DMA request generation during regular channel conversion.
  35.  
  36.  
  37. ##### How to use this driver #####
  38. ==============================================================================
  39. [..]
  40. (#)Initialize the ADC low level resources by implementing the HAL_ADC_MspInit():
  41. (##) Enable the ADC interface clock using __ADC_CLK_ENABLE()
  42. (##) ADC pins configuration
  43. (+++) Enable the clock for the ADC GPIOs using the following function:
  44. __GPIOx_CLK_ENABLE()
  45. (+++) Configure these ADC pins in analog mode using HAL_GPIO_Init()
  46. (##) In case of using interrupts (e.g. HAL_ADC_Start_IT())
  47. (+++) Configure the ADC interrupt priority using HAL_NVIC_SetPriority()
  48. (+++) Enable the ADC IRQ handler using HAL_NVIC_EnableIRQ()
  49. (+++) In ADC IRQ handler, call HAL_ADC_IRQHandler()
  50. (##) In case of using DMA to control data transfer (e.g. HAL_ADC_Start_DMA())
  51. (+++) Enable the DMAx interface clock using __DMAx_CLK_ENABLE()
  52. (+++) Configure and enable two DMA streams stream for managing data
  53. transfer from peripheral to memory (output stream)
  54. (+++) Associate the initilalized DMA handle to the CRYP DMA handle
  55. using __HAL_LINKDMA()
  56. (+++) Configure the priority and enable the NVIC for the transfer complete
  57. interrupt on the two DMA Streams. The output stream should have higher
  58. priority than the input stream.
  59.  
  60. (#) Configure the ADC Prescaler, conversion resolution and data alignment
  61. using the HAL_ADC_Init() function.
  62.  
  63. (#) Configure the ADC regular channels group features, use HAL_ADC_Init()
  64. and HAL_ADC_ConfigChannel() functions.
  65.  
  66. (#) Three mode of operations are available within this driver :
  67.  
  68. *** Polling mode IO operation ***
  69. =================================
  70. [..]
  71. (+) Start the ADC peripheral using HAL_ADC_Start()
  72. (+) Wait for end of conversion using HAL_ADC_PollForConversion(), at this stage
  73. user can specify the value of timeout according to his end application
  74. (+) To read the ADC converted values, use the HAL_ADC_GetValue() function.
  75. (+) Stop the ADC peripheral using HAL_ADC_Stop()
  76.  
  77. *** Interrupt mode IO operation ***
  78. ===================================
  79. [..]
  80. (+) Start the ADC peripheral using HAL_ADC_Start_IT()
  81. (+) Use HAL_ADC_IRQHandler() called under ADC_IRQHandler() Interrupt subroutine
  82. (+) At ADC end of conversion HAL_ADC_ConvCpltCallback() function is executed and user can
  83. add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
  84. (+) In case of ADC Error, HAL_ADC_ErrorCallback() function is executed and user can
  85. add his own code by customization of function pointer HAL_ADC_ErrorCallback
  86. (+) Stop the ADC peripheral using HAL_ADC_Stop_IT()
  87.  
  88. *** DMA mode IO operation ***
  89. ==============================
  90. [..]
  91. (+) Start the ADC peripheral using HAL_ADC_Start_DMA(), at this stage the user specify the length
  92. of data to be transfered at each end of conversion
  93. (+) At The end of data transfer by HAL_ADC_ConvCpltCallback() function is executed and user can
  94. add his own code by customization of function pointer HAL_ADC_ConvCpltCallback
  95. (+) In case of transfer Error, HAL_ADC_ErrorCallback() function is executed and user can
  96. add his own code by customization of function pointer HAL_ADC_ErrorCallback
  97. (+) Stop the ADC peripheral using HAL_ADC_Stop_DMA()
  98.  
  99. *** ADC HAL driver macros list ***
  100. =============================================
  101. [..]
  102. Below the list of most used macros in ADC HAL driver.
  103.  
  104. (+) __HAL_ADC_ENABLE : Enable the ADC peripheral
  105. (+) __HAL_ADC_DISABLE : Disable the ADC peripheral
  106. (+) __HAL_ADC_ENABLE_IT: Enable the ADC end of conversion interrupt
  107. (+) __HAL_ADC_DISABLE_IT: Disable the ADC end of conversion interrupt
  108. (+) __HAL_ADC_GET_IT_SOURCE: Check if the specified ADC interrupt source is enabled or disabled
  109. (+) __HAL_ADC_CLEAR_FLAG: Clear the ADC's pending flags
  110. (+) __HAL_ADC_GET_FLAG: Get the selected ADC's flag status
  111. (+) __HAL_ADC_GET_RESOLUTION: Return resolution bits in CR1 register
  112.  
  113. [..]
  114. (@) You can refer to the ADC HAL driver header file for more useful macros
  115.  
  116. @endverbatim
  117. ******************************************************************************
  118. * @attention
  119. *
  120. *
  121. © COPYRIGHT(c) 2014 STMicroelectronics
  122.  
  123.  
  124. *
  125. * Redistribution and use in source and binary forms, with or without modification,
  126. * are permitted provided that the following conditions are met:
  127. * 1. Redistributions of source code must retain the above copyright notice,
  128. * this list of conditions and the following disclaimer.
  129. * 2. Redistributions in binary form must reproduce the above copyright notice,
  130. * this list of conditions and the following disclaimer in the documentation
  131. * and/or other materials provided with the distribution.
  132. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  133. * may be used to endorse or promote products derived from this software
  134. * without specific prior written permission.
  135. *
  136. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  137. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  138. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  139. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  140. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  141. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  142. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  143. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  144. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  145. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  146. *
  147. ******************************************************************************
  148. */
Advertisement
Add Comment
Please, Sign In to add comment