各位大神好,我在使用串口DMA的时候出现了一些问题,下面是问题描述:
int main()
{
init();
while(1)
{
Send_Data(0x01);
Send_Data(0x02);
Send_Data(0x03);
Send_Data(0x04);
Send_Data(0x05);
Send_Data(0x06);
Send_Data(0x07);
Send_Data(0x08);
Send_Data(0x09);
Send_Data(0x0a);
Send_Data(0x0b);
Send_Data(0x0c);
Send_Data(0x0d);
Send_Data(0x0e);
Send_Data(0x0f);
delay_ms (500);
}
}
但是打印出来是这样的
0x01跑到最后了
相关函数:
unsigned char Trans_Done =1;
unsigned char Tx_Tmp[100]={0};
unsigned char Tx_Buffer[100]={0};
unsigned char * pEnd_s = Tx_Tmp;
unsigned char * pEnd = Tx_Buffer ;
void Send_Data(unsigned char data)
{
*pEnd_s = data;
pEnd_s ++;
if (Trans_Done!=0)
{
unsigned int i=0;
unsigned int size = 0;
size =(unsigned int)pEnd_s-(unsigned int)Tx_Tmp;
Trans_Done=0;
DMA1_Channel4->CNDTR = size;
for (i=0;i<size;i++)
{
*(Tx_Buffer+i)=*(Tx_Tmp+i);
}
pEnd_s =Tx_Tmp;
DMA_Cmd(DMA1_Channel4, ENABLE);
}
}
中断:
void DMA1_Channel4_5_IRQHandler(void)
{
DMA_ClearITPendingBit (DMA1_IT_TC4);
DMA_Cmd(DMA1_Channel4, DISABLE);
Trans_Done=1;
}
|