求助用过这个芯片的大佬,串口接收配置为dma方式,当接收到的数据长度与配置长度相等时。输出来始终多着2个字节。请问什么原因
接收配置如下:
/* deinitialize DMA1 channel2 (USART0 rx) */
dma_deinit(DMA1, DMA_CH2);
dma_init_struct.direction = DMA_PERIPH_TO_MEMORY; //传输模式,外设到存储(接收)
dma_init_struct.memory0_addr = (uint32_t)rxbuffer;
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_init_struct.number = 100;
dma_init_struct.periph_addr = (uint32_t)&USART_DATA(USART0);
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_init_struct.periph_memory_width = DMA_PERIPH_WIDTH_8BIT;
dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH;
dma_single_data_mode_init(DMA1, DMA_CH2, &dma_init_struct);
/* configure DMA mode */
dma_circulation_disable(DMA1, DMA_CH2);
dma_channel_subperipheral_select(DMA1, DMA_CH2, DMA_SUBPERI4);
usart_interrupt_enable(USART0, USART_INT_IDLE);
/* USART interrupt configuration */
nvic_irq_enable(USART0_IRQn, 6, 0);
/* enable DMA1 channel2 */
dma_channel_enable(DMA1, DMA_CH2);
usart_dma_receive_config(USART0, USART_DENR_ENABLE);
//串口0 DMA接收,只触发空闲中断
void USART0_IRQHandler(void){
u8 revLen;
if(RESET != usart_flag_get(USART0, USART_FLAG_IDLE))
{
USART_STAT0(USART0);
usart_data_receive(USART0); //清除串口中断
revLen = 100 - dma_transfer_number_get(DMA1, DMA_CH2);
dma_channel_disable(DMA1, DMA_CH2);
dma_transfer_number_config(DMA1, DMA_CH2, 100);
dma_flag_clear(DMA1,DMA_CH2,DMA_INTF_FTFIF);
dma_channel_enable(DMA1, DMA_CH2);
// printf("len:%d %s\r\n",revLen,rxbuffer);
printf("%s",rxbuffer);
memset(rxbuffer,0,100);
}
}
printf输出的信息。当接收数据小于100字节时。都是正确的。当接收数据大于等于100字节时。能输出接收到的100字节数据。但是还多了两个字节0xC4 10
请问各位要怎么解决
|