好的 等一下 昨天下班回去 家里电脑没有程序 今天上班了 现在贴上来 大家帮我看一下
下面的程序是DAC_Channel_2通道使能和引脚初始化void DAC_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
/* ʹÄÜGPIOAʱÖÓ */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* ʹÄÜDACʱÖÓ */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DACµÄGPIOÅäÖã¬Ä£ÄâÊäÈë */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* ÅäÖÃDAC ͨµÀ1 */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T7_TRGO; //ʹÓÃTIM7×÷Ϊ´¥·¢Ô´
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; //²»Ê¹Óò¨Ðη¢ÉúÆ÷
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //²»Ê¹ÓÃDACÊä³ö»º³å
/* ÅäÖÃDAC ͨµÀ2 */
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* ʹÄÜͨµÀ2 ÓÉPA5Êä³ö */
DAC_Cmd(DAC_Channel_2, ENABLE);
/* ʹÄÜDACµÄDMAÇëÇó */
DAC_DMACmd(DAC_Channel_2, ENABLE);
}
下面的是 TIM7定时器初始化函数void DAC_TIM_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* ʹÄÜTIM2ʱÖÓ */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
/* TIM7»ù±¾¶¨Ê±Æ÷ÅäÖà */
// TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 20; //¶¨Ê±ÖÜÆÚ 20(0)
TIM_TimeBaseStructure.TIM_Prescaler = 8; //Ô¤·ÖƵ£¬²»·ÖƵ 8(0)
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //ʱÖÓ·ÖƵϵÊý
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊýģʽ
TIM_TimeBaseInit(TIM7, &TIM_TimeBaseStructure);
/* ÅäÖÃTIM7´¥·¢Ô´ */
TIM_SelectOutputTrigger(TIM7, TIM_TRGOSource_Update);
/* ʹÄÜTIM7 */
TIM_Cmd(TIM7, ENABLE);
}
接下来是DAC_DMA通道参数设置void DAC_DMA_Config_1(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* ʹÄÜDMA2ʱÖÓ */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
/* ÅäÖÃDMA2 */
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address; //ÍâÉèÊý¾ÝµØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit_1; //ÄÚ´æÊý¾ÝµØÖ· DualSine12bit
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //Êý¾Ý´«Êä·½ÏòÄÚ´æÖÁÍâÉè
DMA_InitStructure.DMA_BufferSize = 64; //»º´æ´óСΪ32×Ö½Ú
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //ÍâÉèÊý¾ÝµØÖ·¹Ì¶¨
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //ÄÚ´æÊý¾ÝµØÖ·×ÔÔö
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //ÍâÉèÊý¾ÝÒÔ×ÖΪµ¥Î»
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; //ÄÚ´æÊý¾ÝÒÔ×ÖΪµ¥Î»
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //Ñ»·Ä£Ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //¸ßDMAͨµÀÓÅÏȼ¶
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //·ÇÄÚ´æÖÁÄÚ´æģʽ
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
/* ʹÄÜDMA2-14ͨµÀ */
DMA_Cmd(DMA2_Channel4, ENABLE);
}
上面的三段程序都是有关初始化的部分程序,当然也有发送数据的右对齐处理,上面没有贴出。
我在主函数中调用初始化函数之后,上电复位之后,等待 DMA TC标志置位不能成功,但是此时如果能够按键复位一下,程序能够正常执行。就是想知道这个问题的原因。
第一次发帖,不太熟悉这个方式。各位高手请帮忙看一下,如果有什么关于代码的疑问的,我可以继续贴出来。
@smallskiff @mmuuss586 @想做大牛的小马 |