STM32F10x_StdPeriph_Examples/ADC/RegSimul_DualMode/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    ADC/RegSimul_DualMode/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 
00024 /** @addtogroup STM32F10x_StdPeriph_Examples
00025   * @{
00026   */
00027 
00028 /** @addtogroup ADC_RegSimul_DualMode
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 #define ADC1_DR_Address    ((uint32_t)0x4001244C)
00035 
00036 /* Private macro -------------------------------------------------------------*/
00037 /* Private variables ---------------------------------------------------------*/
00038 ADC_InitTypeDef ADC_InitStructure;
00039 DMA_InitTypeDef DMA_InitStructure;
00040 __IO uint32_t ADC_DualConvertedValueTab[16];
00041     
00042 /* Private function prototypes -----------------------------------------------*/
00043 void RCC_Configuration(void);
00044 void GPIO_Configuration(void);
00045   
00046 /* Private functions ---------------------------------------------------------*/
00047 
00048 /**
00049   * @brief   Main program
00050   * @param  None
00051   * @retval None
00052   */
00053 int main(void)
00054 {
00055   /*!< At this stage the microcontroller clock setting is already configured, 
00056        this is done through SystemInit() function which is called from startup
00057        file (startup_stm32f10x_xx.s) before to branch to application main.
00058        To reconfigure the default setting of SystemInit() function, refer to
00059        system_stm32f10x.c file
00060      */     
00061        
00062   /* System clocks configuration ---------------------------------------------*/
00063   RCC_Configuration();
00064 
00065   /* GPIO configuration ------------------------------------------------------*/
00066   GPIO_Configuration();
00067 
00068   /* DMA1 channel1 configuration ----------------------------------------------*/
00069   DMA_DeInit(DMA1_Channel1);
00070   DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;
00071   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_DualConvertedValueTab;
00072   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
00073   DMA_InitStructure.DMA_BufferSize = 16;
00074   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
00075   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00076   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
00077   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
00078   DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
00079   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
00080   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
00081   DMA_Init(DMA1_Channel1, &DMA_InitStructure);
00082   /* Enable DMA1 Channel1 */
00083   DMA_Cmd(DMA1_Channel1, ENABLE);
00084 
00085   /* ADC1 configuration ------------------------------------------------------*/
00086   ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
00087   ADC_InitStructure.ADC_ScanConvMode = ENABLE;
00088   ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
00089   ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
00090   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
00091   ADC_InitStructure.ADC_NbrOfChannel = 2;
00092   ADC_Init(ADC1, &ADC_InitStructure);
00093   /* ADC1 regular channels configuration */ 
00094   ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);    
00095   ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_239Cycles5);
00096   /* Enable ADC1 DMA */
00097   ADC_DMACmd(ADC1, ENABLE);
00098 
00099   /* ADC2 configuration ------------------------------------------------------*/
00100   ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
00101   ADC_InitStructure.ADC_ScanConvMode = ENABLE;
00102   ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
00103   ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
00104   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
00105   ADC_InitStructure.ADC_NbrOfChannel = 2;
00106   ADC_Init(ADC2, &ADC_InitStructure);
00107   /* ADC2 regular channels configuration */ 
00108   ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_239Cycles5);
00109   ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 2, ADC_SampleTime_239Cycles5);
00110   /* Enable ADC2 external trigger conversion */
00111   ADC_ExternalTrigConvCmd(ADC2, ENABLE);
00112 
00113   /* Enable ADC1 */
00114   ADC_Cmd(ADC1, ENABLE);
00115   /* Enable Vrefint channel17 */
00116   ADC_TempSensorVrefintCmd(ENABLE);
00117 
00118   /* Enable ADC1 reset calibaration register */   
00119   ADC_ResetCalibration(ADC1);
00120   /* Check the end of ADC1 reset calibration register */
00121   while(ADC_GetResetCalibrationStatus(ADC1));
00122 
00123   /* Start ADC1 calibaration */
00124   ADC_StartCalibration(ADC1);
00125   /* Check the end of ADC1 calibration */
00126   while(ADC_GetCalibrationStatus(ADC1));
00127 
00128   /* Enable ADC2 */
00129   ADC_Cmd(ADC2, ENABLE);
00130 
00131   /* Enable ADC2 reset calibaration register */   
00132   ADC_ResetCalibration(ADC2);
00133   /* Check the end of ADC2 reset calibration register */
00134   while(ADC_GetResetCalibrationStatus(ADC2));
00135 
00136   /* Start ADC2 calibaration */
00137   ADC_StartCalibration(ADC2);
00138   /* Check the end of ADC2 calibration */
00139   while(ADC_GetCalibrationStatus(ADC2));
00140 
00141   /* Start ADC1 Software Conversion */ 
00142   ADC_SoftwareStartConvCmd(ADC1, ENABLE);
00143 
00144   /* Test on DMA1 channel1 transfer complete flag */
00145   while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
00146   /* Clear DMA1 channel1 transfer complete flag */
00147   DMA_ClearFlag(DMA1_FLAG_TC1);
00148 
00149   while (1)
00150   {
00151   }
00152 }
00153 
00154 /**
00155   * @brief  Configures the different system clocks.
00156   * @param  None
00157   * @retval None
00158   */
00159 void RCC_Configuration(void)
00160 {
00161   /* ADCCLK = PCLK2/4 */
00162   RCC_ADCCLKConfig(RCC_PCLK2_Div4);
00163   /* Enable peripheral clocks ------------------------------------------------*/
00164   /* Enable DMA1 clock */
00165   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
00166 
00167   /* Enable ADC1, ADC2 and GPIOC clock */
00168   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 |
00169                          RCC_APB2Periph_GPIOC, ENABLE);
00170 }
00171 
00172 /**
00173   * @brief  Configures the different GPIO ports.
00174   * @param  None
00175   * @retval None
00176   */
00177 void GPIO_Configuration(void)
00178 {
00179   GPIO_InitTypeDef GPIO_InitStructure;
00180 
00181   /* Configure PC.01, PC.02 and PC.04 (ADC Channel11, Channel12 and Channel14)
00182     as analog input ----------------------------------------------------------*/
00183   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_4;
00184   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
00185   GPIO_Init(GPIOC, &GPIO_InitStructure);
00186 }
00187 
00188 #ifdef  USE_FULL_ASSERT
00189 
00190 /**
00191   * @brief  Reports the name of the source file and the source line number
00192   *         where the assert_param error has occurred.
00193   * @param  file: pointer to the source file name
00194   * @param  line: assert_param error line source number
00195   * @retval None
00196   */
00197 void assert_failed(uint8_t* file, uint32_t line)
00198 { 
00199   /* User can add his own implementation to report the file name and line number,
00200      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00201 
00202   /* Infinite loop */
00203   while (1)
00204   {
00205   }
00206 }
00207 #endif
00208 
00209 /**
00210   * @}
00211   */ 
00212 
00213 /**
00214   * @}
00215   */ 
00216 
00217 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32