STM32F10x_StdPeriph_Examples/DAC/OneChannelDMA_Escalator/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    DAC/OneChannelDMA_Escalator/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_OneChannelDMA_Escalator
00029   * @{
00030   */ 
00031 
00032 /* Private typedef -----------------------------------------------------------*/
00033 /* Private define ------------------------------------------------------------*/
00034 #define DAC_DHR8R1_Address      0x40007410
00035 
00036 /* Init Structure definition */
00037 DAC_InitTypeDef            DAC_InitStructure;
00038 DMA_InitTypeDef            DMA_InitStructure;
00039 
00040 /* Private macro -------------------------------------------------------------*/
00041 /* Private variables ---------------------------------------------------------*/
00042 const uint8_t Escalator8bit[6] = {0x0, 0x33, 0x66, 0x99, 0xCC, 0xFF};
00043 
00044 /* Private function prototypes -----------------------------------------------*/
00045 void RCC_Configuration(void);
00046 void GPIO_Configuration(void);
00047 void Delay(__IO uint32_t nCount);
00048 
00049 /* Private functions ---------------------------------------------------------*/
00050 
00051 /**
00052   * @brief   Main program.
00053   * @param  None
00054   * @retval None
00055   */
00056 int main(void)
00057 {
00058   /*!< At this stage the microcontroller clock setting is already configured, 
00059        this is done through SystemInit() function which is called from startup
00060        file (startup_stm32f10x_xx.s) before to branch to application main.
00061        To reconfigure the default setting of SystemInit() function, refer to
00062        system_stm32f10x.c file
00063      */     
00064        
00065   /* System Clocks Configuration */
00066   RCC_Configuration();   
00067 
00068   /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically 
00069      connected to the DAC converter. In order to avoid parasitic consumption, 
00070      the GPIO pin should be configured in analog */
00071   GPIO_Configuration();
00072 
00073   /* TIM6 Configuration */
00074   TIM_PrescalerConfig(TIM6, 0xF, TIM_PSCReloadMode_Update);
00075   TIM_SetAutoreload(TIM6, 0xFF);
00076   /* TIM6 TRGO selection */
00077   TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
00078 
00079   /* DAC channel1 Configuration */
00080   DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;
00081   DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
00082   DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
00083   DAC_Init(DAC_Channel_1, &DAC_InitStructure);
00084 
00085 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
00086   /* DMA2 channel3 configuration */
00087   DMA_DeInit(DMA2_Channel3);
00088 #else
00089   /* DMA1 channel3 configuration */
00090   DMA_DeInit(DMA1_Channel3);
00091 #endif
00092 
00093   DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR8R1_Address;
00094   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&Escalator8bit;
00095   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
00096   DMA_InitStructure.DMA_BufferSize = 6;
00097   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
00098   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
00099   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
00100   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
00101   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
00102   DMA_InitStructure.DMA_Priority = DMA_Priority_High;
00103   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
00104 
00105 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
00106   DMA_Init(DMA2_Channel3, &DMA_InitStructure);
00107   /* Enable DMA2 Channel3 */
00108   DMA_Cmd(DMA2_Channel3, ENABLE);
00109 #else
00110   DMA_Init(DMA1_Channel3, &DMA_InitStructure);
00111   /* Enable DMA1 Channel3 */
00112   DMA_Cmd(DMA1_Channel3, ENABLE);
00113 #endif
00114 
00115   /* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
00116      automatically connected to the DAC converter. */
00117   DAC_Cmd(DAC_Channel_1, ENABLE);
00118 
00119   /* Enable DMA for DAC Channel1 */
00120   DAC_DMACmd(DAC_Channel_1, ENABLE);
00121 
00122   /* TIM6 enable counter */
00123   TIM_Cmd(TIM6, ENABLE);
00124 
00125   while (1)
00126   {
00127   }
00128 }
00129 
00130 
00131 /**
00132   * @brief  Configures the different system clocks.
00133   * @param  None
00134   * @retval None
00135   */
00136 void RCC_Configuration(void)
00137 {   
00138   /* Enable peripheral clocks ------------------------------------------------*/
00139 #if !defined STM32F10X_LD_VL && !defined STM32F10X_MD_VL
00140   /* DMA2 clock enable */
00141   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
00142 #else
00143   /* DMA1 clock enable */
00144   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
00145 #endif
00146   /* GPIOA Periph clock enable */
00147   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
00148   /* DAC Periph clock enable */
00149   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
00150   /* TIM6 Periph clock enable */
00151   RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
00152 }
00153 
00154 /**
00155   * @brief  Configures the different GPIO ports.
00156   * @param  None
00157   * @retval None
00158   */
00159 void GPIO_Configuration(void)
00160 {
00161   GPIO_InitTypeDef GPIO_InitStructure;
00162 
00163   /* Once the DAC channel is enabled, the corresponding GPIO pin is automatically 
00164      connected to the DAC converter. In order to avoid parasitic consumption, 
00165      the GPIO pin should be configured in analog */
00166   GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;
00167   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
00168   GPIO_Init(GPIOA, &GPIO_InitStructure);
00169 }
00170 
00171 /**
00172   * @brief  Inserts a delay time.
00173   * @param  nCount: specifies the delay time length.
00174   * @retval None
00175   */
00176 void Delay(__IO uint32_t nCount)
00177 {
00178   for(; nCount != 0; nCount--);
00179 }
00180 
00181 #ifdef  USE_FULL_ASSERT
00182 
00183 /**
00184   * @brief  Reports the name of the source file and the source line number
00185   *         where the assert_param error has occurred.
00186   * @param  file: pointer to the source file name
00187   * @param  line: assert_param error line source number
00188   * @retval None
00189   */
00190 void assert_failed(uint8_t* file, uint32_t line)
00191 { 
00192   /* User can add his own implementation to report the file name and line number,
00193      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00194 
00195   /* Infinite loop */
00196   while (1)
00197   {
00198   }
00199 }
00200 #endif
00201 
00202 /**
00203   * @}
00204   */ 
00205 
00206 /**
00207   * @}
00208   */ 
00209 
00210 /******************* (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