nrf52840 and external MCU (central and peripheral) using ble_app_uart example

Dear all,

My objective is to have an external MCU send data to an nrf52840 via UART and directly send this data via BLE to another nrf52840. I started from the ble_app_uart_c and ble_app_uart examples. Connecting two boards each with the respective code programmed, I can easily transmit data from one to another. However, when I try it with an external MCU, the system always ends up in a fatal error and stops at a breakpoint.

The external MCU is sampling data and continuously sending this data via UART. I configured a pin in the master nrf52840 board (connected to the external MCU) to set when the board connects and clear if is disconnected so that the data transmission from the external MCU to the master nrf52840 only starts after the connection. This was done as in the code below:

case BLE_GAP_EVT_CONNECTED:
            err_code = ble_nus_c_handles_assign(&m_ble_nus_c, p_ble_evt->evt.gap_evt.conn_handle, NULL);
            APP_ERROR_CHECK(err_code);

            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);

            // start discovery of services. The NUS Client waits for a discovery result
            err_code = ble_db_discovery_start(&m_db_disc, p_ble_evt->evt.gap_evt.conn_handle);
            APP_ERROR_CHECK(err_code);

            nrf_gpio_pin_set(CONNECTION_CHECK_PIN);

            break;

        case BLE_GAP_EVT_DISCONNECTED:

            NRF_LOG_INFO("Disconnected. conn_handle: 0x%x, reason: 0x%x",
                         p_gap_evt->conn_handle,
                         p_gap_evt->params.disconnected.reason);

            nrf_gpio_pin_clear(CONNECTION_CHECK_PIN);

            break;

But as soon as the two boars try to connect, I get the following errors:

In addition, I made the following changes to the code:

I also modified the value of macro NRF_SDH_BLE_GAP_EVENT_LENGTH from 6 to 400 in the sdk_config.h file in both boards.

In the example ble_app_uart, I set the MIN_CONN_INTERVAL and the MAX_CONN_INTERVAL to 7.5 and 30.

And in the ble_evt_handler function:

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG("PHY update request.");
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_2MBPS,
                .tx_phys = BLE_GAP_PHY_2MBPS,
            };
            err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
            APP_ERROR_CHECK(err_code);
        } break;

As said earlier, all worked with these modifications when testing the boards directly connected to a COM port of the computer (using Tera Term).

I would like to ask:

  1. Increasing the value of NRF_SDH_BLE_GAP_EVENT_LENGTH guarantees event extension?
  2. Assigning BLE_GAP_PHY_2MBPS to .rx_phys and .tx_phys as in the block of code above guarantees the use of 2MBPS physical layer?

Also, would it be possible to give me some help on how to avoid falling into these breakpoints?

Thank you.

Related