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

ble_nus_data_send() usage

Hi,

I am using the NRF52840, softdevice: s140, example: ble_app_uart from nRF5_SDK_15.2.0_9412b96.

short description of my application: i am developing an application that samples external ADC and sends the data sampled over BLE.

the biggest sampling frequency is 1000Hz Set of 8 samples (sampling 8 samples in frequency of 1000 Hz) , and the biggest message rate is 500 messages per second, I am sending every 16 samples in one message, one message is 60B.

when I am sampling in the biggest sampling frequency the NRF52840 manages to sample all the samples and I really get 8000 samples in total as it should be.

when i am adding the communication code to during the samples (sending every 16 samples together) the NRF52840 didn't manage to samples all the required samples ( sampled only ~210 set of 8 samples in one second).

the problem is from the while loop that waits for the sending message, but i did some changes

1. changed the BLE_GATT_ATT_MTU_DEFAULT from 23 to 247 , it helped to increase the samples to ~296 set of 8 samples in one second

2. the NRF_SDH_BLE_GAP_DATA_LENGTH is 251 already

3. tried to cancel the loop for message sending, every time i received NRF_ERROR_RESOURCES when I am trying to send message I added this message to message buffer to send, after that I enter the sending message in my application main loop and whenever this buffer have messages to send I try to send the next message to send. but something weird happens.

-when it is a sending loop that try to send the message every time it return NRF_ERROR_RESOURCES  it works.

- but when I added this buffer to help me get the sending be part of my application loop , and when I tried to send a message that I got NRF_ERROR_RESOURCES for it before, i got a  NRF_ERROR_TIMEOUT error from the  ble_nus_data_send() function.

can you say what i am doing wrong !?

why when the loop is small and trying to send before it all it works.

and when I try to send once in my application loop, I got NRF_ERROR_TIMEOUT for something tried to send before and got NRF_ERROR_RESOURCES  for it .

Parents
  • Hi,

    i managed to make it work

    now the ble_nus_data_send() function not returning timeout error.

    now my application can sample all the samples as it should be, and all messages that can't be sent ( received resources error )  added to some buffer where i retries to send them again and again until all the messages in that buffer have been sent in a correct order of course.

    the problem is at some point the function ble_nus_data_send() to stuck and stop sending the messages and always return resources error.

    tried to increase\decrease the connection interval and that cause the ble_nus_data_send() function to stuck and send less messages until it starts to return resources error continuously !.

    any suggestions please

  • Hi,

    jawadk said:
    the problem is at some point the function ble_nus_data_send() to stuck and stop sending the messages and always return resources error.

    That's a bit strange; the link should be terminated if the packets are not being sent. Are you calling it from main context so that it is not blocking softdevice events? Note that you can use the BLE_GATTS_EVT_HVN_TX_COMPLETE event to monitor the packet transfer (GATT Handle Value Notification MSC).  

      

  • Hi, and thanks for your reply.

    Found the problem, but it's so weird ! can't understand it, if you can explain it please.

    the function Send_Message() that  calls to ble_nus_data_send() implemented in the main.c file

    when i call Send_Message() from X.c file it works, but when i call it from another Y.c file it's not.

Reply Children
Related