Translation - Japanese: PSoC 3, PSoC 4, PSoC 5LP 設計での UDB UART のエラーコンディション対応 - KBA221688- Community Translated (JA)
How should the error conditions be correctly handled when UDB UART is used with PSoC 3, PSoC 4, andPSoC 5LP Designs?
The UDB UART supports detection of errors like parity, stop, and overrun. You need to handle the code correctly to detect these errors reliably. For readability, the component instance name used is UART.
There are two modes of UART operation: FIFO mode (when the RX buffer size is equal to 4) and Buffer mode (when the RX buffer size is greater than 4).
In the current implementation of UART_GetChar() function:
- Buffer mode reads RX FIFO directly, and then the code clears the RX FIFO status. Hence, RX interrupt is not triggered and UART_errorStatus is
- There is no data to read.
- An error in UART occurred.
However, you should be able to differentiate these cases. When an error occurs, it means that the character or even the received packet should be dropped. Whereas when there is no data, it means that it is the end of the packet.
So in Buffer mode, errors might not be correctly detected if UART_GetChar() is used. As a workaround, check whether buffer has data, and then call UART_GetChar(). This will ensure that data is never read from RX FIFO directly, which causes the issue.
You can use this code to avoid the issue.
uint8 packet[PACKET_SIZE]; /* Rx buffer size > 4 */
uint8 idx = 0u;
/* Get packet from the UART buffer */
while ((UART_GetRxBufferSize() > 0u) && (idx < PACKET_SIZE))
packet[idx] = UART_GetChar();
/* Echo the received byte */
/* Check if frame error (for e.g.) occurred */
if (0u != (UART_errorStatus & UART_RX_STS_STOP_ERROR))
/* Mark packet to be neglected */
packet[0u] = 0xFF;
/* Clear RX buffer */
/* Clear error detection variable */
UART_errorStatus = 0u;
/* User can add code below (like setting a GPIO Pin) to indicate that Framing error occurred */