Configure second UART on nRF52840 DK

Hello,

I need to configure second UART for nRF52840 DK. So I would like to know the overlay file for uart2 configuration with exact GPIO pins. Also the .c file to initialize the second UART and functions to send and receive data from that newly configured UART without disturbing the default UART.

Thanks,

Sameera.

Parents
  • Hi,

    I have selected P0.28 and P0.29 for TX and RX respectively. I would like to confirm if these are the correct GPIO pins for second UART or uart1 on the nRF52840 DK. Additionally, I would appreciate it if someone could share an appropriate overlay file for enabling and configuring UART2 using these pins.

  • Hello,

    P0.28 and P0.29 are for low frequency only. You should avoid the low frequency pins.

  • Hello,

    I can try to explain adding UART pin in device tree. You have to create a pinctrl.dtsi file. For example, if following pin set up are for your board-pinctrl.dtsi file (This is from our nrf52840 board file),

    &pinctrl {
    	uart0_default: uart0_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 6)>,
    				<NRF_PSEL(UART_RTS, 0, 5)>;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_RX, 0, 8)>,
    				<NRF_PSEL(UART_CTS, 0, 7)>;
    			bias-pull-up;
    		};
    	};
    
    	uart0_sleep: uart0_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 6)>,
    				<NRF_PSEL(UART_RX, 0, 8)>,
    				<NRF_PSEL(UART_RTS, 0, 5)>,
    				<NRF_PSEL(UART_CTS, 0, 7)>;
    			low-power-enable;
    		};
    	};
    
    	uart1_default: uart1_default {
    		group1 {
    			psels = <NRF_PSEL(UART_RX, 1, 1)>;
    			bias-pull-up;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_TX, 1, 2)>;
    		};
    	};
    
    	uart1_sleep: uart1_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_RX, 1, 1)>,
    				<NRF_PSEL(UART_TX, 1, 2)>;
    			low-power-enable;
    		};
    	};

    you can write this on overlay file with the same pin number but with different name (for example: uart0_default_alt instead of uart0_default)

    All upstream boards define both default and sleep states. Overlays also need to define both.

    If the board does not have the power management application, you can write like this

    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };

Reply
  • Hello,

    I can try to explain adding UART pin in device tree. You have to create a pinctrl.dtsi file. For example, if following pin set up are for your board-pinctrl.dtsi file (This is from our nrf52840 board file),

    &pinctrl {
    	uart0_default: uart0_default {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 6)>,
    				<NRF_PSEL(UART_RTS, 0, 5)>;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_RX, 0, 8)>,
    				<NRF_PSEL(UART_CTS, 0, 7)>;
    			bias-pull-up;
    		};
    	};
    
    	uart0_sleep: uart0_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_TX, 0, 6)>,
    				<NRF_PSEL(UART_RX, 0, 8)>,
    				<NRF_PSEL(UART_RTS, 0, 5)>,
    				<NRF_PSEL(UART_CTS, 0, 7)>;
    			low-power-enable;
    		};
    	};
    
    	uart1_default: uart1_default {
    		group1 {
    			psels = <NRF_PSEL(UART_RX, 1, 1)>;
    			bias-pull-up;
    		};
    		group2 {
    			psels = <NRF_PSEL(UART_TX, 1, 2)>;
    		};
    	};
    
    	uart1_sleep: uart1_sleep {
    		group1 {
    			psels = <NRF_PSEL(UART_RX, 1, 1)>,
    				<NRF_PSEL(UART_TX, 1, 2)>;
    			low-power-enable;
    		};
    	};

    you can write this on overlay file with the same pin number but with different name (for example: uart0_default_alt instead of uart0_default)

    All upstream boards define both default and sleep states. Overlays also need to define both.

    If the board does not have the power management application, you can write like this

    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };
    &pinctrl {
        uart0_default_alt: uart0_default_alt {
            ...
        };
    };
    
    &uart0 {
        ...
        pinctrl-0 = <&uart0_default_alt>;
        /delete-property/ pinctrl-1;
        pinctrl-names = "default";
        ...
    };

Children
No Data
Related