2 ******************************************************************************
3 * @file stm32f30x_dac.c
4 * @author MCD Application Team
7 * @brief This file provides firmware functions to manage the following
8 * functionalities of the Digital-to-Analog Converter (DAC) peripheral:
9 * + DAC channels configuration: trigger, output buffer, data format
11 * + Interrupts and flags management
15 ===============================================================================
16 ##### DAC Peripheral features #####
17 ===============================================================================
18 [..] The device integrates two 12-bit Digital Analog Converters that can
19 be used independently or simultaneously (dual mode):
20 (#) DAC1 integrates two DAC channels:
21 (++) DAC1 channel 1 with DAC1_OUT1 as output
22 (++) DAC1 channel 2 with DAC1_OUT2 as output
23 (++) The two channels can be used independently or simultaneously (dual mode)
25 (#) DAC2 integrates only one channel DAC2 channel 1 with DAC2_OUT1 as output
27 [..] Digital to Analog conversion can be non-triggered using DAC_Trigger_None
28 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register using
29 DAC_SetChannel1Data()/DAC_SetChannel2Data.
31 [..] Digital to Analog conversion can be triggered by:
32 (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_Trigger_Ext_IT9.
33 The used pin (GPIOx_Pin9) must be configured in input mode.
35 (#) Timers TRGO: TIM2, TIM8/TIM3, TIM4, TIM6, TIM7, and TIM15
36 (DAC_Trigger_T2_TRGO, DAC_Trigger_T4_TRGO...)
37 The timer TRGO event should be selected using TIM_SelectOutputTrigger()
38 (++) To trigger DAC conversions by TIM3 instead of TIM8 follow
40 (+++) Enable SYSCFG APB clock by calling
41 RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
42 (+++) Select DAC_Trigger_T3_TRGO when calling DAC_Init()
43 (+++) Remap the DAC trigger from TIM8 to TIM3 by calling
44 SYSCFG_TriggerRemapConfig(SYSCFG_TriggerRemap_DACTIM3, ENABLE)
45 (#) Software using DAC_Trigger_Software
47 [..] Each DAC channel integrates an output buffer that can be used to
48 reduce the output impedance, and to drive external loads directly
49 without having to add an external operational amplifier.
50 To enable, the output buffer use
51 DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
53 [..] Refer to the device datasheet for more details about output impedance
54 value with and without output buffer.
56 [..] Both DAC channels can be used to generate:
57 (+) Noise wave using DAC_WaveGeneration_Noise
58 (+) Triangle wave using DAC_WaveGeneration_Triangle
60 [..] Wave generation can be disabled using DAC_WaveGeneration_None
62 [..] The DAC data format can be:
63 (+) 8-bit right alignment using DAC_Align_8b_R
64 (+) 12-bit left alignment using DAC_Align_12b_L
65 (+) 12-bit right alignment using DAC_Align_12b_R
67 [..] The analog output voltage on each DAC channel pin is determined
68 by the following equation:
69 (+) DAC_OUTx = VREF+ * DOR / 4095 with DOR is the Data Output Register.
70 VREF+ is the input voltage reference (refer to the device datasheet)
71 e.g. To set DAC_OUT1 to 0.7V, use DAC_SetChannel1Data(DAC_Align_12b_R, 868);
72 Assuming that VREF+ = 3.3, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V
74 [..] A DMA1 request can be generated when an external trigger (but not
75 a software trigger) occurs if DMA1 requests are enabled using
77 DMA1 requests are mapped as following:
78 (+) DAC channel1 is mapped on DMA1 channel3 which must be already
80 (+) DAC channel2 is mapped on DMA1 channel4 which must be already
83 ##### How to use this driver #####
84 ===============================================================================
86 (+) Enable DAC APB1 clock to get write access to DAC registers
87 using RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE)
89 (+) Configure DACx_OUTy (DAC1_OUT1: PA4, DAC1_OUT2: PA5, DAC2_OUT1: PA6)
92 (+) Configure the DAC channel using DAC_Init()
94 (+) Enable the DAC channel using DAC_Cmd()
98 ******************************************************************************
101 * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2>
103 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
104 * You may not use this file except in compliance with the License.
105 * You may obtain a copy of the License at:
107 * http://www.st.com/software_license_agreement_liberty_v2
109 * Unless required by applicable law or agreed to in writing, software
110 * distributed under the License is distributed on an "AS IS" BASIS,
111 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
112 * See the License for the specific language governing permissions and
113 * limitations under the License.
115 ******************************************************************************
119 /* Includes ------------------------------------------------------------------*/
120 #include "stm32f30x_dac.h"
121 #include "stm32f30x_rcc.h"
123 /** @addtogroup STM32F30x_StdPeriph_Driver
128 * @brief DAC driver modules
132 /* Private typedef -----------------------------------------------------------*/
133 /* Private define ------------------------------------------------------------*/
135 /* CR register Mask */
136 #define CR_CLEAR_MASK ((uint32_t)0x00000FFE)
138 /* DAC Dual Channels SWTRIG masks */
139 #define DUAL_SWTRIG_SET ((uint32_t)0x00000003)
140 #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC)
142 /* DHR registers offsets */
143 #define DHR12R1_OFFSET ((uint32_t)0x00000008)
144 #define DHR12R2_OFFSET ((uint32_t)0x00000014)
145 #define DHR12RD_OFFSET ((uint32_t)0x00000020)
147 /* DOR register offset */
148 #define DOR_OFFSET ((uint32_t)0x0000002C)
150 /* Private macro -------------------------------------------------------------*/
151 /* Private variables ---------------------------------------------------------*/
152 /* Private function prototypes -----------------------------------------------*/
153 /* Private functions ---------------------------------------------------------*/
155 /** @defgroup DAC_Private_Functions
159 /** @defgroup DAC_Group1 DAC channels configuration
160 * @brief DAC channels configuration: trigger, output buffer, data format
163 ===============================================================================
164 ##### DAC channels configuration: trigger, output buffer, data format #####
165 ===============================================================================
172 * @brief Deinitializes the DAC peripheral registers to their default reset values.
173 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
176 void DAC_DeInit(DAC_TypeDef
* DACx
)
178 /* Check the parameters */
179 assert_param(IS_DAC_ALL_PERIPH(DACx
));
183 /* Enable DAC1 reset state */
184 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC1
, ENABLE
);
185 /* Release DAC1 from reset state */
186 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC1
, DISABLE
);
190 /* Enable DAC2 reset state */
191 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC2
, ENABLE
);
192 /* Release DAC2 from reset state */
193 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC2
, DISABLE
);
198 * @brief Initializes the DAC peripheral according to the specified
199 * parameters in the DAC_InitStruct.
200 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
201 * @param DAC_Channel: the selected DAC channel.
202 * This parameter can be one of the following values:
203 * @arg DAC_Channel_1: DAC Channel1 selected
204 * @arg DAC_Channel_2: DAC Channel2 selected
205 * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that
206 * contains the configuration information for the specified DAC channel.
209 void DAC_Init(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, DAC_InitTypeDef
* DAC_InitStruct
)
211 uint32_t tmpreg1
= 0, tmpreg2
= 0;
213 /* Check the DAC parameters */
214 assert_param(IS_DAC_ALL_PERIPH(DACx
));
215 assert_param(IS_DAC_TRIGGER(DAC_InitStruct
->DAC_Trigger
));
216 assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct
->DAC_WaveGeneration
));
217 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct
->DAC_LFSRUnmask_TriangleAmplitude
));
218 assert_param(IS_DAC_BUFFER_SWITCH_STATE(DAC_InitStruct
->DAC_Buffer_Switch
));
220 /*---------------------------- DAC CR Configuration --------------------------*/
221 /* Get the DAC CR value */
223 /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
224 tmpreg1
&= ~(CR_CLEAR_MASK
<< DAC_Channel
);
225 /* Configure for the selected DAC channel: buffer output, trigger, wave generation,
226 mask/amplitude for wave generation */
228 /* Set TSELx and TENx bits according to DAC_Trigger value */
229 /* Set WAVEx bits according to DAC_WaveGeneration value */
230 /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */
231 /* Set BOFFx OUTENx bit according to DAC_Buffer_Switch value */
232 tmpreg2
= (DAC_InitStruct
->DAC_Trigger
| DAC_InitStruct
->DAC_WaveGeneration
|
233 DAC_InitStruct
->DAC_LFSRUnmask_TriangleAmplitude
| DAC_InitStruct
->DAC_Buffer_Switch
);
235 /* Calculate CR register value depending on DAC_Channel */
236 tmpreg1
|= tmpreg2
<< DAC_Channel
;
237 /* Write to DAC CR */
242 * @brief Fills each DAC_InitStruct member with its default value.
243 * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure which will
247 void DAC_StructInit(DAC_InitTypeDef
* DAC_InitStruct
)
249 /*--------------- Reset DAC init structure parameters values -----------------*/
250 /* Initialize the DAC_Trigger member */
251 DAC_InitStruct
->DAC_Trigger
= DAC_Trigger_None
;
252 /* Initialize the DAC_WaveGeneration member */
253 DAC_InitStruct
->DAC_WaveGeneration
= DAC_WaveGeneration_None
;
254 /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */
255 DAC_InitStruct
->DAC_LFSRUnmask_TriangleAmplitude
= DAC_LFSRUnmask_Bit0
;
256 /* Initialize the DAC_Buffer_Switch member */
257 DAC_InitStruct
->DAC_Buffer_Switch
= DAC_BufferSwitch_Enable
;
261 * @brief Enables or disables the specified DAC channel.
262 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
263 * @param DAC_Channel: The selected DAC channel.
264 * This parameter can be one of the following values:
265 * @arg DAC_Channel_1: DAC Channel1 selected
266 * @arg DAC_Channel_2: DAC Channel2 selected
267 * @param NewState: new state of the DAC channel.
268 * This parameter can be: ENABLE or DISABLE.
269 * @note When the DAC channel is enabled the trigger source can no more
273 void DAC_Cmd(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, FunctionalState NewState
)
275 /* Check the parameters */
276 assert_param(IS_DAC_ALL_PERIPH(DACx
));
277 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
278 assert_param(IS_FUNCTIONAL_STATE(NewState
));
280 if (NewState
!= DISABLE
)
282 /* Enable the selected DAC channel */
283 DACx
->CR
|= (DAC_CR_EN1
<< DAC_Channel
);
287 /* Disable the selected DAC channel */
288 DACx
->CR
&= (~(DAC_CR_EN1
<< DAC_Channel
));
293 * @brief Enables or disables the selected DAC channel software trigger.
294 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
295 * @param DAC_Channel: the selected DAC channel.
296 * This parameter can be one of the following values:
297 * @arg DAC_Channel_1: DAC Channel1 selected
298 * @arg DAC_Channel_2: DAC Channel2 selected
299 * @param NewState: new state of the selected DAC channel software trigger.
300 * This parameter can be: ENABLE or DISABLE.
303 void DAC_SoftwareTriggerCmd(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, FunctionalState NewState
)
305 /* Check the parameters */
306 assert_param(IS_DAC_ALL_PERIPH(DACx
));
307 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
308 assert_param(IS_FUNCTIONAL_STATE(NewState
));
310 if (NewState
!= DISABLE
)
312 /* Enable software trigger for the selected DAC channel */
313 DACx
->SWTRIGR
|= (uint32_t)DAC_SWTRIGR_SWTRIG1
<< (DAC_Channel
>> 4);
317 /* Disable software trigger for the selected DAC channel */
318 DACx
->SWTRIGR
&= ~((uint32_t)DAC_SWTRIGR_SWTRIG1
<< (DAC_Channel
>> 4));
323 * @brief Enables or disables simultaneously the two DAC channels software
325 * @param DACx: where x can be 1 to select the DAC1 peripheral.
326 * @note Dual trigger is not applicable for DAC2 (DAC2 integrates one channel).
327 * @param NewState: new state of the DAC channels software triggers.
328 * This parameter can be: ENABLE or DISABLE.
331 void DAC_DualSoftwareTriggerCmd(DAC_TypeDef
* DACx
, FunctionalState NewState
)
333 /* Check the parameters */
334 assert_param(IS_DAC_LIST1_PERIPH(DACx
));
335 assert_param(IS_FUNCTIONAL_STATE(NewState
));
337 if (NewState
!= DISABLE
)
339 /* Enable software trigger for both DAC channels */
340 DACx
->SWTRIGR
|= DUAL_SWTRIG_SET
;
344 /* Disable software trigger for both DAC channels */
345 DACx
->SWTRIGR
&= DUAL_SWTRIG_RESET
;
350 * @brief Enables or disables the selected DAC channel wave generation.
351 * @param DACx: where x can be 1 to select the DAC1 peripheral.
352 * @note Wave generation is not available in DAC2.
353 * @param DAC_Channel: the selected DAC channel.
354 * This parameter can be one of the following values:
355 * @arg DAC_Channel_1: DAC Channel1 selected
356 * @arg DAC_Channel_2: DAC Channel2 selected
357 * @param DAC_Wave: Specifies the wave type to enable or disable.
358 * This parameter can be one of the following values:
359 * @arg DAC_Wave_Noise: noise wave generation
360 * @arg DAC_Wave_Triangle: triangle wave generation
361 * @param NewState: new state of the selected DAC channel wave generation.
362 * This parameter can be: ENABLE or DISABLE.
366 void DAC_WaveGenerationCmd(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, uint32_t DAC_Wave
, FunctionalState NewState
)
368 /* Check the parameters */
369 assert_param(IS_DAC_LIST1_PERIPH(DACx
));
370 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
371 assert_param(IS_DAC_WAVE(DAC_Wave
));
372 assert_param(IS_FUNCTIONAL_STATE(NewState
));
374 if (NewState
!= DISABLE
)
376 /* Enable the selected wave generation for the selected DAC channel */
377 DACx
->CR
|= DAC_Wave
<< DAC_Channel
;
381 /* Disable the selected wave generation for the selected DAC channel */
382 DACx
->CR
&= ~(DAC_Wave
<< DAC_Channel
);
387 * @brief Set the specified data holding register value for DAC channel1.
388 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
389 * @param DAC_Align: Specifies the data alignment for DAC channel1.
390 * This parameter can be one of the following values:
391 * @arg DAC_Align_8b_R: 8bit right data alignment selected
392 * @arg DAC_Align_12b_L: 12bit left data alignment selected
393 * @arg DAC_Align_12b_R: 12bit right data alignment selected
394 * @param Data: Data to be loaded in the selected data holding register.
397 void DAC_SetChannel1Data(DAC_TypeDef
* DACx
, uint32_t DAC_Align
, uint16_t Data
)
399 __IO
uint32_t tmp
= 0;
401 /* Check the parameters */
402 assert_param(IS_DAC_ALL_PERIPH(DACx
));
403 assert_param(IS_DAC_ALIGN(DAC_Align
));
404 assert_param(IS_DAC_DATA(Data
));
406 tmp
= (uint32_t)DACx
;
407 tmp
+= DHR12R1_OFFSET
+ DAC_Align
;
409 /* Set the DAC channel1 selected data holding register */
410 *(__IO
uint32_t *) tmp
= Data
;
414 * @brief Set the specified data holding register value for DAC channel2.
415 * @param DACx: where x can be 1 to select the DAC peripheral.
416 * @note This function is available only for DAC1.
417 * @param DAC_Align: Specifies the data alignment for DAC channel2.
418 * This parameter can be one of the following values:
419 * @arg DAC_Align_8b_R: 8bit right data alignment selected
420 * @arg DAC_Align_12b_L: 12bit left data alignment selected
421 * @arg DAC_Align_12b_R: 12bit right data alignment selected
422 * @param Data : Data to be loaded in the selected data holding register.
425 void DAC_SetChannel2Data(DAC_TypeDef
* DACx
, uint32_t DAC_Align
, uint16_t Data
)
427 __IO
uint32_t tmp
= 0;
429 /* Check the parameters */
430 assert_param(IS_DAC_LIST1_PERIPH(DACx
));
431 assert_param(IS_DAC_ALIGN(DAC_Align
));
432 assert_param(IS_DAC_DATA(Data
));
434 tmp
= (uint32_t)DACx
;
435 tmp
+= DHR12R2_OFFSET
+ DAC_Align
;
437 /* Set the DAC channel2 selected data holding register */
438 *(__IO
uint32_t *)tmp
= Data
;
442 * @brief Set the specified data holding register value for dual channel DAC.
443 * @param DACx: where x can be 1 to select the DAC peripheral.
444 * @note This function isn't applicable for DAC2.
445 * @param DAC_Align: Specifies the data alignment for dual channel DAC.
446 * This parameter can be one of the following values:
447 * @arg DAC_Align_8b_R: 8bit right data alignment selected
448 * @arg DAC_Align_12b_L: 12bit left data alignment selected
449 * @arg DAC_Align_12b_R: 12bit right data alignment selected
450 * @param Data2: Data for DAC Channel2 to be loaded in the selected data
452 * @param Data1: Data for DAC Channel1 to be loaded in the selected data
454 * @note In dual mode, a unique register access is required to write in both
455 * DAC channels at the same time.
458 void DAC_SetDualChannelData(DAC_TypeDef
* DACx
, uint32_t DAC_Align
, uint16_t Data2
, uint16_t Data1
)
460 uint32_t data
= 0, tmp
= 0;
462 /* Check the parameters */
463 assert_param(IS_DAC_LIST1_PERIPH(DACx
));
464 assert_param(IS_DAC_ALIGN(DAC_Align
));
465 assert_param(IS_DAC_DATA(Data1
));
466 assert_param(IS_DAC_DATA(Data2
));
468 /* Calculate and set dual DAC data holding register value */
469 if (DAC_Align
== DAC_Align_8b_R
)
471 data
= ((uint32_t)Data2
<< 8) | Data1
;
475 data
= ((uint32_t)Data2
<< 16) | Data1
;
478 tmp
= (uint32_t)DACx
;
479 tmp
+= DHR12RD_OFFSET
+ DAC_Align
;
481 /* Set the dual DAC selected data holding register */
482 *(__IO
uint32_t *)tmp
= data
;
486 * @brief Returns the last data output value of the selected DAC channel.
487 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
488 * @param DAC_Channel: the selected DAC channel.
489 * This parameter can be one of the following values:
490 * @arg DAC_Channel_1: DAC Channel1 selected
491 * @arg DAC_Channel_2: DAC Channel2 selected
492 * @retval The selected DAC channel data output value.
494 uint16_t DAC_GetDataOutputValue(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
)
496 __IO
uint32_t tmp
= 0;
498 /* Check the parameters */
499 assert_param(IS_DAC_ALL_PERIPH(DACx
));
500 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
502 tmp
= (uint32_t) DACx
;
503 tmp
+= DOR_OFFSET
+ ((uint32_t)DAC_Channel
>> 2);
505 /* Returns the DAC channel data output register value */
506 return (uint16_t) (*(__IO
uint32_t*) tmp
);
513 /** @defgroup DAC_Group2 DMA management functions
514 * @brief DMA management functions
517 ===============================================================================
518 ##### DMA management functions #####
519 ===============================================================================
526 * @brief Enables or disables the specified DAC channel DMA request.
527 * When enabled DMA1 is generated when an external trigger (EXTI Line9,
528 * TIM2, TIM4, TIM6, TIM7 or TIM9 but not a software trigger) occurs
529 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
530 * @param DAC_Channel: the selected DAC channel.
531 * This parameter can be one of the following values:
532 * @arg DAC_Channel_1: DAC Channel1 selected
533 * @arg DAC_Channel_2: DAC Channel2 selected
534 * @param NewState: new state of the selected DAC channel DMA request.
535 * This parameter can be: ENABLE or DISABLE.
536 * @note The DAC channel1 (channel2) is mapped on DMA1 channel3 (channel4) which
537 * must be already configured.
540 void DAC_DMACmd(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, FunctionalState NewState
)
542 /* Check the parameters */
543 assert_param(IS_DAC_ALL_PERIPH(DACx
));
544 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
545 assert_param(IS_FUNCTIONAL_STATE(NewState
));
547 if (NewState
!= DISABLE
)
549 /* Enable the selected DAC channel DMA request */
550 DACx
->CR
|= (DAC_CR_DMAEN1
<< DAC_Channel
);
554 /* Disable the selected DAC channel DMA request */
555 DACx
->CR
&= (~(DAC_CR_DMAEN1
<< DAC_Channel
));
563 /** @defgroup DAC_Group3 Interrupts and flags management functions
564 * @brief Interrupts and flags management functions
567 ===============================================================================
568 ##### Interrupts and flags management functions #####
569 ===============================================================================
576 * @brief Enables or disables the specified DAC interrupts.
577 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
578 * @param DAC_Channel: the selected DAC channel.
579 * This parameter can be one of the following values:
580 * @arg DAC_Channel_1: DAC Channel1 selected
581 * @arg DAC_Channel_2: DAC Channel2 selected
582 * @param DAC_IT: specifies the DAC interrupt sources to be enabled or disabled.
583 * This parameter can be:
584 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
585 * @note The DMA underrun occurs when a second external trigger arrives before
586 * the acknowledgement for the first external trigger is received (first request).
587 * @param NewState: new state of the specified DAC interrupts.
588 * This parameter can be: ENABLE or DISABLE.
591 void DAC_ITConfig(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, uint32_t DAC_IT
, FunctionalState NewState
)
593 /* Check the parameters */
594 assert_param(IS_DAC_ALL_PERIPH(DACx
));
595 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
596 assert_param(IS_FUNCTIONAL_STATE(NewState
));
597 assert_param(IS_DAC_IT(DAC_IT
));
599 if (NewState
!= DISABLE
)
601 /* Enable the selected DAC interrupts */
602 DACx
->CR
|= (DAC_IT
<< DAC_Channel
);
606 /* Disable the selected DAC interrupts */
607 DACx
->CR
&= (~(uint32_t)(DAC_IT
<< DAC_Channel
));
612 * @brief Checks whether the specified DAC flag is set or not.
613 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
614 * @param DAC_Channel: thee selected DAC channel.
615 * This parameter can be one of the following values:
616 * @arg DAC_Channel_1: DAC Channel1 selected
617 * @arg DAC_Channel_2: DAC Channel2 selected
618 * @param DAC_FLAG: specifies the flag to check.
619 * This parameter can be:
620 * @arg DAC_FLAG_DMAUDR: DMA underrun flag
621 * @note The DMA underrun occurs when a second external trigger arrives before
622 * the acknowledgement for the first external trigger is received (first request).
623 * @retval The new state of DAC_FLAG (SET or RESET).
625 FlagStatus
DAC_GetFlagStatus(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, uint32_t DAC_FLAG
)
627 FlagStatus bitstatus
= RESET
;
629 /* Check the parameters */
630 assert_param(IS_DAC_ALL_PERIPH(DACx
));
631 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
632 assert_param(IS_DAC_FLAG(DAC_FLAG
));
634 /* Check the status of the specified DAC flag */
635 if ((DACx
->SR
& (DAC_FLAG
<< DAC_Channel
)) != (uint8_t)RESET
)
637 /* DAC_FLAG is set */
642 /* DAC_FLAG is reset */
645 /* Return the DAC_FLAG status */
650 * @brief Clears the DAC channel's pending flags.
651 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
652 * @param DAC_Channel: the selected DAC channel.
653 * This parameter can be one of the following values:
654 * @arg DAC_Channel_1: DAC Channel1 selected
655 * @arg DAC_Channel_2: DAC Channel2 selected
656 * @param DAC_FLAG: specifies the flag to clear.
657 * This parameter can be:
658 * @arg DAC_FLAG_DMAUDR: DMA underrun flag
661 void DAC_ClearFlag(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, uint32_t DAC_FLAG
)
663 /* Check the parameters */
664 assert_param(IS_DAC_ALL_PERIPH(DACx
));
665 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
666 assert_param(IS_DAC_FLAG(DAC_FLAG
));
668 /* Clear the selected DAC flags */
669 DACx
->SR
= (DAC_FLAG
<< DAC_Channel
);
673 * @brief Checks whether the specified DAC interrupt has occurred or not.
674 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
675 * @param DAC_Channel: the selected DAC channel.
676 * This parameter can be one of the following values:
677 * @arg DAC_Channel_1: DAC Channel1 selected
678 * @arg DAC_Channel_2: DAC Channel2 selected
679 * @param DAC_IT: specifies the DAC interrupt source to check.
680 * This parameter can be:
681 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
682 * @note The DMA underrun occurs when a second external trigger arrives before
683 * the acknowledgement for the first external trigger is received (first request).
684 * @retval The new state of DAC_IT (SET or RESET).
686 ITStatus
DAC_GetITStatus(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, uint32_t DAC_IT
)
688 ITStatus bitstatus
= RESET
;
689 uint32_t enablestatus
= 0;
691 /* Check the parameters */
692 assert_param(IS_DAC_ALL_PERIPH(DACx
));
693 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
694 assert_param(IS_DAC_IT(DAC_IT
));
696 /* Get the DAC_IT enable bit status */
697 enablestatus
= (DACx
->CR
& (DAC_IT
<< DAC_Channel
)) ;
699 /* Check the status of the specified DAC interrupt */
700 if (((DACx
->SR
& (DAC_IT
<< DAC_Channel
)) != (uint32_t)RESET
) && enablestatus
)
707 /* DAC_IT is reset */
710 /* Return the DAC_IT status */
715 * @brief Clears the DAC channel's interrupt pending bits.
716 * @param DACx: where x can be 1 or 2 to select the DAC peripheral.
717 * @param DAC_Channel: the selected DAC channel.
718 * This parameter can be one of the following values:
719 * @arg DAC_Channel_1: DAC Channel1 selected
720 * @arg DAC_Channel_2: DAC Channel2 selected
721 * @param DAC_IT: specifies the DAC interrupt pending bit to clear.
722 * This parameter can be the following values:
723 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
726 void DAC_ClearITPendingBit(DAC_TypeDef
* DACx
, uint32_t DAC_Channel
, uint32_t DAC_IT
)
728 /* Check the parameters */
729 assert_param(IS_DAC_ALL_PERIPH(DACx
));
730 assert_param(IS_DAC_CHANNEL(DAC_Channel
));
731 assert_param(IS_DAC_IT(DAC_IT
));
733 /* Clear the selected DAC interrupt pending bits */
734 DACx
->SR
= (DAC_IT
<< DAC_Channel
);
753 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/