参照例程使用STM32的DAC输出波形正常(DMA传输),现准备让让DAC随时输出可控值,把DAC触发改为软件触发DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software; ,使能软件触发 AC_DualSoftwareTriggerCmd(ENABLE), 把要输出数据直接送至DAC->DHR12R1和DAC->DHR12R1,却没有看到DAC输出值的改变,DAC的输出一直都是DAC_SetChannel1Data(DAC_Align_12b_R,0x07ff) 定义的初值(1.65v)。
DAC能输出初值,说明DAC的主要设置和时钟都没有问题,问题可能是向发送数据有问题,向DAC数据寄存器直接发送数据我是参照网上看到的例程,编译也通过了,不知是否还有问题。下面是程序的主要部分,希望得到大家的指导和帮助,谢谢!
/* DAC channel1 Configuration */
//DAC_StructInit(&DAC_InitStructure); //将DAC_Struct的值设为默认
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
DAC_SetChannel1Data(DAC_Align_12b_R,0x07ff);
//12位右对齐,DAC1输出电压(初值),
DAC_SetChannel2Data(DAC_Align_12b_R,0x07ff);
//12位右对齐,DAC2输出电压(初值),
DAC_DualSoftwareTriggerCmd(ENABLE);
//使能软件触发,更新DAC的值
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_1, ENABLE);
/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_2, ENABLE);
while (1)
{
DAC->DHR12R1 =0x0000;
DAC->DHR12R2 =0x0000;
Delay(0xFFFFF);
}
|