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

LIBUARTE+BLE_APP_UART (ble_nus_data_send seems can't handle too many data or fast enough that comes from libuarte - app just hangs)

Hi Nordic Support Team,

My current setup is : Android Phone <--BLE--> nRF52840 <--LIBUARTE--> External STM32 MCU

I started the example with this folder in the link provided (pca10056 with S140):

https://devzone.nordicsemi.com/f/nordic-q-a/71665/nrf-52832-uart-high-speed-communication/294686#294686

It works fine when I am sending command from my phone to nRF and send to the external MCU.

However, when I tried fetching data from the nRF to the phone through ble_nus_data_send(), the nRF will only send some data (outputted to my phone serial terminal) and then hangs, even when I am in debug mode, the application doesn't even stop. (maybe it it stuck in a while loop or something). Note that nRF and external MCU is exchanging a lot of data at baud rate of 115200.

Also, by "hangs" means that the device doesn't react to my command request from the phone and the debug terminal doesn't output anything after.

When I commented out the ble_nus_data_send() part, the uart is exchanging data smoothly between nRF and External MCU.

I have looked through some of the threads relating to this implementation, but I don't what I am doing wrong here. I think these important pieces of code will be able to show you :

  • Can it be that the code is asserting and entering fault handler? Maybe check if APP_ERROR_CHECK(ret); occurs and what 'ret' is?

    Kenneth

  • Hi Kenneth, ret = 19 so it is NRF_ERROR_RESOURCES

    I found that it in some occasion if it sends everything successfully, it will return NRF_SUCCESS then everything will be displayed in my phone serial monitor.

    If it doesn't, then it will display some partial data into the phone serial monitor, then the ret keeps returning NRF_ERROR_RESOURCES which makes it stuck in the while loop in the example code.

  • Then, in this case you may need to change the implementation such that you do as described for the error code:
    "Wait for a @ref BLE_GATTS_EVT_HVN_TX_COMPLETE event and retry."

    You may then need to buffer the data so you can call it on BLE_GATTS_EVT_HVN_TX_COMPLETE  event.

    Kenneth

  • Ok, I will try this. And also, for anyone looking, this thread is really useful.

    devzone.nordicsemi.com/.../ble-lost-messages

  • Hi Kenneth,

    So I made these adjustment on the code :

    And under ble_evt_handler, I added this case 

    So I set a tx_buffer_free as a global variable, basically what I think it does is the while loop will always be executed until the BLE_GATTS_EVT_HVN_TX_COMPLETE is executed by the SoftDevice Interrupt and changing the tx_buffer_free variable to break from the while loop.

    In reality, I always got the ret code as 19 and tx_buffer_free is always 0. Seems like it never goes into BLE_GATTS_EVT_HVN_TX_COMPLETE, but on other cases where there aren't too much packets coming in. It will print out the "NOTIFICATION_TX_COMPLETE". 

    Can you point out what I am doing wrong here?

1 2