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

Modifying UART peripheral example to send data without using UART peripheral

SDK: 15.1
IDE: Keil
Softdevice: S132 v6.0

Hello, I am using the ble_app_uart example as a starting point.  My goal is to send 5 bytes every 5 seconds to another nRF52 Development kit acting as the Central.  For the central, I used ble_app_uart_c example.  I have established successful link between the peripheral and client to send 5 bytes of my data.  To do this, I created an App Timer, that every 5 seconds calls ble_nus_data_send() in the handler and transmits the array of 5 bytes to the central.  This is working properly and I am able to see the 5 bytes of data every 5 seconds at the central side using a terminal program.

The question is, on the peripheral side, I would like to disable the UART peripheral since I no longer need it since I am plugging in my own data into ble_nus_data_send().  When I try to disable the UART by commenting out uart_init() inside the main() function, the devices stop connecting
 

uart_init();
 

What code needs to be modified in order to disable the UART without breaking the functionality I described above?

Parents
  • Try not sending received data from BLE to the uart; modify this code assuming you haven't already done that:

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    
        if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
    
            NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
            NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
                do
                {
                    err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
                    if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
                    {
                        NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
                        APP_ERROR_CHECK(err_code);
                    }
                } while (err_code == NRF_ERROR_BUSY);
            }
            if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
            {
                while (app_uart_put('\n') == NRF_ERROR_BUSY);
            }
        }
    
    }
    

  • Hello hmolesworth,

    I have already commented out the contents of this handler, see below:

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    //
    //    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    //    {
    //        uint32_t err_code;
    
    //        NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
    //        NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    
    //        for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
    //        {
    //            do
    //            {
    //                err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
    //                if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
    //                {
    //                    NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
    //                    APP_ERROR_CHECK(err_code);
    //                }
    //            } while (err_code == NRF_ERROR_BUSY);
    //        }
    //        if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
    //        {
    //            while (app_uart_put('\n') == NRF_ERROR_BUSY);
    //        }
    //    }
    //
    }

    Even with this, I cannot remove the uart_init() function call without loosing functionality

Reply
  • Hello hmolesworth,

    I have already commented out the contents of this handler, see below:

    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    //
    //    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    //    {
    //        uint32_t err_code;
    
    //        NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
    //        NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    
    //        for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
    //        {
    //            do
    //            {
    //                err_code = app_uart_put(p_evt->params.rx_data.p_data[i]);
    //                if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY))
    //                {
    //                    NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code);
    //                    APP_ERROR_CHECK(err_code);
    //                }
    //            } while (err_code == NRF_ERROR_BUSY);
    //        }
    //        if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r')
    //        {
    //            while (app_uart_put('\n') == NRF_ERROR_BUSY);
    //        }
    //    }
    //
    }

    Even with this, I cannot remove the uart_init() function call without loosing functionality

Children
Related