Hi Martin,
A couple of positive things happened yesterday, though I need your help to explain the observation.
I did some investigation on this. Observation was that always the characters sent at the beginning of a message are getting corrupted. Hence suspected like it could be something related to start character detection at the OpenSDA end.
The OpenSDA controller in NXP Devkit is MK20DX128VFM5. I looked in to the reference manual of K20 series, just to see how the UART might have been configured in it. In the RM, under description for UART Control Register 1, there is a WAKE bit whose reset value is 0. If this is not programmed by the OpenSDA controller, then it means that Receiver Wakeup Method Selected is Idle line wakeup. This indicated that the OpenSDA could have been going in to an Idle state and we have to wake it up before sending the messages. Hence tried sending 10 bits of logic 1's as mentioned in RM under Idle Line Type Select bit description. This improved situation much better but still I was getting junk characters. occasionally. Then there was a Receiver Wakeup Control bit and Send Break bits. Reading through the description, I got an intuition to send 0's instead of 1's. Hence I decided to send 0's instead of 1's, before sending stream of characters. This made it work.
I can now easily recreate the situations where junk characters can be displayed and fix them. Sending 16 bit logic 0's before each string (not each character) will show the messages cleanly on serial terminal and if I comment it, it will show up junk characters.
I need your help to verify whether this is a reliable solution and if possible I need a theoretical explanation for this observation. I have attached the project I used.
Now it seems to be reliably transmitting the characters without junk characters.
Then I was left with the other two issues - a) losing characters occasionally and b) Serial terminal hangs after printing a few screens of messages.
For a) I thought it could be because of some Rx FIFO overflows and hence reduced the baud from 57600 to 19200 which did the trick. I am not getting the issue a) and b) after reducing the baud rate to 19200. I cannot authentically explain this as well.
Regards
Sandeep