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

Buffer received characters into a string over ble_app_uart

I am using ble_app_uart SDK_11 s130 on nRF51-dk.

I want the received characters to be buffered into a string until a new line character is received. The relevant code for receiving characters over BLE is here;

static void nus_data_handler(ble_nus_t * p_nus, uint8_t * p_data, uint16_t length)
{
    for (uint32_t i = 0; i < length; i++)
    {
        while(app_uart_put(p_data[i]) != NRF_SUCCESS);
    }
    while(app_uart_put('\n') != NRF_SUCCESS);
}

When is nus_data_handler() called? Each time a character is received like uart_event_handle()?

Parents
  • Hi,

    nus_data_handler() is called every time a characteristic is sent from another device. Each characteristic can contain up to 20 bytes and you are free to choose how much data You send (0-20).

    You can send strings byte after byte, and wait for the '\n' but I don't think is the best idea. You can also receive bigger frames and check if the last byte is equal to '\n' or check every byte in frame (it depends on how You wish to form bytes into frames)

Reply
  • Hi,

    nus_data_handler() is called every time a characteristic is sent from another device. Each characteristic can contain up to 20 bytes and you are free to choose how much data You send (0-20).

    You can send strings byte after byte, and wait for the '\n' but I don't think is the best idea. You can also receive bigger frames and check if the last byte is equal to '\n' or check every byte in frame (it depends on how You wish to form bytes into frames)

Children
No Data
Related