Best way to debug bt_nus_send()?

Hi, I am testing out the UART Peripheral sample on the nRF52840 DK. Since I am communicating with another MCU, I have remapped the RX and TX pins to P0.26 and P0.27 respectively and set the baud rate to 9600.

I am using nRF Connect on Android to test sending and receiving data. 

It seems that TX is working fine, as the connected external device is responding as expected. However, whenever the device tries to pass something back, I get the following on RTT:

I have enabled notifications on the client side so the issue isn't that. Is there a way to know the reason why it has failed? The documentation on the bt_nus_send() function doesn't go into error return codes.

Thanks.

Parents
  • Hi,

    I have enabled notifications on the client side so the issue isn't that.

    I assume you clicked the "Enable notifications" button then.


    Could you try to print the error-code? Try modifying the ble_write_thread() so it looks something like this:

    void ble_write_thread(void)
    {
        int err = 0;
    	/* Don't go any further until BLE is initialized */
    	k_sem_take(&ble_init_ok, K_FOREVER);
    
    	for (;;) {
    		/* Wait indefinitely for data to be sent over bluetooth */
    		struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
    						     K_FOREVER);
            err = bt_nus_send(NULL, buf->data, buf->len);
    		if (err) {
    			LOG_WRN("Failed to send data over BLE connection. Error: %d",err);
    		}
    
    		k_free(buf);
    	}
    }

Reply
  • Hi,

    I have enabled notifications on the client side so the issue isn't that.

    I assume you clicked the "Enable notifications" button then.


    Could you try to print the error-code? Try modifying the ble_write_thread() so it looks something like this:

    void ble_write_thread(void)
    {
        int err = 0;
    	/* Don't go any further until BLE is initialized */
    	k_sem_take(&ble_init_ok, K_FOREVER);
    
    	for (;;) {
    		/* Wait indefinitely for data to be sent over bluetooth */
    		struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,
    						     K_FOREVER);
            err = bt_nus_send(NULL, buf->data, buf->len);
    		if (err) {
    			LOG_WRN("Failed to send data over BLE connection. Error: %d",err);
    		}
    
    		k_free(buf);
    	}
    }

Children
  • Thanks Sigurd. Regarding enabling notifications, I think the app has the icons backwards, see below:

    Now, I found that if the value is set to "Notifications enabled" (0x01-00), I am actually receiving data on the client side. However, the RTT is still showing various warnings:

    Can you provide any guidance on how to find the root cause?

    Thanks.

  • whyeye said:
    Regarding enabling notifications, I think the app has the icons backwards, see below:

    When the notifications is disabled, you have the option to enable it by clicking the button:
    When the notifications is enabled, you have the option to disable it by clicking the button:


    whyeye said:

    However, the RTT is still showing various warnings:



    Try setting this in prj.confg, and then request longer MTU from the phone.

    CONFIG_BT_USER_DATA_LEN_UPDATE=y
    CONFIG_BT_USER_PHY_UPDATE=y
    CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n
    
    CONFIG_BT_BUF_ACL_RX_SIZE=251
    CONFIG_BT_GATT_CLIENT=y
    CONFIG_BT_ATT_PREPARE_COUNT=2
    CONFIG_BT_CONN_TX_MAX=10
    CONFIG_BT_L2CAP_TX_BUF_COUNT=10
    CONFIG_BT_L2CAP_TX_MTU=247
    CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y
    CONFIG_BT_CTLR_PHY_2M=y
    CONFIG_BT_CTLR_RX_BUFFERS=2
    CONFIG_BT_BUF_ACL_TX_COUNT=10
    CONFIG_BT_BUF_ACL_TX_SIZE=251
    CONFIG_BT_CTLR_DATA_LENGTH_MAX=251

Related