nRF5340 Audio DK: LE Audio and UART2 Concurrently

Hi,

I have problems with the nRF5340 Audio DK to get LE Audio and UART2 concurrently on the same CIS stream to work.

GOAL

Use 2 x nRF5340 Audio DKs to transfer audio both directions via Line IN and at the same time send UART2 data from and to the 2 kits concurrently.  Exactly like the Walkie-Talkie demo but with LINE IN instead of Microphone.  And the UART must be a physical one and UART2 was chosen with a UART/RS232 converter.  So full duplex audio and serial data.

What I did so far

I did manage to modify the Application "<Path to ncs folder>\v2.2.0\nrf\applications\nrf5340_audio" to work with the LINE IN port. See my Forum post:
nRF5340 Audio DK: Walkie Talkie Demo - LINE IN instead of MIC

I also managed to modify both these samples to work with UART2 instead of the CDC Com port UART0.  I used the 2 Samples "Central UART" and "Peripheral UART". See my Forum post:

 Central and Peripheral UART Samples on UART2 - nRF5340 Audio DK 

Then I created a third Project with 2 applications that I want to combine the 2 projects. However, I only manage to get the "GATEWAY" paired with the NUS Server to work. But on the HEADSET side I can't get the NUS Client to work.  I tested the combined GATEWAY and NUS Server (Peripheral UART) with a HEADSET only and with the NUS Client (Central UART). That is why I know the GATEWAY/NUS Server side works.

The Audio still works but I cannot receive or sent serial data on the NUS client side which is on the HEADSET application side.

Application

We need to transfer Audio and Data in a full duplex Intercom system over a short distance because the wiring of an audio and data line is not possible due to moving parts.

Could you please help me combine the 4 projects into 2 please?  Is concurrent UART and LE Audio even possible?

Kind Regards

Parents Reply Children
  • Hi, 

    I think the error is raised from bt_nus_send -> bt_gatt_notify_cb. Please try to debug the bt_gatt_notify_cb function to see where returns - 128, it means ENOTCONN

    -Amanda H.

  • Finally, it's working. :-)

    The key to fixing this was to add the following line in gatt_discover():

    default_conn = conn;

    This was why the UART (NUS) side complained about the connection. It was probably due to having to disable the call to "bt_enable()" during the setup of the UART (NUS). LE Audio is enabled before the NUS Client therefore LE Audio already makes a connection.
      

    static void gatt_discover(struct bt_conn *conn)
    {
        int err;

        // This is the fix...Because bt_enable was disabled
        default_conn = conn;

        if (conn != default_conn)
        {
            return;
        }

        err = bt_gatt_dm_start(conn,
                               BT_UUID_NUS_SERVICE,
                               &discovery_cb,
                               &nus_client);
        if (err)
        {
            LOG_ERR("could not start the discovery procedure, error code: %d", err);
        }
    }
     
    AND
     
    In the NUS Client setup code disable the call to bt_enable():
     
        // err = bt_enable(NULL);
        // if (err)
        // {
        //  LOG_ERR("Bluetooth init failed (err %d)", err);
        //  return;
        // }
     
    AND 
     
    I also moved the "bt_nus_client_send" related code into a separate thread procedure:
     
    void ble_write_thread(void)
    {
        int err;

        printk("\n*** In ble_write_thread ***\n");

        /* Don't go any further until BLE is initialized */
        k_sem_take(&ble_init_ok, K_FOREVER);

        for (;;)
        {
            /* Wait indefinitely for data to be sent over Bluetooth */
            struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data, K_FOREVER);

            // Note: Problem here is that "nus_client->conn" does not
                     contain a valid connection.
            //       This is fixed by adding a line to procedure "gatt_discover".

            err = bt_nus_client_send(&nus_client, buf->data, buf->len);
            if (err)
            {
                printk("Failed to send data over BLE connection(err %d)\n", err);
                LOG_WRN("Failed to send data over BLE connection(err %d)", err);
            }
            else
            {
                printk("Data sent data over BLE connection\n");
            }

            err = k_sem_take(&nus_write_sem, NUS_WRITE_TIMEOUT);
            if (err)
            {
                printk("NUS send timeout\n");
                LOG_WRN("NUS send timeout");
            }
        }
    }
     
    K_THREAD_DEFINE(ble_write_thread_id, STACKSIZE, ble_write_thread, NULL, NULL, NULL, PRIORITY, 0, 4000);
      
    Here is the main() loop:
      
    void main(void)
    {
        // LE Audio
        int ret;

        printk("InitLEAudio()\n");
        InitLEAudio();

        // UART2
        /* Don't go any further until LE Audio is initialized */
        k_sem_take(&le_audio_ok, K_FOREVER);

        printk("InitUART2()\n");
        InitUART2();

        while (1)
        {
            // LE Audio
            streamctrl_event_handler();
            STACK_USAGE_PRINT("main", &z_main_thread);

            // UART2
            /* Use seperate thread (ble_write_thread) for data to be sent over Bluetooth */
        }
    }
      
    k_sem_give(&le_audio_ok);  was added to the end of void on_ble_core_ready(void) {...}
Related