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
  • Hi, 

    As the name BLE suggested, it's for low power application. You can of course choose not to put the CPU to sleep. If you don't want to do processing inside an interrupt you can use app scheduler to put your code into main context. 
    If you don't need to wait for an interrupt, you can call any function from main, no problem. 

  • 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 

Reply
  • 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 

Children
Related