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

Queries on nus_data_send() functionality?

Hi, I have a few general questions on nus_data_send(). 

First off, is there another known way of transferring an array/string via ble to the Nordic mobile app other than the NUS service? 

Secondly, does the nus_data_send() function always need an interrupt/event to get called? 

I am starting with the BLE_UART example in Embedded Studio (SDK 15.2). The main program goes into an indefinite for (';;) loop idle state handle after calling advertising_start(). The way I see this is that the chip is continuously in a low power mode and it advertising so it needs an interrupt (GPIO or NUS or UART)  to initiate a data transfer? 


Why does a program including BLE have to move into a low power sleep state? Can I write a custom data send function including the nus_data_send() and call it in the main successfully with the idle_state_mgmt () function running in an infinite loop at the end? Should the data_send() in the below main program work (i.e. be called despite the for(;;) loop after the advertising  )? 

int main(void)
{
    bool erase_bonds;

    // Initialize.
    uart_init();
    log_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();
    // SPI 
    init_pins(); 

    nrf_delay_ms (10); 
    // initialize the SPI for ADC ADS1220 communication 
    init_spi(); 

    // Start execution.
    printf("\r\nUART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();

    data_send() ; 

   
    for  (;;)
    {
       idle_state_handle(); 
    }
   
   

}

Parents Reply Children
  • Thank you

    I have tried calling nus_data_send() function from:

    1. within the NUS_DATA_HANDLER,

    2. The main program after advertising_start()

    3. The SPI event handler (I am using SPI communication to get data from my ADC chip ADS1220 so I call the nus_data_send of spi data from the spi_evt_handler). So I tried calling the data transfer from the SPI/NUS "interrupts" and the main() but it seems it's not being called properly.  

    The data it sends me on my Android phone NRF_TOOLBOX app does not make sense. I am sure the SPI within the ble-uart project is working correctly (I analyzed pins) but I don't get why the nus_data_send won't throw the spi values to the app.. 
    I am using nrf52382, IDE is embedded studio, SDK 15.2, and I am programming a custom made PCB device using NRF52 DK.

    This is how my app receiving data from the board via BLE and my function call looks like... 

      

      err_code1 = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
                            if ((err_code1 != NRF_ERROR_INVALID_STATE) &&
                                (err_code1 != NRF_ERROR_RESOURCES) &&
                                (err_code1 != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code1);
                            }
    
    
    // data_array is initialized with RX data buffer from SPI 

  • What do you mean by "the data on the app does not make sense" ?

    Have you checked the hex value you see in "Notification received from..." if it's is correct ? The weird characters you  see in the screenshot was simply because it's expected to printout ASCII character (Unicode actually) and the value you are sending to the app is clearly not ASCII characters. 

  • I understand that my value is a HEX/int which is why the ASCII characters on screen do not make sense. 
    Is the value shown after  "Notification received from..." the original array value? The 0x-FF-FF-FF-FF....? If so I think that may be the right kind of data I'm expecting. 

    I still have two questions though? How do I convert my int or hex array to ASCII? Do I have to convert to ASCII or should the  "Notification received from..." part show me my data as it is anyway?  

    I tried using defining a char array and sending that array with my HEX data through the ble_nus_string_send() but that gives me an error as well. The program says I am calling ble_nus_string_send() implicitly and that it is an UNDEFINED call. I made sure I am including "string.h" and "stdlib.h".... How can I use the string_send() function accurately? 

  • Which ble_nus_string_send() are you talking about ? Do you mean ble_nus_data_send() ? 

    I am not sure what exactly you want to do . If you want to display the hex value of your data you can follow what we do in the app (the logging "Notification received from... " ) . 

  • The ble_nus_string_send() is a function for sending string data, like data_send() but different in that it's for string values. Since my data is hex I wanted to send it as a string. 

Related