STM32-快速上手DAC

本文档介绍了如何快速在STM32单片机上配置和使用DAC模块,包括概述、配置步骤、库函数总结和代码示例。适用于需要模拟输出的项目。
摘要由CSDN通过智能技术生成

关于DAC的模块分析在《STM32-一文搞懂DAC》已经记过了,这里只记快速使用。

目录

1 概述

2 配置步骤

3 库函数汇总

4 代码范例


1 概述

STM32的DAC模块只存在于大容量产品中,是12位数字输入,电压输出的数字/模拟转换器,2个输出通道,每个通道都有单独的转换器,支持双DAC模式。DAC可以通过引脚输入参考电压VREF+以获得更精确的转换结果。DAC模块在APB1时钟下!

2 配置步骤

  • (1)DAC模块时钟使能(在APB1下)、输出IO端口时钟使能(APB2下)。
    • void RCC_APB1PeriphClockCmd(uint32_t RCC_APB1Periph, FunctionalState NewState);
    • void RCC_APB2PeriphClockCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
  • (2)输出端口配置
    • void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
  • (3)DAC模块配置
    • void DAC_Init(uint32_t DAC_Channel, DAC_InitTypeDef* DAC_InitStruct);

主要配置前文《stm32-一文搞懂DAC》中提到的控制寄存器DAC_CR。

typedef struct
{
  uint32_t DAC_Trigger;                      /*!< Specifies the external trigger for the selected DAC channel.
                                                  This parameter can be a value of @ref DAC_trigger_selection */

  uint32_t DAC_WaveGeneration;               /*!< Specifies whether DAC channel noise waves or triangle waves
                                                  are generated, or whether no wave is generated.
                                                  This parameter can be a value of @ref DAC_wave_generation */

  uint32_t DAC_LFSRUnmask_TriangleAmplitude; /*!< Specifies the LFSR mask for noise wave generation or
                                                  the maximum amplitude triangle generation for the DAC channel. 
                                                  This parameter can be a value of @ref DAC_lfsrunmask_triangleamplitude */

  uint32_t DAC_OutputBuffer;                 /*!< Specifies whether the DAC channel output buffer is enabled or disabled.
                                                  This parameter can be a value of @ref DAC_output_buffer */
}DAC_InitTypeDef;

DAC_Trigger 通道触发源选择,可选通道如下

#define DAC_Trigger_None                   ((uint32_t)0x00000000) /*!< Conversion is a
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值