How to decrease NUS size in peripheral_uart example available in NCS 1.9.1?

Hey! I am starting my studies in the BLE protocol and I would like to send the ZE03 sensor data through the Nordic UART Service (NUS).

The sensor has 9 bits: 8 data bits and 1 stop bit.

The problem is that by default BT_NUS_UART_BUFFER_SIZE is set to 40. If I change the default value to a number less than 40, my application crashes and a blue LED lights up on my nRF52840 dongle.

I am able to increase the value of the NUS buffer as per the answer available at devzone.nordicsemi.com/.../ncs-1-6-1-peripheral_uart-example---increasing - nude size.

But I can't lower this buffer. With this I can only send 45 bits from my sensor at a time. But what I want is to only send 9 bits every second.

Can someone help me?


Thanks in advance for your cooperation!

Parents
  • Hello,

    The sensor has 9 bits: 8 data bits and 1 stop bit.

    The problem is that by default BT_NUS_UART_BUFFER_SIZE is set to 40. If I change the default value to a number less than 40, my application crashes and a blue LED lights up on my nRF52840 dongle.

    So 8 bits and 1 stop bit is the standard UART communication for a byte. 8 bits in a byte, and one bit indicating that it is complete. That is also the standard way that it is set up in the examples in our SDKs. So when you see BT_NUS_UART_BUFFER_SIZE 40, did you try reducing it to 1?That should give you one byte = 8 bits. 

    However, looking at the table you attached, this looks like 9 bytes, so in that case, you may want to set the buffer to 9, and then you should see that you get the interrupt after 9 bytes are received. Each of those 9 bytes would have 8 data bits and one stop bit.

    Best regards,

    Edvin

  • Hey!

    Thanks for your reply and cooperation. However, as I said before, if I reduce the BT_NUS_UART_BUFFER_SIZE to 9 bytes or any value less than 40 bytes, my device crashes and a blue led on the nRF52840 dongle lights up. With this error I can't even locate the bluetooth device.

    Note in my previous image that I can only receive 45 bytes at a time (45 = 9*5) because I can't put BT_NUS_UART_BUFFER_SIZE smaller than 40.

    There is some other configuration that I don't know how to do, if you can help me I appreciate the collaboration.

  • Ah, I see.

    Since you are writing "BT_NUS_UART_BUFFER_SIZE", and not "CONFIG_BT_NUS_UART_BUFFER_SIZE", does that mean that you are changing it in the examples Kconfig file? In that case, try to change it in the prj.conf file instead, by adding a line saying:

    CONFIG_BT_NUS_UART_BUFFER_SIZE=40

    The reason I didn't understand this was a config was because you didn't use the CONFIG_BT... I am sorry. The reason it will not work setting this lower is because that is the buffer size for the BLE communication. It has a minimum length that it requires to have.

    Either way, I believe a better approach would be to change the uart_cb function instead. Even though the Bluetooth Low Energy buffer is large, you can still send shorter packages. Try changing:

    		if (buf->len == UART_BUF_SIZE) {
    			k_fifo_put(&fifo_uart_rx_data, buf);

    to

    		if (buf->len == MY_MESSAGE_SIZE) {
    			k_fifo_put(&fifo_uart_rx_data, buf);

    And add:

    #define MY_MESSAGE_SIZE 9

    close to the top of main.c. This way, it will send the data over BLE when the UART has received 9 bytes, instead of filling up the buffer.

    Best regards,

    Edvin

Reply
  • Ah, I see.

    Since you are writing "BT_NUS_UART_BUFFER_SIZE", and not "CONFIG_BT_NUS_UART_BUFFER_SIZE", does that mean that you are changing it in the examples Kconfig file? In that case, try to change it in the prj.conf file instead, by adding a line saying:

    CONFIG_BT_NUS_UART_BUFFER_SIZE=40

    The reason I didn't understand this was a config was because you didn't use the CONFIG_BT... I am sorry. The reason it will not work setting this lower is because that is the buffer size for the BLE communication. It has a minimum length that it requires to have.

    Either way, I believe a better approach would be to change the uart_cb function instead. Even though the Bluetooth Low Energy buffer is large, you can still send shorter packages. Try changing:

    		if (buf->len == UART_BUF_SIZE) {
    			k_fifo_put(&fifo_uart_rx_data, buf);

    to

    		if (buf->len == MY_MESSAGE_SIZE) {
    			k_fifo_put(&fifo_uart_rx_data, buf);

    And add:

    #define MY_MESSAGE_SIZE 9

    close to the top of main.c. This way, it will send the data over BLE when the UART has received 9 bytes, instead of filling up the buffer.

    Best regards,

    Edvin

Children
No Data
Related