I am working on UART DMA function and the UART2 baud rate is set as 115200. PC also set baud rate as 115200,
Both send and receive is correct. However, one of them set different baud rate, for example, MK64F512 device sets 115200 and PC sets as 57600. I send a data from PC to device, the MK64F512 device could not receive any data from PC.
I try to re-call DMA function, re-enable UART2 DMS interrupt, ..... UART2 DMA could not receive any data.
The GetRemaining code is zero after PC sends once data to device with wrong baud rate and the GetRing code as below,
How can I fix the issue?
byteCount = GetRingBufferLengthEDMA_UART0();
uint32_t GetRingBufferLengthEDMA_UART0(void)
{
uint32_t regPrimask = 0U;
uint32_t receivedBytes = 0U;
/* Disable IRQ, protect ring buffer. */
regPrimask = DisableGlobalIRQ();
receivedBytes =
UART_RING_BUFFER_SIZE - EDMA_GetRemainingMajorLoopCount(UART0_RX_DMA_BASEADDR, UART0_RX_DMA_CHANNEL);
/* If the received bytes is less than index value, it means the ring buffer has reached it boundary. */
if (receivedBytes < uart0_ringBufferIndex)
{
receivedBytes += UART_RING_BUFFER_SIZE;
}
receivedBytes -= uart0_ringBufferIndex;
/* Enable IRQ if previously enabled. */
EnableGlobalIRQ(regPrimask);
return receivedBytes;
}
Andy
If the UART receiver detects a framing error (eg. due to mismatch of Baud rate) it will suspend any further reception unti the error flag has been cleared.
This means that you need to handle error interrupts and clear such flags and then also DMA will continue to work (it is not a problem with the DMA itself).
Regards
Mark
[uTasker project developer for Kinetis and i.MX RT]
Hi Mark,
Thank you for your advice and I figure out this issue.