CARME-M4 BSP  V1.5
stm32f4xx_dac.c File Reference

This file provides firmware functions to manage the following functionalities of the Digital-to-Analog Converter (DAC) peripheral: More...

#include "stm32f4xx_dac.h"
#include "stm32f4xx_rcc.h"
+ Include dependency graph for stm32f4xx_dac.c:

Go to the source code of this file.

Macros

#define CR_CLEAR_MASK   ((uint32_t)0x00000FFE)
 
#define DUAL_SWTRIG_SET   ((uint32_t)0x00000003)
 
#define DUAL_SWTRIG_RESET   ((uint32_t)0xFFFFFFFC)
 
#define DHR12R1_OFFSET   ((uint32_t)0x00000008)
 
#define DHR12R2_OFFSET   ((uint32_t)0x00000014)
 
#define DHR12RD_OFFSET   ((uint32_t)0x00000020)
 
#define DOR_OFFSET   ((uint32_t)0x0000002C)
 

Functions

void DAC_DeInit (void)
 Deinitializes the DAC peripheral registers to their default reset values. More...
 
void DAC_Init (uint32_t DAC_Channel, DAC_InitTypeDef *DAC_InitStruct)
 Initializes the DAC peripheral according to the specified parameters in the DAC_InitStruct. More...
 
void DAC_StructInit (DAC_InitTypeDef *DAC_InitStruct)
 Fills each DAC_InitStruct member with its default value. More...
 
void DAC_Cmd (uint32_t DAC_Channel, FunctionalState NewState)
 Enables or disables the specified DAC channel. More...
 
void DAC_SoftwareTriggerCmd (uint32_t DAC_Channel, FunctionalState NewState)
 Enables or disables the selected DAC channel software trigger. More...
 
void DAC_DualSoftwareTriggerCmd (FunctionalState NewState)
 Enables or disables simultaneously the two DAC channels software triggers. More...
 
void DAC_WaveGenerationCmd (uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState)
 Enables or disables the selected DAC channel wave generation. More...
 
void DAC_SetChannel1Data (uint32_t DAC_Align, uint16_t Data)
 Set the specified data holding register value for DAC channel1. More...
 
void DAC_SetChannel2Data (uint32_t DAC_Align, uint16_t Data)
 Set the specified data holding register value for DAC channel2. More...
 
void DAC_SetDualChannelData (uint32_t DAC_Align, uint16_t Data2, uint16_t Data1)
 Set the specified data holding register value for dual channel DAC. More...
 
uint16_t DAC_GetDataOutputValue (uint32_t DAC_Channel)
 Returns the last data output value of the selected DAC channel. More...
 
void DAC_DMACmd (uint32_t DAC_Channel, FunctionalState NewState)
 Enables or disables the specified DAC channel DMA request. More...
 
void DAC_ITConfig (uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState)
 Enables or disables the specified DAC interrupts. More...
 
FlagStatus DAC_GetFlagStatus (uint32_t DAC_Channel, uint32_t DAC_FLAG)
 Checks whether the specified DAC flag is set or not. More...
 
void DAC_ClearFlag (uint32_t DAC_Channel, uint32_t DAC_FLAG)
 Clears the DAC channel's pending flags. More...
 
ITStatus DAC_GetITStatus (uint32_t DAC_Channel, uint32_t DAC_IT)
 Checks whether the specified DAC interrupt has occurred or not. More...
 
void DAC_ClearITPendingBit (uint32_t DAC_Channel, uint32_t DAC_IT)
 Clears the DAC channel's interrupt pending bits. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Digital-to-Analog Converter (DAC) peripheral:

Author
MCD Application Team
Version
V1.3.0
Date
08-November-2013
  • DAC channels configuration: trigger, output buffer, data format
  • DMA management
  • Interrupts and flags management
===============================================================================
                     ##### DAC Peripheral features #####
===============================================================================
   [..]        
     *** DAC Channels ***
     ====================  
   [..]  
   The device integrates two 12-bit Digital Analog Converters that can 
   be used independently or simultaneously (dual mode):
     (#) DAC channel1 with DAC_OUT1 (PA4) as output
     (#) DAC channel2 with DAC_OUT2 (PA5) as output
 
     *** DAC Triggers ***
     ====================
   [..]
   Digital to Analog conversion can be non-triggered using DAC_Trigger_None
   and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register 
   using DAC_SetChannel1Data() / DAC_SetChannel2Data() functions.
   [..] 
   Digital to Analog conversion can be triggered by:
     (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_Trigger_Ext_IT9.
         The used pin (GPIOx_Pin9) must be configured in input mode.
 
     (#) Timers TRGO: TIM2, TIM4, TIM5, TIM6, TIM7 and TIM8 
         (DAC_Trigger_T2_TRGO, DAC_Trigger_T4_TRGO...)
         The timer TRGO event should be selected using TIM_SelectOutputTrigger()
 
     (#) Software using DAC_Trigger_Software
 
     *** DAC Buffer mode feature ***
     =============================== 
     [..] 
     Each DAC channel integrates an output buffer that can be used to 
     reduce the output impedance, and to drive external loads directly
     without having to add an external operational amplifier.
     To enable, the output buffer use  
     DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
     [..]           
     (@) Refer to the device datasheet for more details about output 
         impedance value with and without output buffer.
           
      *** DAC wave generation feature ***
      =================================== 
      [..]     
      Both DAC channels can be used to generate
        (#) Noise wave using DAC_WaveGeneration_Noise
        (#) Triangle wave using DAC_WaveGeneration_Triangle
         
         -@-  Wave generation can be disabled using DAC_WaveGeneration_None
 
      *** DAC data format ***
      =======================
      [..]   
      The DAC data format can be:
        (#) 8-bit right alignment using DAC_Align_8b_R
        (#) 12-bit left alignment using DAC_Align_12b_L
        (#) 12-bit right alignment using DAC_Align_12b_R
 
      *** DAC data value to voltage correspondence ***  
      ================================================ 
      [..] 
      The analog output voltage on each DAC channel pin is determined
      by the following equation: 
      DAC_OUTx = VREF+ * DOR / 4095
      with  DOR is the Data Output Register
         VEF+ is the input voltage reference (refer to the device datasheet)
       e.g. To set DAC_OUT1 to 0.7V, use
         DAC_SetChannel1Data(DAC_Align_12b_R, 868);
         Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
 
      *** DMA requests  ***
      =====================
      [..]    
      A DMA1 request can be generated when an external trigger (but not
      a software trigger) occurs if DMA1 requests are enabled using
      DAC_DMACmd()
      [..]
      DMA1 requests are mapped as following:
        (#) DAC channel1 : mapped on DMA1 Stream5 channel7 which must be 
            already configured
        (#) DAC channel2 : mapped on DMA1 Stream6 channel7 which must be 
            already configured
 
     
                     ##### How to use this driver #####
===============================================================================
   [..]          
     (+) DAC APB clock must be enabled to get write access to DAC
         registers using
         RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE)
     (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
     (+) Configure the DAC channel using DAC_Init() function
     (+) Enable the DAC channel using DAC_Cmd() function
Attention

© COPYRIGHT 2013 STMicroelectronics

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); You may not use this file except in compliance with the License. You may obtain a copy of the License at:

   http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file stm32f4xx_dac.c.