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

Why is an array used to to receive 1 byte of data in uart_event_handle:APP_UARTD_DATA_READY?

This is more of a question than a problem:

I have been studying the ble_app_uart_c code and noticed that although data is transmitted to the handler one byte at a time, the data is buffered into an array that is 20 bytes in size. Is there a reason for this?  Is there some underlying reason for this? 

Thanks again,

Robin @ TL 

Parents
  • Hello,

    That is correct. That is, it either waits for the buffer to fill up (20 bytes by default), or until it receives an '\r' or '\n' character before it sends it.

    This is only an application choice. It is more power efficient to buffer up and send more characters at once. In addition, it will be possible to send a message consisting of several characters in one message. 

    If you for some reason want to change this to send only one character at the time, that is perfectly fine.

    Best regards,

    Edvin

  • Hello Edvin,

    I hope your new year is starting out in a healthy and prosperous way!  

    Thanks for the prompt reply.  Since I am not sure how the PC UART interface app I am using handle these string, and one char per xmit is working, I probably should maintain that process.  

    But I will ask if you know of an example that uses longer string lengths.  I am sure I can sus it out, but a comparison is always helpful..

    Thanks again 

    Best to you,

    Robin@ TL 

  • Hello Robin,

    I don't know what SDK version you are using, but in the later SDKs, the UART buffer has the a larger size. Whenever a byte is received, it is compared to the parameter m_ble_nus_max_data_len, which is the connections data length. When a connection is initiated, this is set to 20, but the peripheral will negotiate a higher connection data length (MTU). Depending on what the central replies with, the buffer will be increased. This new buffer length is printed in the log from the callback gatt_evt_handler() in main.c.

    As for UART, there is no "message length" in the UART protocol. UART is just transmitted one byte at the time. This is why we have this buffer length and the \r\n to determine when to send the message.

    Best regards,

    Edvin

  • Hello Edvin,

    Thank you for confirming what I eventually figured out myself.  I apparently had yet another one of those "senior moments".  

    Thanks again,

    Until we e-meet again...

    Robin @ TL 

Reply Children
No Data
Related