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

[nRF52832] Central, ble_nus_chars_received_uart_print

static void ble_nus_chars_received_uart_print(uint8_t * p_data, uint16_t data_len)
{
    ret_code_t ret_val;

    printf("Receiving data.");
    app_uart_put("receiving data.\r");
    NRF_LOG_HEXDUMP_DEBUG(p_data, data_len);

    for (uint32_t i = 0; i < data_len; i++)
    {
        do
        {
            ret_val = app_uart_put(p_data[i]);
            if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY))
            {
                printf("app_uart_put failed for index 0x%04x.", i);
                APP_ERROR_CHECK(ret_val);
            }
        } while (ret_val == NRF_ERROR_BUSY);
    }
    if (p_data[data_len-1] == '\r')
    {
        while (app_uart_put('\n') == NRF_ERROR_BUSY);
    }
    if (ECHOBACK_BLE_UART_DATA)
    {
        // Send data back to the peripheral.
        do
        {
            ret_val = ble_nus_c_string_send(&m_ble_nus_c, p_data, data_len);
            

            if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY))
            {
                printf("Failed sending NUS message. Error 0x%x. ", ret_val);
                APP_ERROR_CHECK(ret_val);
            }
        } while (ret_val == NRF_ERROR_BUSY);
    }
}

Hi 

using sdk17, softdevice132...

There are some parts of the central implementation that I don't understand.

It is based on cle_uart_app_c.

Isn't the function bl_nus_chars_received_outprint_print_called when connected?

There is no action when associated with peripheral.

Parents
  • Hi,

    The ble_nus_chars_received_uart_print() function is not called when a peripheral is connected, it is only called when the peripheral transfers some data to the central (through notifications). If you are testing towards the ble_app_uart example, connect a serial terminal to the board and write a string after the devices have established a connection. This string will be sent over NUS to the central, which will print it on its own serial terminal/UART connection.

    The TX part of the event (BLE_NUS_C_EVT_NUS_TX_EVT) may be a bit confusing, but it is indicating that the central received data from the peripheral.

    Best regards,
    Jørgen

Reply
  • Hi,

    The ble_nus_chars_received_uart_print() function is not called when a peripheral is connected, it is only called when the peripheral transfers some data to the central (through notifications). If you are testing towards the ble_app_uart example, connect a serial terminal to the board and write a string after the devices have established a connection. This string will be sent over NUS to the central, which will print it on its own serial terminal/UART connection.

    The TX part of the event (BLE_NUS_C_EVT_NUS_TX_EVT) may be a bit confusing, but it is indicating that the central received data from the peripheral.

    Best regards,
    Jørgen

Children
No Data
Related