stm32f4的DMA: Double Buffer中断进不去

2019-07-21 05:07发布

DMA2_Stream1的初始化配置:

/* DMA2 Stream1 Configuration */  
DMA_DeInit(DMA2_Stream1);

DMA_InitStructure.DMA_Channel = DMA_Channel_1;  
DMA_InitStructure.DMA_PeripheralBaseAddr = DCMI_DR_ADDRESS;
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Image_Buffer1;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = IMAGE_BUFFER_SIZE; //以字为单位
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_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
/*DMA double buffer mode*/
DMA_DoubleBufferModeConfig(DMA2_Stream1,(uint32_t)Image_Buffer2,DMA_Memory_0);//DMA_Memory_0首先被传输
DMA_DoubleBufferModeCmd(DMA2_Stream1,ENABLE);
DMA_Init(DMA2_Stream1, &DMA_InitStructure); //初始化DMA

Dma_FreeBuf_No = DMA_FREEBUF_NO_2;//因为DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Image_Buffer1;
Dma_FreeBuf_Ok = 0;//此时没有数据准备完成

..........................................


中断服务函数:

void DMA2_Stream1_IRQHandler(void)
{
    DMA_InitTypeDef DMA_InitStructure;
    if(DMA_GetITStatus(DMA2_Stream1,DMA_IT_TCIF1) != RESET)
    {
       DMA2_Stream1_TC_FLAG = 1;
       DMA_ClearITPendingBit(DMA2_Stream1,DMA_IT_TCIF1);
      //转换可操作buf
      if(Dma_FreeBuf_No == DMA_FREEBUF_NO_1)
      {
         DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Image_Buffer1;
         DMA_Init(DMA2_Stream1,&DMA_InitStructure);
         Dma_FreeBuf_No = DMA_FREEBUF_NO_2;
      }
    else
    {
       DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Image_Buffer2;
       DMA_Init(DMA2_Stream1,&DMA_InitStructure);
       Dma_FreeBuf_No = DMA_FREEBUF_NO_1;
    }
   Dma_FreeBuf_Ok = 1;//有准备好的数据了
   }
}

当启用上述代码中的红 {MOD}部分,即开启double buffer模式时,不会进入中断。但是当不启用双buffer模式时可以正常进入中断。
第一次用DMA的double buffer  模式,不知道哪里出错了,诚心向原子哥等各位前辈请教。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答
玄心空月
2019-07-21 10:05
 回复【2楼】 正点原子 :
---------------------------------
谢谢原子哥~发现问题所在了。
f4的double buffer模式开启后,两个buffer是自动切换的,不需要手动配置。
把中断服务程序中的红 {MOD}部分去掉后,进入中断正常。
void DMA2_Stream1_IRQHandler(void)
{
    DMA_InitTypeDef DMA_InitStructure;
    if(DMA_GetITStatus(DMA2_Stream1,DMA_IT_TCIF1) != RESET)
    {
       DMA2_Stream1_TC_FLAG = 1;
       DMA_ClearITPendingBit(DMA2_Stream1,DMA_IT_TCIF1);
      //转换可操作buf
      if(Dma_FreeBuf_No == DMA_FREEBUF_NO_1)
      {
         DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Image_Buffer1;
         DMA_Init(DMA2_Stream1,&DMA_InitStructure);
         Dma_FreeBuf_No = DMA_FREEBUF_NO_2;
      }
    else
    {
       DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Image_Buffer2;
       DMA_Init(DMA2_Stream1,&DMA_InitStructure);
       Dma_FreeBuf_No = DMA_FREEBUF_NO_1;
    }
   Dma_FreeBuf_Ok = 1;//有准备好的数据了
   }
}

一周热门 更多>