This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Send string without terminal

Hi,

I try to send a string using example code ble_app_uart_pca10028 without input from terminal ,but directly from inside the code

All of the tutorials I've search send data from terminal

Below are what I've done, but no value appears in nRF Master Control Panel

  char *s = "Hello World";
  for(uint8_t i = 0; i < 5; i++)
  { 		
    uint8_t len = strlen((char *) s);
    for (uint8_t i = 0; i < len; i++)
        while (app_uart_put(s[i]) != NRF_SUCCESS);
  }

The version of Keil is 5.14 The version of SDK is 9.0.0

Parents
  • Hello. Are you using the softdevice s110? If you are, you should use the function ble_nus_string_send( ) to send the data from the nrf51 chip. As an example I have changed the nus_data_handler( ), which handles the data received from the App. Here you see how the nrf51 chip can send data to the application, and also how it can react to data received:

    static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
    {
    	uint32_t       err_code;
    	if (p_data[0] == 'a') { //If first character is 'a'
    		uint8_t data_array[12] = {'a', ' ', 'r', 'e', 'c', 'e', 'i', 'v', 'e', 'd', '\n'};
    		uint8_t length_of_data = 12;
    		err_code = ble_nus_string_send(&m_nus, data_array, length_of_data);
    		APP_ERROR_CHECK(err_code);
        }
    	else {
    		err_code = ble_nus_string_send(&m_nus,  p_data, length);
    		APP_ERROR_CHECK(err_code);
    	 }
    }
    

    If the first character is 'a' then the string "a received" is sent back to the application. If not the received characters is echoed back to the application.

    ble_nus_string_send can be called from other parts of the code, for instance from a function that reads some sensor data.

  • I am also looking a way to send a string without the terminal, ble_nus_string_send function only works in the uart_event_handle() and APP_UART_DATA_READY is only triggered when pressing enter in the terminal(termite). Can someone please post a solution

Reply Children
No Data
Related