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

Use of nus_data_send() in user made data send function

Hi everyone, 

I want to transmit a HEX array I read from a peripheral using SPI communication (I initialize my RX_BUF in the SPI_EVT_HANDLER() function) via BLE. I am using a mobile app (nrfConnect and nrf Toolbox) to receive data from the device. The device is a custom made PCB using nrf52832. I start with the ble_uart example in SDK 15.2 (Embedded Studio), and add SPI functionality. I think my SPI communication works fine and initializes the data array okay. 

I am using the NUS service to transmit data via ble. When I call ble_nus_data_send() outside of the nus_data_handler () function, it does not work. Even though this post (https://devzone.nordicsemi.com/f/nordic-q-a/43576/queries-on-nus_data_send-functionality) says that the function call and data transfer can be done anywhere in the project. I try calling the ble data send function in the main loop, didn't send anything to my NRF_TOOLBOX mobile app. Then I removed it from the main loop and tried calling nus_data_send() in my spi event handler instead, but it wouldn't throw anything to the mobile app there either. 

My goal here is to control when the data transfer via ble occurs. I don't want the project to send data whenever the nus_data_handler (i.e. a ble event occurs) is called. I want the transfer to happen when my SPI event is called. Or when I am requesting data from my peripheral. But the nus_data_send() doesn't work that way apparently..? 

                      1. I tried calling the spi_evt_handler inside the nus_evt_handler in an attempt to merge these two events (I want them to happen at the same time), but that didn't work. The program doesn't send anything to the app in that case, and I'm guessing it's because it gets stuck in calling a function from within another. 

                      2. I cannot see my received array on my RTT log. I have disabled all uart use so that my custom device works properly (there was a pin use clash). 

Can someone please help me understand this nus_data_send() functionality? And how I can use it to call it in my custom made data call function? 

Parents
  • Hi, 

    When you see something doesn't work as expected. Please try to debug. 

    To debug in this case you would need to check the return code of the API(s) you call, ble_nus_data_send() . YOu need to check if it return err_code = NRF_SUCCESS or not. 

    You can also step into the code and see which exact function return the error code if it's not normal (NRF_SUCCESS). Most likely the error comes from sd_ble_gatts_hvx() and then you can have a look at the description of the function and have a suggestion on why that happened.

    I would suspect that it was because the connection has not been established and the CCCD (notification) was not enabled. 

Reply
  • Hi, 

    When you see something doesn't work as expected. Please try to debug. 

    To debug in this case you would need to check the return code of the API(s) you call, ble_nus_data_send() . YOu need to check if it return err_code = NRF_SUCCESS or not. 

    You can also step into the code and see which exact function return the error code if it's not normal (NRF_SUCCESS). Most likely the error comes from sd_ble_gatts_hvx() and then you can have a look at the description of the function and have a suggestion on why that happened.

    I would suspect that it was because the connection has not been established and the CCCD (notification) was not enabled. 

Children
No Data
Related