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

UART error

What would be the best value for UART buffer? When I put it as 512 it gets crashes, below you can see the putty output 0.000013 : UART Start!

0.415937 : Handle list for mpu9250 service 0x15: 0017 0018 001a 001b 001d 001e 0020 0021 0023 0024 0.416432 : MPU9250 service initialized 0.416770 : Handle list for tag service 0x25: 0027 000.4

but when I update it to 1024, I get the proper output.

0.000013 : UART Start!

0.393025 : Handle list for mpu9250 service 0x17: 0019 001a 001c 001d 001f 0020 0022 0023 0025 0026 0.393522 : MPU9250 service initialized 0.393801 : Handle list for service 0x27: 0029 002a 0.394047 : Temperature service initialized

I did not understood what would be the problem and what would be the best value for buffer?

Parents
  • Hi,

    The UART buffer should be large enough to hold the maximum number of bytes that your application is able to put in the buffer before the data is sent out.

    There is no generic way of estimating this, you should know approximately how much data you may put in the buffer in your application. The easiest way to see if the buffer is large enough is by testing. Just as you did and figured out that 512 was too little, but 1024 was enough.

    Remember that the UART driver will get the next byte in the buffer using interrupt, so if you spend a lot of time in interrupts (event handlers) in your application you may need a larger buffer. In that case you may consider increasing the priority of the UART interrupt.

    And of course the UART baudrate will have an effect. Set it to 115200 or higher if possible.

    Ole

Reply
  • Hi,

    The UART buffer should be large enough to hold the maximum number of bytes that your application is able to put in the buffer before the data is sent out.

    There is no generic way of estimating this, you should know approximately how much data you may put in the buffer in your application. The easiest way to see if the buffer is large enough is by testing. Just as you did and figured out that 512 was too little, but 1024 was enough.

    Remember that the UART driver will get the next byte in the buffer using interrupt, so if you spend a lot of time in interrupts (event handlers) in your application you may need a larger buffer. In that case you may consider increasing the priority of the UART interrupt.

    And of course the UART baudrate will have an effect. Set it to 115200 or higher if possible.

    Ole

Children
Related