Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

PSoC™ 5, 3 & 1 Forum Discussions

RaAl_264636
Level 5
Level 5
50 sign-ins 25 sign-ins 10 solutions authored

Hello,

I'm using a PSoC5LP where STDIN/STDOUT is retargeted to the UART by corresponding _read()/_write() functions. This works as expected. Now, I need to extend the functionality so that it's possible to convert the newline characters at run-time for both receive and transmit.

For transmit, it is easy to implement since the character to be sent is known prior to sending it. For example, if all outputs by printf() are using '\n' (linefeed character LF = 0x0A), but the system I'm connected to expects '\r\n' (carriage return + linefeed, CRLF = 0x0D0A), I can send the carriage return prior to the linefeed character. The same for the case that the application uses CRLF, but only CR or LF has to be sent.

For receive, this is somewhat harder to implement. I'm not using scanf() functions, the application needs to process each incoming character separately. So the getchar() function is used and therefore calls to _read() are always performed with a length of one character. Now I wonder how I can translate incoming LF, CR, CRLF and even LFCR (uncommon, but possible). Replacing LF by CR and vice versa shouldn't be a problem. Using LF only as newline for the application would imply to always simply throw away the CR if CRLF is received, but I want to keep the option that CR is still recognized if the following character is not a LF.
Since the current structure of the UART API doesn't allow to insert characters into the transmit/receive buffers by the UART interrupt, the only way I could imagine for solving this is to have a small state-machine within the _read() function handling those cases. Any other ideas?

Regards

0 Likes
1 Reply
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

RaAl,

You can find basic PSoC5  UART Rx example here

UART string reception garbage value

 

It handles both CR, LF or combination of them

 

0 Likes