2 ******************************************************************************
\r
3 * @file stm32l1xx_dac.c
\r
4 * @author MCD Application Team
\r
6 * @date 05-March-2012
\r
7 * @brief This file provides firmware functions to manage the following
\r
8 * functionalities of the Digital-to-Analog Converter (DAC) peripheral:
\r
9 * + DAC channels configuration: trigger, output buffer, data format
\r
11 * + Interrupts and flags management
\r
15 ===============================================================================
\r
16 ##### DAC Peripheral features #####
\r
17 ===============================================================================
\r
18 [..] The device integrates two 12-bit Digital Analog Converters that can
\r
19 be used independently or simultaneously (dual mode):
\r
20 (#) DAC channel1 with DAC_OUT1 (PA4) as output.
\r
21 (#) DAC channel2 with DAC_OUT2 (PA5) as output.
\r
23 [..] Digital to Analog conversion can be non-triggered using DAC_Trigger_None
\r
24 and DAC_OUT1/DAC_OUT2 is available once writing to DHRx register using
\r
25 DAC_SetChannel1Data()/DAC_SetChannel2Data.
\r
27 [..] Digital to Analog conversion can be triggered by:
\r
28 (#) External event: EXTI Line 9 (any GPIOx_Pin9) using DAC_Trigger_Ext_IT9.
\r
29 The used pin (GPIOx_Pin9) must be configured in input mode.
\r
30 (#) Timers TRGO: TIM2, TIM4, TIM6, TIM7 and TIM9
\r
31 (DAC_Trigger_T2_TRGO, DAC_Trigger_T4_TRGO...).
\r
32 The timer TRGO event should be selected using TIM_SelectOutputTrigger()
\r
33 (#) Software using DAC_Trigger_Software.
\r
35 [..] Each DAC channel integrates an output buffer that can be used to
\r
36 reduce the output impedance, and to drive external loads directly
\r
37 without having to add an external operational amplifier.
\r
38 To enable, the output buffer use
\r
39 DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
\r
41 [..] Refer to the device datasheet for more details about output impedance
\r
42 value with and without output buffer.
\r
44 [..] Both DAC channels can be used to generate:
\r
45 (#) Noise wave using DAC_WaveGeneration_Noise
\r
46 (#) Triangle wave using DAC_WaveGeneration_Triangle
\r
48 [..] Wave generation can be disabled using DAC_WaveGeneration_None.
\r
50 [..] The DAC data format can be:
\r
51 (#) 8-bit right alignment using DAC_Align_8b_R
\r
52 (#) 12-bit left alignment using DAC_Align_12b_L
\r
53 (#) 12-bit right alignment using DAC_Align_12b_R
\r
55 [..] The analog output voltage on each DAC channel pin is determined
\r
56 by the following equation: DAC_OUTx = VREF+ * DOR / 4095
\r
57 with DOR is the Data Output Register.
\r
58 VEF+ is the input voltage reference (refer to the device datasheet)
\r
59 e.g. To set DAC_OUT1 to 0.7V, use
\r
60 DAC_SetChannel1Data(DAC_Align_12b_R, 868);
\r
61 Assuming that VREF+ = 3.3, DAC_OUT1 = (3.3 * 868) / 4095 = 0.7V.
\r
63 [..] A DMA1 request can be generated when an external trigger (but not
\r
64 a software trigger) occurs if DMA1 requests are enabled using
\r
66 [..] DMA1 requests are mapped as following:
\r
67 (#) DAC channel1 is mapped on DMA1 channel3 which must be already
\r
69 (#) DAC channel2 is mapped on DMA1 channel4 which must be already
\r
72 ##### How to use this driver #####
\r
73 ===============================================================================
\r
75 (+) DAC APB clock must be enabled to get write access to DAC registers using
\r
76 RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE)
\r
77 (+) Configure DAC_OUTx (DAC_OUT1: PA4, DAC_OUT2: PA5) in analog mode.
\r
78 (+) Configure the DAC channel using DAC_Init()
\r
79 (+) Enable the DAC channel using DAC_Cmd()
\r
83 ******************************************************************************
\r
86 * <h2><center>© COPYRIGHT 2012 STMicroelectronics</center></h2>
\r
88 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
\r
89 * You may not use this file except in compliance with the License.
\r
90 * You may obtain a copy of the License at:
\r
92 * http://www.st.com/software_license_agreement_liberty_v2
\r
94 * Unless required by applicable law or agreed to in writing, software
\r
95 * distributed under the License is distributed on an "AS IS" BASIS,
\r
96 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
97 * See the License for the specific language governing permissions and
\r
98 * limitations under the License.
\r
100 ******************************************************************************
\r
103 /* Includes ------------------------------------------------------------------*/
\r
104 #include "stm32l1xx_dac.h"
\r
105 #include "stm32l1xx_rcc.h"
\r
107 /** @addtogroup STM32L1xx_StdPeriph_Driver
\r
112 * @brief DAC driver modules
\r
116 /* Private typedef -----------------------------------------------------------*/
\r
117 /* Private define ------------------------------------------------------------*/
\r
118 /* CR register Mask */
\r
119 #define CR_CLEAR_MASK ((uint32_t)0x00000FFE)
\r
121 /* DAC Dual Channels SWTRIG masks */
\r
122 #define DUAL_SWTRIG_SET ((uint32_t)0x00000003)
\r
123 #define DUAL_SWTRIG_RESET ((uint32_t)0xFFFFFFFC)
\r
125 /* DHR registers offsets */
\r
126 #define DHR12R1_OFFSET ((uint32_t)0x00000008)
\r
127 #define DHR12R2_OFFSET ((uint32_t)0x00000014)
\r
128 #define DHR12RD_OFFSET ((uint32_t)0x00000020)
\r
130 /* DOR register offset */
\r
131 #define DOR_OFFSET ((uint32_t)0x0000002C)
\r
133 /* Private macro -------------------------------------------------------------*/
\r
134 /* Private variables ---------------------------------------------------------*/
\r
135 /* Private function prototypes -----------------------------------------------*/
\r
136 /* Private functions ---------------------------------------------------------*/
\r
138 /** @defgroup DAC_Private_Functions
\r
142 /** @defgroup DAC_Group1 DAC channels configuration
\r
143 * @brief DAC channels configuration: trigger, output buffer, data format.
\r
146 ===============================================================================
\r
147 ##### DAC channels configuration: trigger, output buffer, data format #####
\r
148 ===============================================================================
\r
155 * @brief Deinitializes the DAC peripheral registers to their default reset values.
\r
159 void DAC_DeInit(void)
\r
161 /* Enable DAC reset state */
\r
162 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, ENABLE);
\r
163 /* Release DAC from reset state */
\r
164 RCC_APB1PeriphResetCmd(RCC_APB1Periph_DAC, DISABLE);
\r
168 * @brief Initializes the DAC peripheral according to the specified
\r
169 * parameters in the DAC_InitStruct.
\r
170 * @param DAC_Channel: the selected DAC channel.
\r
171 * This parameter can be one of the following values:
\r
172 * @arg DAC_Channel_1: DAC Channel1 selected.
\r
173 * @arg DAC_Channel_2: DAC Channel2 selected.
\r
174 * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure that
\r
175 * contains the configuration information for the specified DAC channel.
\r
178 void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct)
\r
180 uint32_t tmpreg1 = 0, tmpreg2 = 0;
\r
182 /* Check the DAC parameters */
\r
183 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
184 assert_param(IS_DAC_TRIGGER(DAC_InitStruct->DAC_Trigger));
\r
185 assert_param(IS_DAC_GENERATE_WAVE(DAC_InitStruct->DAC_WaveGeneration));
\r
186 assert_param(IS_DAC_LFSR_UNMASK_TRIANGLE_AMPLITUDE(DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude));
\r
187 assert_param(IS_DAC_OUTPUT_BUFFER_STATE(DAC_InitStruct->DAC_OutputBuffer));
\r
189 /*---------------------------- DAC CR Configuration --------------------------*/
\r
190 /* Get the DAC CR value */
\r
192 /* Clear BOFFx, TENx, TSELx, WAVEx and MAMPx bits */
\r
193 tmpreg1 &= ~(CR_CLEAR_MASK << DAC_Channel);
\r
194 /* Configure for the selected DAC channel: buffer output, trigger, wave generation,
\r
195 mask/amplitude for wave generation */
\r
196 /* Set TSELx and TENx bits according to DAC_Trigger value */
\r
197 /* Set WAVEx bits according to DAC_WaveGeneration value */
\r
198 /* Set MAMPx bits according to DAC_LFSRUnmask_TriangleAmplitude value */
\r
199 /* Set BOFFx bit according to DAC_OutputBuffer value */
\r
200 tmpreg2 = (DAC_InitStruct->DAC_Trigger | DAC_InitStruct->DAC_WaveGeneration |
\r
201 DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude | DAC_InitStruct->DAC_OutputBuffer);
\r
202 /* Calculate CR register value depending on DAC_Channel */
\r
203 tmpreg1 |= tmpreg2 << DAC_Channel;
\r
204 /* Write to DAC CR */
\r
209 * @brief Fills each DAC_InitStruct member with its default value.
\r
210 * @param DAC_InitStruct: pointer to a DAC_InitTypeDef structure which will
\r
214 void DAC_StructInit(DAC_InitTypeDef* DAC_InitStruct)
\r
216 /*--------------- Reset DAC init structure parameters values -----------------*/
\r
217 /* Initialize the DAC_Trigger member */
\r
218 DAC_InitStruct->DAC_Trigger = DAC_Trigger_None;
\r
219 /* Initialize the DAC_WaveGeneration member */
\r
220 DAC_InitStruct->DAC_WaveGeneration = DAC_WaveGeneration_None;
\r
221 /* Initialize the DAC_LFSRUnmask_TriangleAmplitude member */
\r
222 DAC_InitStruct->DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
\r
223 /* Initialize the DAC_OutputBuffer member */
\r
224 DAC_InitStruct->DAC_OutputBuffer = DAC_OutputBuffer_Enable;
\r
228 * @brief Enables or disables the specified DAC channel.
\r
229 * @param DAC_Channel: The selected DAC channel.
\r
230 * This parameter can be one of the following values:
\r
231 * @arg DAC_Channel_1: DAC Channel1 selected
\r
232 * @arg DAC_Channel_2: DAC Channel2 selected
\r
233 * @param NewState: new state of the DAC channel.
\r
234 * This parameter can be: ENABLE or DISABLE.
\r
235 * @note When the DAC channel is enabled the trigger source can no more
\r
239 void DAC_Cmd(uint32_t DAC_Channel, FunctionalState NewState)
\r
241 /* Check the parameters */
\r
242 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
243 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
245 if (NewState != DISABLE)
\r
247 /* Enable the selected DAC channel */
\r
248 DAC->CR |= (DAC_CR_EN1 << DAC_Channel);
\r
252 /* Disable the selected DAC channel */
\r
253 DAC->CR &= (~(DAC_CR_EN1 << DAC_Channel));
\r
258 * @brief Enables or disables the selected DAC channel software trigger.
\r
259 * @param DAC_Channel: the selected DAC channel.
\r
260 * This parameter can be one of the following values:
\r
261 * @arg DAC_Channel_1: DAC Channel1 selected
\r
262 * @arg DAC_Channel_2: DAC Channel2 selected
\r
263 * @param NewState: new state of the selected DAC channel software trigger.
\r
264 * This parameter can be: ENABLE or DISABLE.
\r
267 void DAC_SoftwareTriggerCmd(uint32_t DAC_Channel, FunctionalState NewState)
\r
269 /* Check the parameters */
\r
270 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
271 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
273 if (NewState != DISABLE)
\r
275 /* Enable software trigger for the selected DAC channel */
\r
276 DAC->SWTRIGR |= (uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4);
\r
280 /* Disable software trigger for the selected DAC channel */
\r
281 DAC->SWTRIGR &= ~((uint32_t)DAC_SWTRIGR_SWTRIG1 << (DAC_Channel >> 4));
\r
286 * @brief Enables or disables simultaneously the two DAC channels software
\r
288 * @param NewState: new state of the DAC channels software triggers.
\r
289 * This parameter can be: ENABLE or DISABLE.
\r
292 void DAC_DualSoftwareTriggerCmd(FunctionalState NewState)
\r
294 /* Check the parameters */
\r
295 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
297 if (NewState != DISABLE)
\r
299 /* Enable software trigger for both DAC channels */
\r
300 DAC->SWTRIGR |= DUAL_SWTRIG_SET;
\r
304 /* Disable software trigger for both DAC channels */
\r
305 DAC->SWTRIGR &= DUAL_SWTRIG_RESET;
\r
310 * @brief Enables or disables the selected DAC channel wave generation.
\r
311 * @param DAC_Channel: the selected DAC channel.
\r
312 * This parameter can be one of the following values:
\r
313 * @arg DAC_Channel_1: DAC Channel1 selected
\r
314 * @arg DAC_Channel_2: DAC Channel2 selected
\r
315 * @param DAC_Wave: Specifies the wave type to enable or disable.
\r
316 * This parameter can be one of the following values:
\r
317 * @arg DAC_Wave_Noise: noise wave generation
\r
318 * @arg DAC_Wave_Triangle: triangle wave generation
\r
319 * @param NewState: new state of the selected DAC channel wave generation.
\r
320 * This parameter can be: ENABLE or DISABLE.
\r
324 void DAC_WaveGenerationCmd(uint32_t DAC_Channel, uint32_t DAC_Wave, FunctionalState NewState)
\r
326 /* Check the parameters */
\r
327 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
328 assert_param(IS_DAC_WAVE(DAC_Wave));
\r
329 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
331 if (NewState != DISABLE)
\r
333 /* Enable the selected wave generation for the selected DAC channel */
\r
334 DAC->CR |= DAC_Wave << DAC_Channel;
\r
338 /* Disable the selected wave generation for the selected DAC channel */
\r
339 DAC->CR &= ~(DAC_Wave << DAC_Channel);
\r
344 * @brief Set the specified data holding register value for DAC channel1.
\r
345 * @param DAC_Align: Specifies the data alignment for DAC channel1.
\r
346 * This parameter can be one of the following values:
\r
347 * @arg DAC_Align_8b_R: 8bit right data alignment selected
\r
348 * @arg DAC_Align_12b_L: 12bit left data alignment selected
\r
349 * @arg DAC_Align_12b_R: 12bit right data alignment selected
\r
350 * @param Data : Data to be loaded in the selected data holding register.
\r
353 void DAC_SetChannel1Data(uint32_t DAC_Align, uint16_t Data)
\r
355 __IO uint32_t tmp = 0;
\r
357 /* Check the parameters */
\r
358 assert_param(IS_DAC_ALIGN(DAC_Align));
\r
359 assert_param(IS_DAC_DATA(Data));
\r
361 tmp = (uint32_t)DAC_BASE;
\r
362 tmp += DHR12R1_OFFSET + DAC_Align;
\r
364 /* Set the DAC channel1 selected data holding register */
\r
365 *(__IO uint32_t *) tmp = Data;
\r
369 * @brief Set the specified data holding register value for DAC channel2.
\r
370 * @param DAC_Align: Specifies the data alignment for DAC channel2.
\r
371 * This parameter can be one of the following values:
\r
372 * @arg DAC_Align_8b_R: 8bit right data alignment selected
\r
373 * @arg DAC_Align_12b_L: 12bit left data alignment selected
\r
374 * @arg DAC_Align_12b_R: 12bit right data alignment selected
\r
375 * @param Data : Data to be loaded in the selected data holding register.
\r
378 void DAC_SetChannel2Data(uint32_t DAC_Align, uint16_t Data)
\r
380 __IO uint32_t tmp = 0;
\r
382 /* Check the parameters */
\r
383 assert_param(IS_DAC_ALIGN(DAC_Align));
\r
384 assert_param(IS_DAC_DATA(Data));
\r
386 tmp = (uint32_t)DAC_BASE;
\r
387 tmp += DHR12R2_OFFSET + DAC_Align;
\r
389 /* Set the DAC channel2 selected data holding register */
\r
390 *(__IO uint32_t *)tmp = Data;
\r
394 * @brief Set the specified data holding register value for dual channel DAC.
\r
395 * @param DAC_Align: Specifies the data alignment for dual channel DAC.
\r
396 * This parameter can be one of the following values:
\r
397 * @arg DAC_Align_8b_R: 8bit right data alignment selected
\r
398 * @arg DAC_Align_12b_L: 12bit left data alignment selected
\r
399 * @arg DAC_Align_12b_R: 12bit right data alignment selected
\r
400 * @param Data2: Data for DAC Channel2 to be loaded in the selected data
\r
401 * holding register.
\r
402 * @param Data1: Data for DAC Channel1 to be loaded in the selected data
\r
403 * holding register.
\r
404 * @note In dual mode, a unique register access is required to write in both
\r
405 * DAC channels at the same time.
\r
408 void DAC_SetDualChannelData(uint32_t DAC_Align, uint16_t Data2, uint16_t Data1)
\r
410 uint32_t data = 0, tmp = 0;
\r
412 /* Check the parameters */
\r
413 assert_param(IS_DAC_ALIGN(DAC_Align));
\r
414 assert_param(IS_DAC_DATA(Data1));
\r
415 assert_param(IS_DAC_DATA(Data2));
\r
417 /* Calculate and set dual DAC data holding register value */
\r
418 if (DAC_Align == DAC_Align_8b_R)
\r
420 data = ((uint32_t)Data2 << 8) | Data1;
\r
424 data = ((uint32_t)Data2 << 16) | Data1;
\r
427 tmp = (uint32_t)DAC_BASE;
\r
428 tmp += DHR12RD_OFFSET + DAC_Align;
\r
430 /* Set the dual DAC selected data holding register */
\r
431 *(__IO uint32_t *)tmp = data;
\r
435 * @brief Returns the last data output value of the selected DAC channel.
\r
436 * @param DAC_Channel: the selected DAC channel.
\r
437 * This parameter can be one of the following values:
\r
438 * @arg DAC_Channel_1: DAC Channel1 selected
\r
439 * @arg DAC_Channel_2: DAC Channel2 selected
\r
440 * @retval The selected DAC channel data output value.
\r
442 uint16_t DAC_GetDataOutputValue(uint32_t DAC_Channel)
\r
444 __IO uint32_t tmp = 0;
\r
446 /* Check the parameters */
\r
447 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
449 tmp = (uint32_t) DAC_BASE ;
\r
450 tmp += DOR_OFFSET + ((uint32_t)DAC_Channel >> 2);
\r
452 /* Returns the DAC channel data output register value */
\r
453 return (uint16_t) (*(__IO uint32_t*) tmp);
\r
460 /** @defgroup DAC_Group2 DMA management functions
\r
461 * @brief DMA management functions
\r
464 ===============================================================================
\r
465 ##### DMA management functions #####
\r
466 ===============================================================================
\r
473 * @brief Enables or disables the specified DAC channel DMA request.
\r
474 * When enabled DMA1 is generated when an external trigger (EXTI Line9,
\r
475 * TIM2, TIM4, TIM6, TIM7 or TIM9 but not a software trigger) occurs.
\r
476 * @param DAC_Channel: the selected DAC channel.
\r
477 * This parameter can be one of the following values:
\r
478 * @arg DAC_Channel_1: DAC Channel1 selected
\r
479 * @arg DAC_Channel_2: DAC Channel2 selected
\r
480 * @param NewState: new state of the selected DAC channel DMA request.
\r
481 * This parameter can be: ENABLE or DISABLE.
\r
482 * @note The DAC channel1 (channel2) is mapped on DMA1 channel3 (channel4) which
\r
483 * must be already configured.
\r
486 void DAC_DMACmd(uint32_t DAC_Channel, FunctionalState NewState)
\r
488 /* Check the parameters */
\r
489 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
490 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
492 if (NewState != DISABLE)
\r
494 /* Enable the selected DAC channel DMA request */
\r
495 DAC->CR |= (DAC_CR_DMAEN1 << DAC_Channel);
\r
499 /* Disable the selected DAC channel DMA request */
\r
500 DAC->CR &= (~(DAC_CR_DMAEN1 << DAC_Channel));
\r
508 /** @defgroup DAC_Group3 Interrupts and flags management functions
\r
509 * @brief Interrupts and flags management functions
\r
512 ===============================================================================
\r
513 ##### Interrupts and flags management functions #####
\r
514 ===============================================================================
\r
521 * @brief Enables or disables the specified DAC interrupts.
\r
522 * @param DAC_Channel: the selected DAC channel.
\r
523 * This parameter can be one of the following values:
\r
524 * @arg DAC_Channel_1: DAC Channel1 selected
\r
525 * @arg DAC_Channel_2: DAC Channel2 selected
\r
526 * @param DAC_IT: specifies the DAC interrupt sources to be enabled or disabled.
\r
527 * This parameter can be the following value:
\r
528 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
\r
529 * @note The DMA underrun occurs when a second external trigger arrives before
\r
530 * the acknowledgement for the first external trigger is received (first request).
\r
531 * @param NewState: new state of the specified DAC interrupts.
\r
532 * This parameter can be: ENABLE or DISABLE.
\r
535 void DAC_ITConfig(uint32_t DAC_Channel, uint32_t DAC_IT, FunctionalState NewState)
\r
537 /* Check the parameters */
\r
538 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
539 assert_param(IS_FUNCTIONAL_STATE(NewState));
\r
540 assert_param(IS_DAC_IT(DAC_IT));
\r
542 if (NewState != DISABLE)
\r
544 /* Enable the selected DAC interrupts */
\r
545 DAC->CR |= (DAC_IT << DAC_Channel);
\r
549 /* Disable the selected DAC interrupts */
\r
550 DAC->CR &= (~(uint32_t)(DAC_IT << DAC_Channel));
\r
555 * @brief Checks whether the specified DAC flag is set or not.
\r
556 * @param DAC_Channel: thee selected DAC channel.
\r
557 * This parameter can be one of the following values:
\r
558 * @arg DAC_Channel_1: DAC Channel1 selected
\r
559 * @arg DAC_Channel_2: DAC Channel2 selected
\r
560 * @param DAC_FLAG: specifies the flag to check.
\r
561 * This parameter can be only of the following value:
\r
562 * @arg DAC_FLAG_DMAUDR: DMA underrun flag
\r
563 * @note The DMA underrun occurs when a second external trigger arrives before
\r
564 * the acknowledgement for the first external trigger is received (first request).
\r
565 * @retval The new state of DAC_FLAG (SET or RESET).
\r
567 FlagStatus DAC_GetFlagStatus(uint32_t DAC_Channel, uint32_t DAC_FLAG)
\r
569 FlagStatus bitstatus = RESET;
\r
570 /* Check the parameters */
\r
571 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
572 assert_param(IS_DAC_FLAG(DAC_FLAG));
\r
574 /* Check the status of the specified DAC flag */
\r
575 if ((DAC->SR & (DAC_FLAG << DAC_Channel)) != (uint8_t)RESET)
\r
577 /* DAC_FLAG is set */
\r
582 /* DAC_FLAG is reset */
\r
585 /* Return the DAC_FLAG status */
\r
590 * @brief Clears the DAC channel's pending flags.
\r
591 * @param DAC_Channel: the selected DAC channel.
\r
592 * This parameter can be one of the following values:
\r
593 * @arg DAC_Channel_1: DAC Channel1 selected
\r
594 * @arg DAC_Channel_2: DAC Channel2 selected
\r
595 * @param DAC_FLAG: specifies the flag to clear.
\r
596 * This parameter can be the following value:
\r
597 * @arg DAC_FLAG_DMAUDR: DMA underrun flag
\r
600 void DAC_ClearFlag(uint32_t DAC_Channel, uint32_t DAC_FLAG)
\r
602 /* Check the parameters */
\r
603 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
604 assert_param(IS_DAC_FLAG(DAC_FLAG));
\r
606 /* Clear the selected DAC flags */
\r
607 DAC->SR = (DAC_FLAG << DAC_Channel);
\r
611 * @brief Checks whether the specified DAC interrupt has occurred or not.
\r
612 * @param DAC_Channel: the selected DAC channel.
\r
613 * This parameter can be one of the following values:
\r
614 * @arg DAC_Channel_1: DAC Channel1 selected
\r
615 * @arg DAC_Channel_2: DAC Channel2 selected
\r
616 * @param DAC_IT: specifies the DAC interrupt source to check.
\r
617 * This parameter can be the following values:
\r
618 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
\r
619 * @note The DMA underrun occurs when a second external trigger arrives before
\r
620 * the acknowledgement for the first external trigger is received (first request).
\r
621 * @retval The new state of DAC_IT (SET or RESET).
\r
623 ITStatus DAC_GetITStatus(uint32_t DAC_Channel, uint32_t DAC_IT)
\r
625 ITStatus bitstatus = RESET;
\r
626 uint32_t enablestatus = 0;
\r
628 /* Check the parameters */
\r
629 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
630 assert_param(IS_DAC_IT(DAC_IT));
\r
632 /* Get the DAC_IT enable bit status */
\r
633 enablestatus = (DAC->CR & (DAC_IT << DAC_Channel)) ;
\r
635 /* Check the status of the specified DAC interrupt */
\r
636 if (((DAC->SR & (DAC_IT << DAC_Channel)) != (uint32_t)RESET) && enablestatus)
\r
638 /* DAC_IT is set */
\r
643 /* DAC_IT is reset */
\r
646 /* Return the DAC_IT status */
\r
651 * @brief Clears the DAC channel's interrupt pending bits.
\r
652 * @param DAC_Channel: the selected DAC channel.
\r
653 * This parameter can be one of the following values:
\r
654 * @arg DAC_Channel_1: DAC Channel1 selected
\r
655 * @arg DAC_Channel_2: DAC Channel2 selected
\r
656 * @param DAC_IT: specifies the DAC interrupt pending bit to clear.
\r
657 * This parameter can be the following values:
\r
658 * @arg DAC_IT_DMAUDR: DMA underrun interrupt mask
\r
661 void DAC_ClearITPendingBit(uint32_t DAC_Channel, uint32_t DAC_IT)
\r
663 /* Check the parameters */
\r
664 assert_param(IS_DAC_CHANNEL(DAC_Channel));
\r
665 assert_param(IS_DAC_IT(DAC_IT));
\r
667 /* Clear the selected DAC interrupt pending bits */
\r
668 DAC->SR = (DAC_IT << DAC_Channel);
\r
687 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r