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

Sending string data over NUS

Hello,

I am trying to modify the ble_app_uart code so that my peripheral can send data automatically to the central, which in turn can print it on a computer through UART. What I mean is that instead of the ble_nus_string_send() command being called when I press enter, I want the peripheral to send a number automatically from the main.

This is the code I'm using for sending the number in the peripheral, which prints the value of number correct starting at 1:

    uint8_t number = 0;
    uint8_t data[20]; 

    for (;;)
    {

        number = number + 1;

        sprintf((char *)data, "%d", number); 

        ble_nus_string_send(&m_nus, data, sizeof(data));
    }

This is the code in the central, in the case that BLE_NUS_C_EVT_NUS_TX_EVT happens it calls this function:

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

    NRF_LOG_DEBUG("Receiving data.");
    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))
            {
                NRF_LOG_ERROR("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);
    }
}

As far as I know, with the ble_nus_string_send the central should receive and print the number on the other PC. From what I know, the central enters ble_nus_c_evt_handler to establish connection but the NUS_TX_EVT is not being called.

How can I fix this? Or is there a better way to send a number from the peripheral and have the central simply print it to UART?

I'm using NRF52832 and S132.

Parents Reply Children
No Data
Related