最近在研究DAC+TIMER+DMA,在循环模式得情况下能够正确输出正弦信号,切换成正常模式的时候出现了问题,DAC的下溢出中断被置1了,导致无法进行下一个DAM请求
void dac_config(void)
{
/* enable the clock of DAC */
rcu_periph_clock_enable(RCU_DAC);
dac_deinit();
dac_trigger_disable();
/* set DAC trigger source */
dac_wave_mode_config(DAC_WAVE_DISABLE);
// dac_lfsr_noise_config(DAC_LFSR_BIT0);
dac_output_buffer_disable();
dac_trigger_source_config(DAC_TRIGGER_T1_TRGO);
dac_interrupt_disable();
dac_dma_enable();
dac_trigger_enable();
/* enable DAC */
dac_enable();
}
static void dma_config(void)
{
dma_parameter_struct dma_init_struct;
/* enable DMA CLK */
rcu_periph_clock_enable(RCU_DMA);
/* deinitialize DMA channel3(USART0 tx) */
dma_deinit(DMA_CH2);
dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL;
// dma_init_struct.memory_addr = ;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.memory_width = DMA_MEMORY_WIDTH_16BIT;
// dma_init_struct.number = ;
// dma_init_struct.periph_addr = ;
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_16BIT;
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_init(DMA_CH2, &dma_init_struct);
/* configure DMA mode */
dma_memory_to_memory_disable(DMA_CH2);
}
void sin_dma_function_config(void)
{
//DMAx的通道y的存储器基地址配置
dma_memory_address_config(DMA_CH2,(uint32_t)Sine);
//配置DMAx通道y还有多少数据要传输
dma_transfer_number_config(DMA_CH2,5000);
//DMAx的通道y的外设基地址配置
dma_periph_address_config(DMA_CH2,DAC0_R12DH_ADDRESS);
//DMA循环模式开启
dma_circulation_disable(DMA_CH2);
//DMA的通道使能
dma_channel_enable(DMA_CH2);
}
void sin_timx_trigger_function_config(void)
{
timer_parameter_struct timer_initpara;
rcu_periph_clock_enable(RCU_TIMER1);
timer_deinit(TIMER1);
/* TIMER6 configuration */
timer_initpara.prescaler = 1-1;//预分频
timer_initpara.counterdirection = TIMER_COUNTER_UP;//向上计数
timer_initpara.period = 108-1;//定时周期
timer_init(TIMER1,&timer_initpara);
//定时器主输出触发源选择
timer_master_output_trigger_source_select(TIMER1,TIMER_TRI_OUT_SRC_UPDATE);
//定时器更新事件使能
timer_update_event_enable(TIMER1);
} |