芯片是N32G4FRKEQ7,改了4x4的封装,重新做好了板子,开始调试了。
DAC直接用DAC_SetCh1Data是可以输出不同的数据的,但是改用DMA,始终无法输出波形,相关代码如下,请帮忙看看
//DAC DMA IRQ
void DMA2_Channel3_IRQHandler(void)
{
//DAC DMA full transfer IRQ
//这个中断始终进不来
....
}
// --------------------------------------------------------------------------------
void dac_gpio_config(void)
{
GPIO_InitType gpio_init_struct;
// PA4 = DAC1
gpio_init_struct.GPIO_Mode = GPIO_Mode_AIN;
gpio_init_struct.Pin = GPIO_PIN_4;
GPIO_InitPeripheral(GPIOA, &gpio_init_struct);
}
static void nvic_config(IRQn_Type irq)
{
NVIC_InitType NVIC_InitStructure;
/* Enable the Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = irq;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void dac_dma_config(void)
{
DMA_InitType DMA_InitStructure;
DMA_DeInit(DMA2_CH3);
DMA_InitStructure.PeriphAddr = (uint32_t)DAC->DR12CH1;
DMA_InitStructure.MemAddr = (uint32_t)dac_Wave;
DMA_InitStructure.Direction = DMA_DIR_PERIPH_DST;
DMA_InitStructure.BufSize = TUNE_LEN_DAC;
DMA_InitStructure.PeriphInc = DMA_PERIPH_INC_DISABLE;
DMA_InitStructure.DMA_MemoryInc = DMA_MEM_INC_ENABLE;
DMA_InitStructure.PeriphDataSize = DMA_PERIPH_DATA_SIZE_HALFWORD;
DMA_InitStructure.MemDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.CircularMode = DMA_MODE_CIRCULAR;
DMA_InitStructure.Priority = DMA_PRIORITY_HIGH;
DMA_InitStructure.Mem2Mem = DMA_M2M_DISABLE;
DMA_Init(DMA2_CH3, &DMA_InitStructure);
DMA_EnableChannel(DMA2_CH3, ENABLE);
DMA_ConfigInt(DMA2_CH3, DMA_INT_TXC | DMA_INT_HTX, ENABLE);
/* dma1 channel1 interrupt nvic init */
nvic_config(DMA2_Channel3_IRQn);
}
void TIM2_TrgoInit(void)
{
TIM_TimeBaseInitType TIM_TimeBaseStructure;
/* TIM2 Configuration */
/* Time base configuration */
TIM_InitTimBaseStruct(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.Period = 108-1;//108MHz/108=1MHz
TIM_TimeBaseStructure.Prescaler = 0x0;
TIM_TimeBaseStructure.ClkDiv = 0x0;
TIM_TimeBaseStructure.CntMode = TIM_CNT_MODE_UP;
TIM_InitTimeBase(TIM2, &TIM_TimeBaseStructure);
/* TIM2 TRGO selection */
TIM_SelectOutputTrig(TIM2, TIM_TRGO_SRC_UPDATE);
}
void dac_config(void)
{
DAC_InitType dac_init_struct;
TIM2_TrgoInit();
/* dac1 configuration */
DAC_ClearStruct(&dac_init_struct);
dac_init_struct.Trigger = DAC_TRG_T2_TRGO;
dac_init_struct.WaveGen = DAC_WAVEGEN_NONE;
dac_init_struct.BufferOutput = DAC_BUFFOUTPUT_DISABLE;
DAC_Init(DAC_CHANNEL_1, &dac_init_struct);
dac_dma_config();
DAC_Enable(DAC_CHANNEL_1, ENABLE);
}
void dac_setup(void)
{
dac_gpio_config();
dac_config();
}
void dac_start(void)
{
DAC_DmaEnable(DAC_CHANNEL_1, ENABLE); // DAC
/* enable tmr2 */
TIM_Enable(TIM2, ENABLE);
}
|