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
  • Have you ever config NUS service UUID with peripherial & central?  ble_nus_c_evt_handler() will handle tx

    static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)
    {
    ret_code_t err_code;

    switch (p_ble_nus_evt->evt_type)
    {
    case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
    NRF_LOG_INFO("Discovery complete.");
    err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt->conn_handle, &p_ble_nus_evt->handles);
    APP_ERROR_CHECK(err_code);

    err_code = ble_nus_c_tx_notif_enable(p_ble_nus_c);
    APP_ERROR_CHECK(err_code);
    NRF_LOG_INFO("Connected to device with Nordic UART Service.");
    break;

    case BLE_NUS_C_EVT_NUS_TX_EVT:
    ble_nus_chars_received_uart_print(p_ble_nus_evt->p_data, p_ble_nus_evt->data_len);
    break;

    case BLE_NUS_C_EVT_DISCONNECTED:
    NRF_LOG_INFO("Disconnected.");
    scan_start();
    break;
    }
    }

    Here you are.

  • I have this handler.

    If BLE_NUS_C_EVT_NUS_TX_EVT is called, isn't the DATA transmitted?

    But I don't think this handler is being called.

    Peripheral was made using nRF52810.
    This is not what I made.

    static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)
    {
        ret_code_t err_code;
    
        switch (p_ble_nus_evt->evt_type)
        {
             
            case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
                printf("Discovery complete.");
                err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt->conn_handle, &p_ble_nus_evt->handles);
                APP_ERROR_CHECK(err_code);
    
                err_code = ble_nus_c_tx_notif_enable(p_ble_nus_c);
                APP_ERROR_CHECK(err_code);
                printf("Connected to device with Nordic UART Service.");
                break;
    
            case BLE_NUS_C_EVT_NUS_TX_EVT:
                ble_nus_chars_received_uart_print(p_ble_nus_evt->p_data, p_ble_nus_evt->data_len);
                printf("BLE_NUS_C_EVT_NUS_TX_EVT\n");
                break;
    
            case BLE_NUS_C_EVT_DISCONNECTED:
                printf("Disconnected.");
                scan_start();
                break;
            default:
                printf("client evt handler\r");
                break;
        }
    }

    I have this nus handler...

Reply
  • I have this handler.

    If BLE_NUS_C_EVT_NUS_TX_EVT is called, isn't the DATA transmitted?

    But I don't think this handler is being called.

    Peripheral was made using nRF52810.
    This is not what I made.

    static void ble_nus_c_evt_handler(ble_nus_c_t * p_ble_nus_c, ble_nus_c_evt_t const * p_ble_nus_evt)
    {
        ret_code_t err_code;
    
        switch (p_ble_nus_evt->evt_type)
        {
             
            case BLE_NUS_C_EVT_DISCOVERY_COMPLETE:
                printf("Discovery complete.");
                err_code = ble_nus_c_handles_assign(p_ble_nus_c, p_ble_nus_evt->conn_handle, &p_ble_nus_evt->handles);
                APP_ERROR_CHECK(err_code);
    
                err_code = ble_nus_c_tx_notif_enable(p_ble_nus_c);
                APP_ERROR_CHECK(err_code);
                printf("Connected to device with Nordic UART Service.");
                break;
    
            case BLE_NUS_C_EVT_NUS_TX_EVT:
                ble_nus_chars_received_uart_print(p_ble_nus_evt->p_data, p_ble_nus_evt->data_len);
                printf("BLE_NUS_C_EVT_NUS_TX_EVT\n");
                break;
    
            case BLE_NUS_C_EVT_DISCONNECTED:
                printf("Disconnected.");
                scan_start();
                break;
            default:
                printf("client evt handler\r");
                break;
        }
    }

    I have this nus handler...

Children
No Data
Related