本帖最后由 mingshixu 于 2019-1-23 20:17 编辑
各位老师,求助一个问题:
最近在学习STM32F334,想实现双路DAC独立输出,根据DEMO改的代码调试过程中,DAC1能正常输出,DAC2寄存器上能看到数据,但硬件管脚上检测不到输出电平。代码如下:
- void Configure_DAC(void)
- {
- /*## Configuration of GPIO used by DAC channels ############################*/
- __IO uint32_t wait_loop_index = 0;
- /* Enable GPIO Clock */
- LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
- /* Configure GPIO in analog mode to be used as DAC output */
- LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_4, LL_GPIO_MODE_ANALOG);
- /* Configure GPIO in analog mode to be used as DAC output */
- LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_6, LL_GPIO_MODE_ANALOG);
- /*## Configuration of DAC ##################################################*/
- /* Enable DAC clock */
- LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DAC1);
- LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_DAC2);
- /* Select trigger source */
- LL_DAC_SetTriggerSource(DAC1, LL_DAC_CHANNEL_1, LL_DAC_TRIG_SOFTWARE);
- LL_DAC_SetTriggerSource(DAC2, LL_DAC_CHANNEL_1, LL_DAC_TRIG_SOFTWARE);
- /* Set the data to be loaded in the data holding register */
- LL_DAC_ConvertData12RightAligned(DAC1, LL_DAC_CHANNEL_1, 0x300);
- LL_DAC_ConvertData12RightAligned(DAC2, LL_DAC_CHANNEL_1, 0x300);
- /* Enable interruption DAC channel1 underrun */
- LL_DAC_EnableIT_DMAUDR1(DAC1);
- LL_DAC_EnableIT_DMAUDR1(DAC2);
- /* Enable DAC channel */
- LL_DAC_Enable(DAC1, LL_DAC_CHANNEL_1);
- LL_DAC_Enable(DAC2, LL_DAC_CHANNEL_1);
- /* Delay for DAC channel voltage settling time from DAC channel startup. */
- wait_loop_index = ((LL_DAC_DELAY_STARTUP_VOLTAGE_SETTLING_US * (SystemCoreClock / (100000 * 2))) / 10);
- while(wait_loop_index != 0)
- {
- wait_loop_index--;
- }
- LL_DAC_EnableTrigger(DAC1, LL_DAC_CHANNEL_1);
- LL_DAC_EnableTrigger(DAC2, LL_DAC_CHANNEL_1);
- }
复制代码
调试时观测两路DAC的寄存器,数值都相同,但DAC2管脚上始终没有输出电平,请教各位老师,这个问题怎么查?
仔细阅读了数据手册,发现DAC2与DAC1不同的一点是:DAC2在输出端有一个switch需要配置,配置为switch_enable就可以了。
|