UART only works when bluetooth is connected.

Hi, I'm currently having a problem with the uart peripheral.

I have an STM32 MCU connected to the NRF52840. In this case, the NRF acts only as a "transceiver".

Whenever I receive data from the Bluetooth stack, I send it via UART.
Whenever I receive data from the UART peripheral, I send it via Bluetooth.

If the NRF is connected to bluetooth, it works as expected, but I can't receive data from UART when Bluetooth is not connected. I really need this because information that'll be shown in advertising will be received from the main MCU before anyone connects via Bluetooth.

I'm using the following softdevice: `s140_nrf52_7.2.0_softdevice`

I set up UART like:

    uint32_t errorCode;
    const app_uart_comm_params_t uartInit = {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
        .baud_rate    = NRF_UART_BAUDRATE_115200};

    APP_UART_FIFO_INIT(&uartInit,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       Serial_SRV_Handler,
                       APP_IRQ_PRIORITY_LOWEST,
                       errCode);

My handler function is:

static void Serial_SRV_Handler(app_uart_evt_t *p_event) {
    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
    static uint8_t index = 0;

    switch (p_event->evt_type) {
        case APP_UART_DATA_READY:
            if (app_uart_get(&data_array[index]) == NRF_SUCCESS) {
                // Do something with data... etc...
                ++index;
                if (index >= BLE_NUS_MAX_DATA_LEN) {
                    index = 0;
                }
            }
            break;
        default:
            break;
    }
}

The problem is that this handler function only gets called when I'm connected via Bluetooth. By debugging, I can see that this function gets called all the way up from the UARTE_UART0 Interrupt. This interrupt, however, never happens if not connected to a Bluetooth device.

This problem makes no sense to me, I really don't know where things got tangled here....

Related