你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 4650|回复: 19

HAL的DAC解说----二

[复制链接]

27

主题

58

回帖

0

蝴蝶豆

中级会员

最后登录
2017-3-30
发表于 2015-2-16 12:29:31 | 显示全部楼层 |阅读模式

static void DAC_Ch1_EscalatorConfig(void)
{
  /*##-1- Initialize the DAC peripheral ######################################*/
  if (HAL_DAC_Init(&DacHandle) != HAL_OK)
  {
    /* Initiliazation Error */
    Error_Handler();
  }
QQ截图20150216121708.png
  /*##-1- DAC channel1 Configuration #########################################*/
  sConfig.DAC_Trigger = DAC_TRIGGER_T6_TRGO;
  sConfig.DAC_OutputBuffer = DAC_OUTPUTBUFFER_ENABLE;

  if (HAL_DAC_ConfigChannel(&DacHandle, &sConfig, DACx_CHANNEL) != HAL_OK)
  {
    /* Channel configuration Error */
    Error_Handler();
  }

  /*##-2- Enable DAC Channel1 and associeted DMA #############################*/
  if (HAL_DAC_Start_DMA(&DacHandle, DACx_CHANNEL, (uint32_t *)aEscalator8bit, 6, DAC_ALIGN_8B_R) != HAL_OK)
  {
    /* Start DMA Error */
    Error_Handler();
  }
}
其中
#define  DAC_CR_TEN1                         ((uint32_t)0x00000004)        /*!< DAC channel1 Trigger enable */
#define  DAC_CR_EN1                          ((uint32_t)0x00000001)        /*!< DAC channel1 enable */
The DAC channel can be powered on by setting the EN1 bit in the DAC_CR register. The DAC channel is then enabled after a startup time tWAKEUP.
所以在使用基准电压的时候可以使能DAC_XCR_EN1;
#define DAC_TRIGGER_T6_TRGO                ((uint32_t)DAC_CR_TEN1) /*!< TIM6 TRGO selected as external conversion trigger for DAC channel */
QQ截图20150216120104.png
意思就是:
DAC整合输出缓冲区,可以不使用一个外部的运算放大器,而用来降低输出阻抗和直接驱动外部负载。缓冲区可以绕过通过配置BOFFx位DAC_CR配置。

侃了这么多,重点来了,就是这几个寄存器的情况。

QQ截图20150216122430.png

顺便就可以写它的定义了

#define  DAC_CR_BOFF1                        ((uint32_t)0x00000002)        /*!< DAC channel1 output buffer disable */
#define  DAC_CR_TEN1                         ((uint32_t)0x00000004)        /*!< DAC channel1 Trigger enable */

#define  DAC_CR_TSEL1                        ((uint32_t)0x00000038)        /*!< TSEL1[2:0] (DAC channel1 Trigger selection) */
#define  DAC_CR_TSEL1_0                      ((uint32_t)0x00000008)        /*!< Bit 0 */
#define  DAC_CR_TSEL1_1                      ((uint32_t)0x00000010)        /*!< Bit 1 */
#define  DAC_CR_TSEL1_2                      ((uint32_t)0x00000020)        /*!< Bit 2 */

#define  DAC_CR_WAVE1                        ((uint32_t)0x000000C0)        /*!< WAVE1[1:0] (DAC channel1 noise/triangle wave generation enable) */
#define  DAC_CR_WAVE1_0                      ((uint32_t)0x00000040)        /*!< Bit 0 */
#define  DAC_CR_WAVE1_1                      ((uint32_t)0x00000080)        /*!< Bit 1 */

#define  DAC_CR_MAMP1                        ((uint32_t)0x00000F00)        /*!< MAMP1[3:0] (DAC channel1 Mask/Amplitude selector)  */
#define  DAC_CR_MAMP1_0                      ((uint32_t)0x00000100)        /*!< Bit 0 */
#define  DAC_CR_MAMP1_1                      ((uint32_t)0x00000200)        /*!< Bit 1 */
#define  DAC_CR_MAMP1_2                      ((uint32_t)0x00000400)        /*!< Bit 2 */
#define  DAC_CR_MAMP1_3                      ((uint32_t)0x00000800)        /*!< Bit 3 */

#define  DAC_CR_DMAEN1                       ((uint32_t)0x00001000)        /*!< DAC channel1 DMA enable */
#define  DAC_CR_DMAUDRIE1                    ((uint32_t)0x00002000)        /*!< DAC channel1 DMA Underrun Interrupt enable */

#define  DAC_CR_EN2                          ((uint32_t)0x00010000)        /*!< DAC channel2 enable */
#define  DAC_CR_BOFF2                        ((uint32_t)0x00020000)        /*!< DAC channel2 output buffer disable */
#define  DAC_CR_TEN2                         ((uint32_t)0x00040000)        /*!< DAC channel2 Trigger enable */

#define  DAC_CR_TSEL2                        ((uint32_t)0x00380000)        /*!< TSEL2[2:0] (DAC channel2 Trigger selection) */
#define  DAC_CR_TSEL2_0                      ((uint32_t)0x00080000)        /*!< Bit 0 */
#define  DAC_CR_TSEL2_1                      ((uint32_t)0x00100000)        /*!< Bit 1 */
#define  DAC_CR_TSEL2_2                      ((uint32_t)0x00200000)        /*!< Bit 2 */

#define  DAC_CR_WAVE2                        ((uint32_t)0x00C00000)        /*!< WAVE2[1:0] (DAC channel2 noise/triangle wave generation enable) */
#define  DAC_CR_WAVE2_0                      ((uint32_t)0x00400000)        /*!< Bit 0 */
#define  DAC_CR_WAVE2_1                      ((uint32_t)0x00800000)        /*!< Bit 1 */

#define  DAC_CR_MAMP2                        ((uint32_t)0x0F000000)        /*!< MAMP2[3:0] (DAC channel2 Mask/Amplitude selector) */
#define  DAC_CR_MAMP2_0                      ((uint32_t)0x01000000)        /*!< Bit 0 */
#define  DAC_CR_MAMP2_1                      ((uint32_t)0x02000000)        /*!< Bit 1 */
#define  DAC_CR_MAMP2_2                      ((uint32_t)0x04000000)        /*!< Bit 2 */
#define  DAC_CR_MAMP2_3                      ((uint32_t)0x08000000)        /*!< Bit 3 */

#define  DAC_CR_DMAEN2                       ((uint32_t)0x10000000)        /*!< DAC channel2 DMA enabled */
#define  DAC_CR_DMAUDRIE2                    ((uint32_t)0x20000000)        /*!< DAC channel2 DMA Underrun Interrupt enable */
又字数超限制了

回复

使用道具 举报

93

主题

2449

回帖

4

蝴蝶豆

论坛元老

最后登录
2020-6-28
发表于 2015-2-16 12:31:12 | 显示全部楼层
字数超限,可以占楼再发
回复 支持 反对

使用道具 举报

16

主题

560

回帖

1

蝴蝶豆

金牌会员

最后登录
2020-6-25
发表于 2015-2-16 15:14:44 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

14

主题

421

回帖

2

蝴蝶豆

金牌会员

最后登录
2020-7-26
发表于 2015-2-16 15:27:55 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

52

主题

3313

回帖

61

蝴蝶豆

论坛元老

最后登录
2020-12-9
发表于 2015-2-16 17:08:21 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

8

主题

407

回帖

0

蝴蝶豆

高级会员

最后登录
2016-11-24
发表于 2015-2-16 17:35:02 | 显示全部楼层
感谢分享!
回复 支持 反对

使用道具 举报

8

主题

252

回帖

0

蝴蝶豆

金牌会员

最后登录
2019-2-22
发表于 2015-2-16 20:33:02 | 显示全部楼层
感谢分享!顶一个!
回复 支持 反对

使用道具 举报

56

主题

970

回帖

2

蝴蝶豆

金牌会员

最后登录
2020-9-21
发表于 2015-2-17 00:22:38 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

6

主题

75

回帖

0

蝴蝶豆

中级会员

最后登录
2015-11-25
发表于 2015-2-17 00:42:42 | 显示全部楼层
围观学习,谢谢分享!
回复 支持 反对

使用道具 举报

27

主题

58

回帖

0

蝴蝶豆

中级会员

最后登录
2017-3-30
 楼主| 发表于 2015-2-17 08:27:11 | 显示全部楼层
直接通过CUBEMX配置非常简单
回复 支持 反对

使用道具 举报

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版