This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART Reception only 6 bytes

Hello,

Using the "simple_uart_get_ with_timeout",I cannot receive a "frame" bigger than 6 bytes. Why?

while(simple_uart_get_with_timeout(1, &UART_RX[receivedBytes])){receivedBytes++;}

How to deal with this problem?

thank you!

  • Best guess: On the latest nRF51 chips the UART FIFO is 6 characters. I suspect the FIFO is already full when you start polling the data out of the FIFO. If you don't have HW flow control turned on it is likely any further characters transmitted by the other side have been dropped. If you do have HW flow control turned on perhaps your other side doesn't resume transmitting quickly enough after you begin polling the characters out of the FIFO.

  • thank you! I have another question, when increase the time out to 450ms.

    while(simple_uart_get_with_timeout(400, &UART_RX[receivedBytes])){receivedBytes++;}
    

    After 2 or 3 sendings, it works. All bytes are received. How to explain this ?

  • When you have 1ms as timeout, you can receive all 6 bytes in the FIFO right away. Probably before your software runs to simple_uart_get_with_timeout, the 6 bytes already received by UART. But for the 7th byte to come into the UART, it will take time based on your BAUDRATE. 1ms is not enough if your baudrate is less than 9600. 450ms sure works. :-)

  • When you wait for up to 1msec this is not long enough for a byte to arrive. Therefore once you have read the bytes in the FIFO the next byte you wait for will take too long and the loop will timeout and exit.

    By lengthening the timeout you are waiting for longer, therefore there is time for another byte to arrive, so the call does not time out and the while loop continues.

Related