This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UART data loss

Respected all,
This is my first query over this forum so I thank you for your support well in advance.

I am simply trying to use the following "USART_PutChar" function which would send the data bytes via uart4.

Now, my code is calling this "putchar" function each time one of my sensor receives the data.

The function is as follows:


void USART_PutChar(char *ch)
 {

        while((*ch!='\0'))
         {

                        while(!(UART4->SR & USART_SR_TXE));
                                UART4->DR = *ch;
        ch++;

   }

 }

The issue is as follows:
When the data is sent to the sensor on a slower pace, let say twice a second or so, the data is coming fine.
But when this rate increases, there is data loss and the data stops coming.

When I removed this line from the code above,

                        while(!(UART4->SR & USART_SR_TXE));

,

the data starts coming but then the data turns out bit random (full of spaces and all).

Well, this shows that the TX/RX pin is somehow causing the difference.

Can anyone kindly assist me in this regard.

Thanks
Regards

Parents
  • There are several things missing from your problem presentation. The most crucial ones are: the baudrate your serial output is configured to, and the length of the string that you send as "the data". And when you say "the rate increases": to what level does it increase? All combined, the question is: are you sure you're not simply overloading your serial output channel with too much data?

    The function itself is also quite wrongly named. That function is not outputting a character, but rather an entire string.

    The function busy-loops for as long as one string needs to be transmitted. That may be too long for some other functions not to be starved of CPU time.

Reply
  • There are several things missing from your problem presentation. The most crucial ones are: the baudrate your serial output is configured to, and the length of the string that you send as "the data". And when you say "the rate increases": to what level does it increase? All combined, the question is: are you sure you're not simply overloading your serial output channel with too much data?

    The function itself is also quite wrongly named. That function is not outputting a character, but rather an entire string.

    The function busy-loops for as long as one string needs to be transmitted. That may be too long for some other functions not to be starved of CPU time.

Children
No data