comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/ADC/RegSimul_DualMode/main.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file ADC/RegSimul_DualMode/main.c
4 * @author MCD Application Team
5 * @version V3.5.0
6 * @date 08-April-2011
7 * @brief Main program body
8 ******************************************************************************
9 * @attention
10 *
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 *
18 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
20 */
21
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x.h"
24
25 /** @addtogroup STM32F10x_StdPeriph_Examples
26 * @{
27 */
28
29 /** @addtogroup ADC_RegSimul_DualMode
30 * @{
31 */
32
33 /* Private typedef -----------------------------------------------------------*/
34 /* Private define ------------------------------------------------------------*/
35 #define ADC1_DR_Address ((uint32_t)0x4001244C)
36
37 /* Private macro -------------------------------------------------------------*/
38 /* Private variables ---------------------------------------------------------*/
39 ADC_InitTypeDef ADC_InitStructure;
40 DMA_InitTypeDef DMA_InitStructure;
41 __IO uint32_t ADC_DualConvertedValueTab[16];
42
43 /* Private function prototypes -----------------------------------------------*/
44 void RCC_Configuration(void);
45 void GPIO_Configuration(void);
46
47 /* Private functions ---------------------------------------------------------*/
48
49 /**
50 * @brief Main program
51 * @param None
52 * @retval None
53 */
54 int main(void)
55 {
56 /*!< At this stage the microcontroller clock setting is already configured,
57 this is done through SystemInit() function which is called from startup
58 file (startup_stm32f10x_xx.s) before to branch to application main.
59 To reconfigure the default setting of SystemInit() function, refer to
60 system_stm32f10x.c file
61 */
62
63 /* System clocks configuration ---------------------------------------------*/
64 RCC_Configuration();
65
66 /* GPIO configuration ------------------------------------------------------*/
67 GPIO_Configuration();
68
69 /* DMA1 channel1 configuration ----------------------------------------------*/
70 DMA_DeInit(DMA1_Channel1);
71 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_Address;
72 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_DualConvertedValueTab;
73 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
74 DMA_InitStructure.DMA_BufferSize = 16;
75 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
76 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
77 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
78 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
79 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
80 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
81 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
82 DMA_Init(DMA1_Channel1, &DMA_InitStructure);
83 /* Enable DMA1 Channel1 */
84 DMA_Cmd(DMA1_Channel1, ENABLE);
85
86 /* ADC1 configuration ------------------------------------------------------*/
87 ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
88 ADC_InitStructure.ADC_ScanConvMode = ENABLE;
89 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
90 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
91 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
92 ADC_InitStructure.ADC_NbrOfChannel = 2;
93 ADC_Init(ADC1, &ADC_InitStructure);
94 /* ADC1 regular channels configuration */
95 ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_239Cycles5);
96 ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_239Cycles5);
97 /* Enable ADC1 DMA */
98 ADC_DMACmd(ADC1, ENABLE);
99
100 /* ADC2 configuration ------------------------------------------------------*/
101 ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;
102 ADC_InitStructure.ADC_ScanConvMode = ENABLE;
103 ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
104 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
105 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
106 ADC_InitStructure.ADC_NbrOfChannel = 2;
107 ADC_Init(ADC2, &ADC_InitStructure);
108 /* ADC2 regular channels configuration */
109 ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_239Cycles5);
110 ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 2, ADC_SampleTime_239Cycles5);
111 /* Enable ADC2 external trigger conversion */
112 ADC_ExternalTrigConvCmd(ADC2, ENABLE);
113
114 /* Enable ADC1 */
115 ADC_Cmd(ADC1, ENABLE);
116 /* Enable Vrefint channel17 */
117 ADC_TempSensorVrefintCmd(ENABLE);
118
119 /* Enable ADC1 reset calibration register */
120 ADC_ResetCalibration(ADC1);
121 /* Check the end of ADC1 reset calibration register */
122 while(ADC_GetResetCalibrationStatus(ADC1));
123
124 /* Start ADC1 calibration */
125 ADC_StartCalibration(ADC1);
126 /* Check the end of ADC1 calibration */
127 while(ADC_GetCalibrationStatus(ADC1));
128
129 /* Enable ADC2 */
130 ADC_Cmd(ADC2, ENABLE);
131
132 /* Enable ADC2 reset calibration register */
133 ADC_ResetCalibration(ADC2);
134 /* Check the end of ADC2 reset calibration register */
135 while(ADC_GetResetCalibrationStatus(ADC2));
136
137 /* Start ADC2 calibration */
138 ADC_StartCalibration(ADC2);
139 /* Check the end of ADC2 calibration */
140 while(ADC_GetCalibrationStatus(ADC2));
141
142 /* Start ADC1 Software Conversion */
143 ADC_SoftwareStartConvCmd(ADC1, ENABLE);
144
145 /* Test on DMA1 channel1 transfer complete flag */
146 while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
147 /* Clear DMA1 channel1 transfer complete flag */
148 DMA_ClearFlag(DMA1_FLAG_TC1);
149
150 while (1)
151 {
152 }
153 }
154
155 /**
156 * @brief Configures the different system clocks.
157 * @param None
158 * @retval None
159 */
160 void RCC_Configuration(void)
161 {
162 /* ADCCLK = PCLK2/4 */
163 RCC_ADCCLKConfig(RCC_PCLK2_Div4);
164 /* Enable peripheral clocks ------------------------------------------------*/
165 /* Enable DMA1 clock */
166 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
167
168 /* Enable ADC1, ADC2 and GPIOC clock */
169 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 |
170 RCC_APB2Periph_GPIOC, ENABLE);
171 }
172
173 /**
174 * @brief Configures the different GPIO ports.
175 * @param None
176 * @retval None
177 */
178 void GPIO_Configuration(void)
179 {
180 GPIO_InitTypeDef GPIO_InitStructure;
181
182 /* Configure PC.01, PC.02 and PC.04 (ADC Channel11, Channel12 and Channel14)
183 as analog input ----------------------------------------------------------*/
184 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_4;
185 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
186 GPIO_Init(GPIOC, &GPIO_InitStructure);
187 }
188
189 #ifdef USE_FULL_ASSERT
190
191 /**
192 * @brief Reports the name of the source file and the source line number
193 * where the assert_param error has occurred.
194 * @param file: pointer to the source file name
195 * @param line: assert_param error line source number
196 * @retval None
197 */
198 void assert_failed(uint8_t* file, uint32_t line)
199 {
200 /* User can add his own implementation to report the file name and line number,
201 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
202
203 /* Infinite loop */
204 while (1)
205 {
206 }
207 }
208
209 #endif
210
211 /**
212 * @}
213 */
214
215 /**
216 * @}
217 */
218
219 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/