I've been handed a project that has a uart that is tied to a 485 port. The code I received is clearly based on the uart_edma_non_blocking example but it's not working as needed and I'm not finding much documentation on how that example was supposed to work.
Specifics:
Processor: MKV31F
IDE: Kinetis Design Studio
SDK: KSDK_1.3.0
This unit is going to be on a fairly busy communication network. As such I hope to be able to check in on the incoming buffer every milisecond or so, gather all of the data it has and then parse it for action items, etc.
The code I was handed is clearly based on this example code:
C:\Freescale\KSDK_1.3.0\examples\frdmkv31f\driver_examples\uart\uart_edma_non_blocking
In it there is a while loop that checks for a single byte coming off of the wire, then it sends that byte back on the wire. It's meant to be a non-blocking example but as it's written it's basically still blocking. What's more, once I put this device on a loaded network it chokes and turns off the interrupts entirely making me think I'm not servising it properly.
Here's the code straight from the DMA non-blocking uart example:
while(true)
{
// Call received API
UART_DRV_EdmaReceiveData(BOARD_DEBUG_UART_INSTANCE, &rxChar, 1u);
// Wait until we receive a character
while (kStatus_UART_RxBusy == UART_DRV_EdmaGetReceiveStatus(BOARD_DEBUG_UART_INSTANCE, NULL)) { }
// Echo received character
txChar = rxChar;
UART_DRV_EdmaSendData(BOARD_DEBUG_UART_INSTANCE, &txChar, 1u);
}
How should I be using the "UART_DRV_EdmaReceiveData" function? Do I hit it once, then remain locked in a loop until the UART_DRV_EdmaGetReceiveStatus says it's not busy? Should I hit the UART_DRV_EdmaReceiveData, then bounce out and do other chores for a milisecond, then come back and see if it's completed? What makes it say it's completed?
Also, assuming "rxChar" is redefined as an array, what are the implications of asking for more than one byte at a time? Does the rxbusy flag indicate that I've received the number I expected or simply that we're between bytes on the wire?
I had though that there might be documentation for these functions but I'm really not seeing them.
Any thoughts or links to manuals would be appreciated.
Thanks in advance,
-Leeds
For what it's worth, sending data works just fine for me. It's just servicing the receiving portion that isn't yet clear to me.
Hello Leeds,
- The KSDK is open source ,you can find the function source code , for example the function
"UART_DRV_EdmaReceiveData" and "UART_DRV_EdmaReceiveDataBlocking "
- If you use the function "UART_DRV_EdmaReceiveData" , yes , you need read the statue to
check whether the receive has completed , for example :
// Wait until we receive a character
while (kStatus_UART_RxBusy == UART_DRV_EdmaGetReceiveStatus(BOARD_DEBUG_UART_INSTANCE, NULL)){}
If you use the block receive function , the function does not return until the receive is complete .
So you need refer to your requirement to use .
Hope it helps
Alice