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 )?
// initialize the SPI for ADC ADS1220 communication
// Start execution.
NRF_LOG_INFO("Debug logging for UART over RTT started.");
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 Hung Bui
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))
// data_array is initialized with RX data buffer from SPI
Not sure if this helps, but it's easy to forget that the application is effectively multi-threaded. ble_nus_data_send() is by default invoked within an event, which is effectively an interrupt to the main(). One might think that sprinkling a few other ble_nus_data_send() calls in (say) main() would not be an issue, but in that case one invocation may be interrupted by another, following which the send buffer data_array becomes corrupted as two messages stomp on each other. Since the serial port i/o and the BLE serial packets are all events, this can get interesting; throw in yet another call from the SPI interrupt and without adding a lock or semaphore or other signal at some point data corruption will occur.
No I am not doing all three calls at the same time. I call the nus_data_send() only once in the entire project. I tried doing these single calls at three different places in the code... I am calling the function once in each case, but I do not get tangible data in any scenario.
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.