Central and Peripheral UART Samples on UART2 - nRF5340 Audio DK

Hello,

I am working with 2 x nRF5340 Audio DK.  I flashed the Central UART Sample on the 1st Kit and the Peripheral UART Sample on the second kit.  It works 100%. 

However the UART used in the sample is UART0 and it is a CDC-based UART accessible on the PC via 2 virtual COM ports via USB.  I need to set up the kits to use a Hardware UART since I will be connecting the kits to other devices via RS232. I have a UART/RS232 circuit to take care of that. 

According to the documentation, there is UART2 on the Arduino headers on Pin 1.08 (UART2_RXD)  and P1.09 (UART2_TXD).  

Based on the DTS files in the nRF5340 Audio DK there is no UART2 setup by default. I then created an overlay called nrf5340_audio_dk_nrf5340_cpuapp.overlay in the root folder of the project. Here are the contents:

&uart2 {
        status = "okay";
        current-speed = <115200>;

        pinctrl-0 = <&uart2_default_alt>;
        pinctrl-1 = <&uart2_sleep_alt>;
        pinctrl-names = "default", "sleep";
};

&gpiote {
        interrupts = <13 NRF_DEFAULT_IRQ_PRIORITY>;
};

&pinctrl {
        uart2_default_alt: uart2_default_alt {
                group1 {
                        psels = <NRF_PSEL(UART_RX, 1, 8)>,
                                <NRF_PSEL(UART_TX, 1, 9)>;
                };
        };

        uart2_sleep_alt: uart2_sleep_alt {
                group1 {
                        psels = <NRF_PSEL(UART_RX, 1, 8)>,
                                <NRF_PSEL(UART_TX, 1, 9)>;
                        low-power-enable;
                };
        };
};

I have tested another test project and I was able to communicate (RX and TX) with UART2 via my RS232/UART converter and a console on the PC. So UART2 is accessible and wired up correctly.

My question is:

How can I change these 2 projects (Central UART and Peripheral UART) to interact with UART2 and not with UART0?

Thanks

Parents
  • Hi,

    In the peripheral_uart app.overlay file, you would need to specify uart2 instead of uart0 and then to enable it.

    / {
    	chosen {
    		nordic,nus-uart = &uart2;
    	};
    };
    
    &uart2 {
    status = "okay"; 
    ....
    
    };


    Similar to peripheral_uart, uart2 would need to be enabled in central_uart too. On the central_uart side, uart0 is hard-coded in the main.c file and that would need to be changed as well.

    static const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart2));


    Best regards,
    Dejan

  • Thanks Dejan for your post.


    Unfortunately, it's still not working.   What I do get is a "*** Booting Zephyr OS Build v3.2.99-ncs2 ***" message on UART 2 on both boards when I reset the DK. Otherwise no data on UART2 (and UART0).

    On Central UART I did the following:

    Changed in main.c the line referring to UART0 to:

    static const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart2));

    On Peripheral UART I did the following:

    In nrf5340_audio_dk_nrf5340_cpuapp.overlay I added:

    / {
        chosen {
            nordic,nus-uart = &uart2;
        };
    };


    &uart2 {
        status = "okay";
        current-speed = <115200>;

        pinctrl-0 = <&uart2_default_alt>;
        pinctrl-1 = <&uart2_sleep_alt>;
        pinctrl-names = "default", "sleep";
    };

    &gpiote {
        interrupts = <13 NRF_DEFAULT_IRQ_PRIORITY>;
    };

    &pinctrl {
        uart2_default_alt: uart2_default_alt {
            group1 {
                psels = <NRF_PSEL(UART_RX, 1, 8)>,
                        <NRF_PSEL(UART_TX, 1, 9)>;
            };
        };

        uart2_sleep_alt: uart2_sleep_alt {
            group1 {
                psels = <NRF_PSEL(UART_RX, 1, 8)>,
                        <NRF_PSEL(UART_TX, 1, 9)>;
                low-power-enable;
            };
        };
    };
    I first tried with a modified Central but original Peripheral and later tried both sides modified. Even with a unmodified Peripheral DK, no data was coming in or going out.
    Thanks
  • Hi,

    In the file nrf5340_audio_dk_nrf5340_cpuapp_common.dts you can see that pins P1.08 and P1.09 are forwarded to the network core. Looking at the connector interface for audio hardware, there are pins P1.12 and P1.13 which could be used in your case. In the psels lines of the pinctrl section, you could try replacing pins P1.08 and P1.09 with pins P1.12 and P1.13. It would look like something like this:

    psels = <NRF_PSEL(UART_RX, 1, 12)>,
            <NRF_PSEL(UART_TX, 1, 13)>;


    Best regards,
    Dejan

  • Thank you very much. It is working 100%. Much appreciated. :-)

Reply Children
No Data
Related