STM32F10x_StdPeriph_Examples/DAC/OneChannel_NoiseWave/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    DAC/OneChannel_NoiseWave/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 DAC_OneChannel_NoiseWave
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 /* Init Structure definition */
00035 DAC_InitTypeDef            DAC_InitStructure;
00036 
00037 /* Private macro -------------------------------------------------------------*/
00038 /* Private variables ---------------------------------------------------------*/
00039 /* Private function prototypes -----------------------------------------------*/
00040 void RCC_Configuration(void);
00041 void GPIO_Configuration(void);
00042 void Delay(__IO uint32_t nCount);
00043 
00044 /* Private functions ---------------------------------------------------------*/
00045 
00046 /**
00047   * @brief   Main program.
00048   * @param  None
00049   * @retval None
00050   */
00051 int main(void)
00052 {
00053   /*!< At this stage the microcontroller clock setting is already configured, 
00054        this is done through SystemInit() function which is called from startup
00055        file (startup_stm32f10x_xx.s) before to branch to application main.
00056        To reconfigure the default setting of SystemInit() function, refer to
00057        system_stm32f10x.c file
00058      */     
00059        
00060   /* System Clocks Configuration */
00061   RCC_Configuration();   
00062 
00063   /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically 
00064      connected to the DAC converter. In order to avoid parasitic consumption, 
00065      the GPIO pin should be configured in analog */
00066   GPIO_Configuration();
00067 
00068   /* DAC channel1 Configuration */
00069   DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
00070   DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_Noise;
00071   DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits8_0;
00072   DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
00073   DAC_Init(DAC_Channel_1, &DAC_InitStructure);
00074 
00075   /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
00076      automatically connected to the DAC converter. */
00077   DAC_Cmd(DAC_Channel_1, ENABLE);
00078 
00079   /* Set DAC Channel1 DHR12L register */
00080   DAC_SetChannel1Data(DAC_Align_12b_L, 0x7FF0);
00081 
00082   while (1)
00083   {
00084     /* Start DAC Channel1 conversion by software */
00085     DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
00086   }
00087 }
00088 
00089 /**
00090   * @brief  Configures the different system clocks.
00091   * @param  None
00092   * @retval None
00093   */
00094 void RCC_Configuration(void)
00095 {   
00096   /* Enable peripheral clocks ------------------------------------------------*/
00097   /* GPIOA Periph clock enable */
00098   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
00099   /* DAC Periph clock enable */
00100   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
00101 }
00102 
00103 /**
00104   * @brief  Configures the different GPIO ports.
00105   * @param  None
00106   * @retval None
00107   */
00108 void GPIO_Configuration(void)
00109 {
00110   GPIO_InitTypeDef GPIO_InitStructure;
00111 
00112   /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically 
00113      connected to the DAC converter. In order to avoid parasitic consumption, 
00114      the GPIO pin should be configured in analog */
00115   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
00116   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
00117   GPIO_Init(GPIOA, &GPIO_InitStructure);
00118 }
00119 
00120 /**
00121   * @brief  Inserts a delay time.
00122   * @param  nCount: specifies the delay time length.
00123   * @retval None
00124   */
00125 void Delay(__IO uint32_t nCount)
00126 {
00127   for(; nCount != 0; nCount--);
00128 }
00129 
00130 #ifdef  USE_FULL_ASSERT
00131 
00132 /**
00133   * @brief  Reports the name of the source file and the source line number
00134   *         where the assert_param error has occurred.
00135   * @param  file: pointer to the source file name
00136   * @param  line: assert_param error line source number
00137   * @retval None
00138   */
00139 void assert_failed(uint8_t* file, uint32_t line)
00140 { 
00141   /* User can add his own implementation to report the file name and line number,
00142      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00143 
00144   /* Infinite loop */
00145   while (1)
00146   {
00147   }
00148 }
00149 #endif
00150 
00151 /**
00152   * @}
00153   */ 
00154 
00155 /**
00156   * @}
00157   */ 
00158 
00159 /******************* (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