uint8_t Buffrev[5];
DMA_InitStructure.DMA_PeripheralBaseAddr = USART1_DR_Base;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)Buffrev;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = 1;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;
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_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel5, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel5,DMA_IT_TC,ENABLE);
USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE);
DMA_Cmd (DMA1_Channel5,ENABLE);
问题描述:
比如上位机发送的数据为十六进制0x12 0x13 0x14 0x15 0x16五个字节,下位机在开启DMA循环接收模式(DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;DMA_InitStructure.DMA_BufferSize = 5;)后正常传输后Buffrev[0]=0x12,Buffrev[1]=0x13,Buffrev[2]=0x14,Buffrev[3]=0x15,Buffrev[4]=0x16,但万一上位机发送有误或发生干扰,传输的过程中多了或少了一个字节数据,比如实际发送了0x12 0x13 0x14 0x15 0x16 0xAA 六个数据,则第一次数据接收正常,这时其实Buffrev[0]=0xAA,第二次发送正确数据的时候0x12 0x13 0x14 0x15 0x16,接收到0x15就产生了DMA接受中断Buffrev[0]=0xAA,Buffrev[1]=0x12,Buffrev[2]=0x13,Buffrev[3]=0x14,Buffrev[4]=0x15,这样我接受的数据就全部错位了,请问大家如何解决? |