libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.

Defined Constants and Types for the STM32L4xx DAC More...

Collaboration diagram for DAC Defines:

Modules

 DAC register base addresses
 
 DAC Registers
 
 DAC_CR values
 
 DAC_SWTRIGR Values
 
 DAC_DHRxxx Values
 
 DAC_DORx Values
 
 DAC_SR Values
 
 DAC Channel Identifier
 

Enumerations

enum  dac_align { DAC_ALIGN_RIGHT8 , DAC_ALIGN_RIGHT12 , DAC_ALIGN_LEFT12 }
 DAC data size (8/12 bits), alignment (right/left) More...
 
enum  dac_wave { DAC_WAVE_DISABLE = 0 , DAC_WAVE_NOISE = 1 , DAC_WAVE_TRIANGLE = 2 , DAC_WAVE_SAWTOOTH = 3 }
 DAC waveform generation options. More...
 

Functions

void dac_enable (uint32_t dac, int channel)
 DAC Channel Enable. More...
 
void dac_disable (uint32_t dac, int channel)
 DAC Channel Disable. More...
 
void dac_buffer_enable (uint32_t dac, int channel)
 DAC Channel Output Buffer Enable. More...
 
void dac_buffer_disable (uint32_t dac, int channel)
 DAC Channel Output Buffer Disable. More...
 
void dac_dma_enable (uint32_t dac, int channel)
 DAC Channel DMA Enable. More...
 
void dac_dma_disable (uint32_t dac, int channel)
 DAC Channel DMA Disable. More...
 
void dac_trigger_enable (uint32_t dac, int channel)
 DAC Channel Trigger Enable. More...
 
void dac_trigger_disable (uint32_t dac, int channel)
 DAC Channel Trigger Disable. More...
 
void dac_set_trigger_source (uint32_t dac, uint32_t source)
 Set DAC Channel Trigger Source. More...
 
void dac_set_waveform_generation (uint32_t dac, int channel, enum dac_wave wave)
 Set DAC Channel Waveform Generation mode for one or both channels. More...
 
void dac_disable_waveform_generation (uint32_t dac, int channel)
 Disable DAC Channel Waveform Generation. More...
 
void dac_set_waveform_characteristics (uint32_t dac, int channel, int mamp)
 Set DAC Channel LFSR Mask or Triangle Wave Amplitude. More...
 
void dac_load_data_buffer_single (uint32_t dac, uint16_t data, enum dac_align align, int channel)
 Load DAC Data Register. More...
 
void dac_load_data_buffer_dual (uint32_t dac, uint16_t data1, uint16_t data2, enum dac_align align)
 Load DAC Dual Data Register. More...
 
void dac_software_trigger (uint32_t dac, int channel)
 Trigger the DAC by a Software Trigger. More...
 

Detailed Description

Defined Constants and Types for the STM32L4xx DAC

Version
1.0.0
Date
8 June 2019

LGPL License Terms libopencm3 License

Author
© 2012 Felix Held felix.nosp@m.-lib.nosp@m.openc.nosp@m.m3@f.nosp@m.elixh.nosp@m.eld..nosp@m.de
© 2020 Ben Brewer ben.b.nosp@m.rewe.nosp@m.r@cod.nosp@m.ethi.nosp@m.nk.co.nosp@m..uk
© 2020 Ben Brewer ben.b.nosp@m.rewe.nosp@m.r@cod.nosp@m.ethi.nosp@m.nk.co.nosp@m..uk

Enumeration Type Documentation

◆ dac_align

enum dac_align

DAC data size (8/12 bits), alignment (right/left)

Enumerator
DAC_ALIGN_RIGHT8 
DAC_ALIGN_RIGHT12 
DAC_ALIGN_LEFT12 

Definition at line 237 of file dac_common_all.h.

◆ dac_wave

enum dac_wave

DAC waveform generation options.

Not all wave shapes are available on all parts.

Enumerator
DAC_WAVE_DISABLE 
DAC_WAVE_NOISE 
DAC_WAVE_TRIANGLE 
DAC_WAVE_SAWTOOTH 

Definition at line 246 of file dac_common_all.h.

Function Documentation

◆ dac_buffer_disable()

void dac_buffer_disable ( uint32_t  dac,
int  channel 
)

DAC Channel Output Buffer Disable.

Disable a digital to analog converter channel output drive buffer. Disabling this will reduce power consumption slightly and will increase the output impedance of the DAC. The buffers are enabled by default after a reset.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 66 of file dac_common_v1.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_BOFF1, and DAC_CR_BOFF2.

◆ dac_buffer_enable()

void dac_buffer_enable ( uint32_t  dac,
int  channel 
)

DAC Channel Output Buffer Enable.

Enable a digital to analog converter channel output drive buffer. This is an optional amplifying buffer that provides additional drive for the output signal. The buffer is enabled by default after a reset and needs to be explicitly disabled if required.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 42 of file dac_common_v1.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_BOFF1, and DAC_CR_BOFF2.

◆ dac_disable()

void dac_disable ( uint32_t  dac,
int  channel 
)

DAC Channel Disable.

Disable a digital to analog converter channel.

Parameters
[in]dacthe base address of the DAC DAC register base addresses
[in]channelwith DAC mask DAC Channel Identifier

Definition at line 159 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_EN1, and DAC_CR_EN2.

◆ dac_disable_waveform_generation()

void dac_disable_waveform_generation ( uint32_t  dac,
int  channel 
)

Disable DAC Channel Waveform Generation.

Note
this is equivalent to dac_set_waveform_generation (dac, channel, DAC_WAVE_DISABLE)
Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 332 of file dac_common_all.c.

References dac_set_waveform_generation(), and DAC_WAVE_DISABLE.

Here is the call graph for this function:

◆ dac_dma_disable()

void dac_dma_disable ( uint32_t  dac,
int  channel 
)

DAC Channel DMA Disable.

Disable a digital to analog converter channel DMA mode.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 209 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_DMAEN1, and DAC_CR_DMAEN2.

◆ dac_dma_enable()

void dac_dma_enable ( uint32_t  dac,
int  channel 
)

DAC Channel DMA Enable.

Enable a digital to analog converter channel DMA mode (connected to DMA2 channel 3 for DAC channel 1 and DMA2 channel 4 for DAC channel 2). A DMA request is generated following an external trigger.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 185 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_DMAEN1, and DAC_CR_DMAEN2.

◆ dac_enable()

void dac_enable ( uint32_t  dac,
int  channel 
)

DAC Channel Enable.

Enable a digital to analog converter channel. After setting this enable, the DAC requires a twakeup time typically around 10 microseconds before it actually wakes up.

Parameters
[in]dacthe base address of the DAC DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 137 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_EN1, and DAC_CR_EN2.

◆ dac_load_data_buffer_dual()

void dac_load_data_buffer_dual ( uint32_t  dac,
uint16_t  data1,
uint16_t  data2,
enum dac_align  align 
)

Load DAC Dual Data Register.

Loads the appropriate digital to analog converter dual data register with 12 or 8 bit data to be converted for both channels. This allows high bandwidth simultaneous or independent analog output. The data in both channels are aligned identically.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]data1uint16_t for channel 1 with appropriate alignment.
[in]data2uint16_t for channel 2 with appropriate alignment.
[in]alignenum dac_align. Right or left aligned, and 8 or 12 bit.

Definition at line 441 of file dac_common_all.c.

References DAC_ALIGN_LEFT12, DAC_ALIGN_RIGHT12, DAC_ALIGN_RIGHT8, DAC_DHR12LD, DAC_DHR12RD, and DAC_DHR8RD.

◆ dac_load_data_buffer_single()

void dac_load_data_buffer_single ( uint32_t  dac,
uint16_t  data,
enum dac_align  align,
int  channel 
)

Load DAC Data Register.

Loads the appropriate digital to analog converter data register with 12 or 8 bit data to be converted on a channel. The data can be aligned as follows:

  • right-aligned 8 bit data in bits 0-7
  • right-aligned 12 bit data in bits 0-11
  • left aligned 12 bit data in bits 4-15
Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]datauint16_t with appropriate alignment.
[in]alignenum dac_align. Alignment and size.
[in]channeluint8_t with DAC mask.

Definition at line 393 of file dac_common_all.c.

References DAC_ALIGN_LEFT12, DAC_ALIGN_RIGHT12, DAC_ALIGN_RIGHT8, DAC_CHANNEL1, DAC_CHANNEL2, DAC_DHR12L1, DAC_DHR12L2, DAC_DHR12R1, DAC_DHR12R2, DAC_DHR8R1, and DAC_DHR8R2.

◆ dac_set_trigger_source()

void dac_set_trigger_source ( uint32_t  dac,
uint32_t  source 
)

Set DAC Channel Trigger Source.

Sets the digital to analog converter trigger source, which can be taken from various timers, an external trigger or a software trigger.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]sourceTaken from DAC Channel 2 Trigger Source Selection or DAC Channel 1 Trigger Source Selection or a logical OR of one of each of these to set both channels simultaneously.

Definition at line 287 of file dac_common_all.c.

References DAC_CR.

◆ dac_set_waveform_characteristics()

void dac_set_waveform_characteristics ( uint32_t  dac,
int  channel,
int  mamp 
)

Set DAC Channel LFSR Mask or Triangle Wave Amplitude.

Sets the digital to analog converter superimposed waveform generation characteristics.

  • If the noise generation mode is set, this sets the length of the PRBS sequence and hence the amplitude of the output noise signal. Default setting is length 1.
  • If the triangle wave generation mode is set, this sets the amplitude of the output signal as 2^(n)-1 where n is the parameter value. Default setting is 1.
Note
High amplitude levels of these waveforms can overload the DAC and distort the signal output.
This must be called before enabling the DAC as the settings will then become read-only.
The DAC trigger must be enabled for this to work.
Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelone or both, select from DAC Channel Identifier
[in]mampamplitude of mixed waveform, bit width DAC_CR_MAMPx_MASK

Definition at line 356 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_MAMP1_SHIFT, DAC_CR_MAMP2_SHIFT, and DAC_CR_MAMPx_MASK.

◆ dac_set_waveform_generation()

void dac_set_waveform_generation ( uint32_t  dac,
int  channel,
enum dac_wave  wave 
)

Set DAC Channel Waveform Generation mode for one or both channels.

These signals are superimposed on existing output values in the DAC output registers. Waveform can be disabled, noise, triangular, or sawtooth, depending on family.

Note
The DAC trigger must be enabled for this to work.
Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelone or both, DAC Channel Identifier
[in]waveenum dac_wave. mode for channel

Definition at line 302 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_WAVE1_SHIFT, DAC_CR_WAVE2_SHIFT, and DAC_CR_WAVEx_MASK.

Referenced by dac_disable_waveform_generation().

Here is the caller graph for this function:

◆ dac_software_trigger()

void dac_software_trigger ( uint32_t  dac,
int  channel 
)

Trigger the DAC by a Software Trigger.

If the trigger source is set to be a software trigger, cause a trigger to occur. The trigger is cleared by hardware after conversion.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 470 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_SWTRIGR, DAC_SWTRIGR_SWTRIG1, and DAC_SWTRIGR_SWTRIG2.

◆ dac_trigger_disable()

void dac_trigger_disable ( uint32_t  dac,
int  channel 
)

DAC Channel Trigger Disable.

Disable a digital to analog converter channel external trigger.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 260 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_TEN1, and DAC_CR_TEN2.

◆ dac_trigger_enable()

void dac_trigger_enable ( uint32_t  dac,
int  channel 
)

DAC Channel Trigger Enable.

Enable a digital to analog converter channel external trigger mode. This allows an external trigger to initiate register transfers from the buffer register to the DAC output register, followed by a DMA transfer to the buffer register if DMA is enabled. The trigger source must also be selected.

Parameters
[in]dacthe base address of the DAC. DAC register base addresses
[in]channelwith DAC mask. DAC Channel Identifier

Definition at line 236 of file dac_common_all.c.

References DAC_CHANNEL1, DAC_CHANNEL2, DAC_CHANNEL_BOTH, DAC_CR, DAC_CR_TEN1, and DAC_CR_TEN2.