片子是smt32F407 程序目的是通过UART4接收数据,积攒到5个的时候,由CAN按顺序发出,采用DMA doublebuffer模式。
现在遇到一个问题,buffer2的时候CAN发出的数据全是0,buffer1正常,发送数据的数目也正常
代码如下
[mw_shl_code=c,true]void DMA1_Stream2_IRQHandler(void)
{
if(DMA_GetITStatus(DMA1_Stream2,DMA_IT_TCIF2)!=RESET)
{
if(DMA_FreeBuffer_No==1)
{
DMA_FreeBuffer_No=0;
DMA_ClearITPendingBit(DMA1_Stream2,DMA_IT_TCIF2);
k=0;
for(k=0;k<13;k+=3)
{
j++;
Can_send(0x0203,UART4_RECIEVE_DATA[k],UART4_RECIEVE_DATA[k+1],UART4_RECIEVE_DATA[k+2],0,0,0,0,j);
Delay(4000);
}
j=0;
}
else
{
DMA_FreeBuffer_No=1;
DMA_ClearITPendingBit(DMA1_Stream2,DMA_IT_TCIF2);
n=0;
for(n=0;n<13;n+=3)
{
j++;
Can_send(0x0204,UART4_RECIEVE_DATA2[n],UART4_RECIEVE_DATA2[n+1],UART4_RECIEVE_DATA2[n+2],0,0,0,0,j);
Delay(4000);
}
j=0;
}}}[/mw_shl_code]
[mw_shl_code=c,true] DMA_DeInit(DMA1_Stream2);
DMA_StructInit(&DMA_InitStructure);
DMA_InitStructure.DMA_Channel = DMA_Channel_4;
DMA_InitStructure.DMA_PeripheralBaseAddr = UART4_DR_Addr; //UART4_DR_Addr;
DMA_InitStructure.DMA_Memory0BaseAddr =(uint32_t)UART4_RECIEVE_DATA;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize =ReBufferSize;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable ;
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull ; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single ;
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream2, &DMA_InitStructure);
DMA_ITConfig(DMA1_Stream2, DMA_IT_TC, ENABLE);
DMA_Cmd(DMA1_Stream2,ENABLE);
DMA_DoubleBufferModeConfig(DMA1_Stream2,(uint32_t)UART4_RECIEVE_DATA2,DMA_Memory_0);
DMA_DoubleBufferModeCmd(DMA1_Stream2,ENABLE);
DMA_FreeBuffer_No=1;[/mw_shl_code]
[mw_shl_code=c,true]int main(void)
{NVIC_Config();
TIM_Config();
CAN1_Config();
DMA_Config();
while(1)
{}}[/mw_shl_code]
|