comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/DAC/OneChannel_NoiseWave/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/OneChannel_NoiseWave/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_OneChannel_NoiseWave
30 * @{
31 */
32
33 /* Private typedef -----------------------------------------------------------*/
34 /* Private define ------------------------------------------------------------*/
35 /* Init Structure definition */
36 DAC_InitTypeDef DAC_InitStructure;
37
38 /* Private macro -------------------------------------------------------------*/
39 /* Private variables ---------------------------------------------------------*/
40 /* Private function prototypes -----------------------------------------------*/
41 void RCC_Configuration(void);
42 void GPIO_Configuration(void);
43 void Delay(__IO uint32_t nCount);
44
45 /* Private functions ---------------------------------------------------------*/
46
47 /**
48 * @brief Main program.
49 * @param None
50 * @retval None
51 */
52 int main(void)
53 {
54 /*!< At this stage the microcontroller clock setting is already configured,
55 this is done through SystemInit() function which is called from startup
56 file (startup_stm32f10x_xx.s) before to branch to application main.
57 To reconfigure the default setting of SystemInit() function, refer to
58 system_stm32f10x.c file
59 */
60
61 /* System Clocks Configuration */
62 RCC_Configuration();
63
64 /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
65 connected to the DAC converter. In order to avoid parasitic consumption,
66 the GPIO pin should be configured in analog */
67 GPIO_Configuration();
68
69 /* DAC channel1 Configuration */
70 DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
71 DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Noise;
72 DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits8_0;
73 DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
74 DAC_Init(DAC_Channel_1, &DAC_InitStructure);
75
76 /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
77 automatically connected to the DAC converter. */
78 DAC_Cmd(DAC_Channel_1, ENABLE);
79
80 /* Set DAC Channel1 DHR12L register */
81 DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0);
82
83 while (1)
84 {
85 /* Start DAC Channel1 conversion by software */
86 DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
87 }
88 }
89
90 /**
91 * @brief Configures the different system clocks.
92 * @param None
93 * @retval None
94 */
95 void RCC_Configuration(void)
96 {
97 /* Enable peripheral clocks ------------------------------------------------*/
98 /* GPIOA Periph clock enable */
99 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
100 /* DAC Periph clock enable */
101 RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
102 }
103
104 /**
105 * @brief Configures the different GPIO ports.
106 * @param None
107 * @retval None
108 */
109 void GPIO_Configuration(void)
110 {
111 GPIO_InitTypeDef GPIO_InitStructure;
112
113 /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically
114 connected to the DAC converter. In order to avoid parasitic consumption,
115 the GPIO pin should be configured in analog */
116 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
117 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
118 GPIO_Init(GPIOA, &GPIO_InitStructure);
119 }
120
121 /**
122 * @brief Inserts a delay time.
123 * @param nCount: specifies the delay time length.
124 * @retval None
125 */
126 void Delay(__IO uint32_t nCount)
127 {
128 for(; nCount != 0; nCount--);
129 }
130
131 #ifdef USE_FULL_ASSERT
132
133 /**
134 * @brief Reports the name of the source file and the source line number
135 * where the assert_param error has occurred.
136 * @param file: pointer to the source file name
137 * @param line: assert_param error line source number
138 * @retval None
139 */
140 void assert_failed(uint8_t* file, uint32_t line)
141 {
142 /* User can add his own implementation to report the file name and line number,
143 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
144
145 /* Infinite loop */
146 while (1)
147 {
148 }
149 }
150
151 #endif
152
153 /**
154 * @}
155 */
156
157 /**
158 * @}
159 */
160
161 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/