comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/DAC/OneChannelDMA_Escalator/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 DAC/OneChannelDMA_Escalator/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 DAC_OneChannelDMA_Escalator
30 * @{
31 */
32
33 /* Private typedef -----------------------------------------------------------*/
34 /* Private define ------------------------------------------------------------*/
35 #define DAC_DHR8R1_Address 0x40007410
36
37 /* Init Structure definition */
38 DAC_InitTypeDef DAC_InitStructure;
39 DMA_InitTypeDef DMA_InitStructure;
40
41 /* Private macro -------------------------------------------------------------*/
42 /* Private variables ---------------------------------------------------------*/
43 const uint8_t Escalator8bit[6] = {0x0, 0x33, 0x66, 0x99, 0xCC, 0xFF};
44
45 /* Private function prototypes -----------------------------------------------*/
46 void RCC_Configuration(void);
47 void GPIO_Configuration(void);
48 void Delay(__IO uint32_t nCount);
49
50 /* Private functions ---------------------------------------------------------*/
51
52 /**
53 * @brief Main program.
54 * @param None
55 * @retval None
56 */
57 int main(void)
58 {
59 /*!< At this stage the microcontroller clock setting is already configured,
60 this is done through SystemInit() function which is called from startup
61 file (startup_stm32f10x_xx.s) before to branch to application main.
62 To reconfigure the default setting of SystemInit() function, refer to
63 system_stm32f10x.c file
64 */
65
66 /* System Clocks Configuration */
67 RCC_Configuration();
68
69 /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
70 connected to the DAC converter. In order to avoid parasitic consumption,
71 the GPIO pin should be configured in analog */
72 GPIO_Configuration();
73
74 /* TIM6 Configuration */
75 TIM_PrescalerConfig(TIM6, 0xF, TIM_PSCReloadMode_Update);
76 TIM_SetAutoreload(TIM6, 0xFF);
77 /* TIM6 TRGO selection */
78 TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
79
80 /* DAC channel1 Configuration */
81 DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
82 DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
83 DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
84 DAC_Init(DAC_Channel_1, &DAC_InitStructure);
85
86 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
87 /* DMA2 channel3 configuration */
88 DMA_DeInit(DMA2_Channel3);
89 #else
90 /* DMA1 channel3 configuration */
91 DMA_DeInit(DMA1_Channel3);
92 #endif
93
94 DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR8R1_Address;
95 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Escalator8bit;
96 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
97 DMA_InitStructure.DMA_BufferSize = 6;
98 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
99 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
100 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
101 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
102 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
103 DMA_InitStructure.DMA_Priority = DMA_Priority_High;
104 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
105
106 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
107 DMA_Init(DMA2_Channel3, &DMA_InitStructure);
108 /* Enable DMA2 Channel3 */
109 DMA_Cmd(DMA2_Channel3, ENABLE);
110 #else
111 DMA_Init(DMA1_Channel3, &DMA_InitStructure);
112 /* Enable DMA1 Channel3 */
113 DMA_Cmd(DMA1_Channel3, ENABLE);
114 #endif
115
116 /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
117 automatically connected to the DAC converter. */
118 DAC_Cmd(DAC_Channel_1, ENABLE);
119
120 /* Enable DMA for DAC Channel1 */
121 DAC_DMACmd(DAC_Channel_1, ENABLE);
122
123 /* TIM6 enable counter */
124 TIM_Cmd(TIM6, ENABLE);
125
126 while (1)
127 {
128 }
129 }
130
131
132 /**
133 * @brief Configures the different system clocks.
134 * @param None
135 * @retval None
136 */
137 void RCC_Configuration(void)
138 {
139 /* Enable peripheral clocks ------------------------------------------------*/
140 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
141 /* DMA2 clock enable */
142 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
143 #else
144 /* DMA1 clock enable */
145 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
146 #endif
147 /* GPIOA Periph clock enable */
148 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
149 /* DAC Periph clock enable */
150 RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
151 /* TIM6 Periph clock enable */
152 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
153 }
154
155 /**
156 * @brief Configures the different GPIO ports.
157 * @param None
158 * @retval None
159 */
160 void GPIO_Configuration(void)
161 {
162 GPIO_InitTypeDef GPIO_InitStructure;
163
164 /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
165 connected to the DAC converter. In order to avoid parasitic consumption,
166 the GPIO pin should be configured in analog */
167 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
168 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
169 GPIO_Init(GPIOA, &GPIO_InitStructure);
170 }
171
172 /**
173 * @brief Inserts a delay time.
174 * @param nCount: specifies the delay time length.
175 * @retval None
176 */
177 void Delay(__IO uint32_t nCount)
178 {
179 for(; nCount != 0; nCount--);
180 }
181
182 #ifdef USE_FULL_ASSERT
183
184 /**
185 * @brief Reports the name of the source file and the source line number
186 * where the assert_param error has occurred.
187 * @param file: pointer to the source file name
188 * @param line: assert_param error line source number
189 * @retval None
190 */
191 void assert_failed(uint8_t* file, uint32_t line)
192 {
193 /* User can add his own implementation to report the file name and line number,
194 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
195
196 /* Infinite loop */
197 while (1)
198 {
199 }
200 }
201
202 #endif
203
204 /**
205 * @}
206 */
207
208 /**
209 * @}
210 */
211
212 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/