Serial (UART) communication

Here is the code, it works fine

No what you posted does not work at all. You need to post ALL your code.

See why here :- http://snippets-r-us.com/

A reminder is here:- https://www.youtube.com/watch?v=tdQL_7osGzc