STM32F405,
A serial port using DMA receiving, receiving data size,
Question: I through the upper machine to STM to send data (data size, less than 256), for the first time send, receive normal
After sending, access to a serial port interrupt, but there is no data, read dma_cnt was 256, what is the possible reason?
Main program is as follows: RECVBUFF_SIZE=256
Void Debug_USART_Config (void)
{
NVIC_InitStructure. NVIC_IRQChannel=USART1_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=DEBUG_PREE_PRIO;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=DEBUG_SUB_PRIO;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);
USART_Init (DEBUG_USART, & amp; USART_InitStructure);
USART_ITConfig (DEBUG_USART USART_IT_IDLE, ENABLE);
USART_DMACmd (DEBUG_USART USART_DMAReq_Rx, ENABLE);
USART_Cmd (DEBUG_USART, ENABLE);
DMA_DeInit (DEBUG_USART_DMA_STREAM);
While (DMA_GetCmdStatus (DEBUG_USART_DMA_STREAM)!=DISABLE) {}
DMA_InitStructure. DMA_Channel=DEBUG_USART_DMA_CHANNEL;
DMA_InitStructure. DMA_PeripheralBaseAddr=DEBUG_USART_DR_BASE;
DMA_InitStructure. DMA_Memory0BaseAddr=(u32 RecvBuff);
DMA_InitStructure. DMA_DIR=DMA_DIR_PeripheralToMemory;
DMA_InitStructure. DMA_BufferSize=RECVBUFF_SIZE;
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_Normal;
DMA_InitStructure. DMA_Priority=DMA_Priority_Medium;
DMA_InitStructure. DMA_PeripheralBurst=DMA_PeripheralBurst_Single;
DMA_InitStructure. DMA_MemoryBurst=DMA_MemoryBurst_Single;
DMA_Init (DEBUG_USART_DMA_STREAM, & amp; DMA_InitStructure);
DMA_Cmd (DEBUG_USART_DMA_STREAM, ENABLE);
While (DMA_GetCmdStatus (DEBUG_USART_DMA_STREAM)!=ENABLE) {}
}
Void USART1_IRQHandler (void)
{
Uint16_t dma_cnt;
If (USART_GetITStatus (DEBUG_USART, USART_IT_IDLE)!=RESET)
{
USART_ReceiveData (DEBUG_USART);
Dma_cnt=DMA_GetCurrDataCounter (DEBUG_USART_DMA_STREAM);
Uart1_rev_len=RECVBUFF_SIZE - dma_cnt;
If (uart1_rev_len!=0)
{
Uart_parse (RecvBuff);
Hw_memset (RecvBuff, 0, sizeof (RecvBuff));
}
USART_ClearITPendingBit (DEBUG_USART USART_IT_IDLE);
DMA_Cmd (DEBUG_USART_DMA_STREAM, DISABLE);
While (DMA_GetCmdStatus (DEBUG_USART_DMA_STREAM)!=DISABLE) {}
DMA_SetCurrDataCounter (DEBUG_USART_DMA_STREAM RECVBUFF_SIZE);
DMA_Cmd (DEBUG_USART_DMA_STREAM, ENABLE);
}
}
CodePudding user response:
Uart_parse (RecvBuff); What is this