This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to communicate an external module through UART in nRF9160DK?

I want to let nRF9160DK communicate with an external module through UART in nRF9160DK

Then I need to assign rx and tx on two pins.

I will use UART0 for printk function so P0.26, 27, 28, and 29 are reserved.

I read page18 in nRF91_DK_User_Guide_v07.pdf and realized that all the pins are already connected to some modules in the DK.

Is it possible to assign some pins as UART tx and rx and connect to an external module? And if possibel, how can yo do it?

Thank you in advance.

Parents Reply
  • Thank you so much for your reply.

    > I'd recommend that you use GPIOs between P0.10 and P0.20,

    Get it. Then I set uart2 as shown below.

    <nrf9160_pca10090.dts>
    
    {
    
    	chosen {
    	    ..
            zephyr,uart-wifi = &uart2;
    		..
    	};
    }
    
    &uart2 {
    	status = "ok";
    	current-speed = <115200>;
    	tx-pin = <10>;
    	rx-pin = <11>;
    };

    void main(void)
    {
        printk("Hello, World!\r\n");
        uart_wifi = device_get_binding("UART_2");
        if (!uart_wifi) {
        	printk("error\r\n");
    	}
    	..
    }

    However, "device_get_binding" does not work well and get error.

    build is successful.

    Do you know why?

Children
  • Did you add "CONFIG_UART_2_NRF_UARTE=y" to your prj.conf? Are you using the bsdlib in this project? It tries to use UART2 unless you add "CONFIG_BSD_LIBRARY_TRACE_ENABLED=n" to the prj.conf.

     

    Kind regards,

    Håkon

  • Thank you for your advice!

    I added "CONFIG_UART_2_NRF_UARTE=y" to a wrong file. 

    Building and Running were successful when I added it to correct file.

    However, I can't communicate through UART yet.

    Tx pin is P0.10 = Pin 3 in P19.

    I checked the waveform of the Pin 3 with an oscilloscope, but there is no signal. 

    Do you now why?

  • The behavior depends on what you do in your example.

    The TXD pin should be high when idle, while the RXD pin should be floating when its not connected to another UART. Have you connected another UART to the GPIOs?

    For testing reasons, you could add a loop where you send over UART2, using "uart_tx(..)" for instance. 

  • your advice is helpful.

    >Have you connected another UART to the GPIOs?

    Yes.

    Here is my code. very simple. Any advice is helpful for me.

    <main.c>
    #include <nrf9160.h>
    #include <zephyr.h>
    #include <misc/printk.h>
    #include <uart.h>
    #include <string.h>
    #include <stdlib.h>
    #include <math.h>
    
    static u8_t uart_buf[1024];
    static struct device *uart_wifi;
    
    void uart_cb(struct device *_uart)
    {
    	uart_irq_update(_uart); // Start processing interrupts in ISR.
    	int data_length = 0;
    
    	if (uart_irq_rx_ready(_uart)) { // Check if UART RX buffer has a received char.
    		data_length = uart_fifo_read(_uart, uart_buf, sizeof(uart_buf)); // Read data from FIFO.
    		uart_buf[data_length] = 0;
    	}
    	printk("%s\r\n", uart_buf);
    }
    
    void uart_send_str(struct device *uart, char *str){
        printk("callback!\r\n");
        u32_t len = strlen(str);
        while (len--) {
            uart_poll_out(uart, *str++);
        }
    }
    
    void main(void)
    {
            char *command = "AT,test\r\n";
            printk("Hello, World!\r\n");
    
            uart_wifi = device_get_binding("UART_2"); // "UART_1" works fine. "UART_2" does not work out.
            if (!uart_wifi) {
    		printk("error\r\n");
    	}
            uart_irq_rx_disable(uart_wifi);
            uart_irq_callback_set(uart_wifi, uart_cb); // Set UART interrupt callback
            uart_irq_rx_enable(uart_wifi);
    
    	while (1) {
                    printk("loop head\r\n");
                    uart_send_str(uart_wifi, command);
                    printk("enter sleep\r\n");
                    __WFI();
    	}
    }
    

    <prj.conf>
    
    CONFIG_SERIAL=y
    CONFIG_TRUSTED_EXECUTION_NONSECURE=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_1_NRF_UARTE=y
    CONFIG_UART_2_NRF_UARTE=y
    CONFIG_BSD_LIBRARY_TRACE_ENABLED=n
    

    <nrf9160_pca10090.dts>
    
    /dts-v1/;
    #include <nordic/nrf9160_xxaa.dtsi>
    
    / {
    	model = "Nordic PCA10090 Dev Kit";
    	compatible = "nordic,pca10090-dk", "nordic,nrf9160-xxaa";
    
    	chosen {
    		zephyr,console = &uart0;
                    zephyr,debug = &uart1;
                    zephyr,uart-wifi = &uart2;
    		zephyr,sram = &sram0;
    		zephyr,flash = &flash0;
    	};
    
    	aliases {
    		led0 = &led0;
    		led1 = &led1;
    		led2 = &led2;
    		led3 = &led3;
    		sw0 = &button2;
    		sw1 = &button3;
    		sw2 = &button0;
    		sw3 = &button1;
    	};
    
    	leds {
    		compatible = "gpio-leds";
    		led0: led_0 {
    			gpios = <&gpio0 2 GPIO_INT_ACTIVE_LOW>;
    			label = "Green LED 0";
    		};
    		led1: led_1 {
    			gpios = <&gpio0 3 GPIO_INT_ACTIVE_LOW>;
    			label = "Green LED 1";
    		};
    		led2: led_2 {
    			gpios = <&gpio0 4 GPIO_INT_ACTIVE_LOW>;
    			label = "Green LED 2";
    		};
    		led3: led_3 {
    			gpios = <&gpio0 5 GPIO_INT_ACTIVE_LOW>;
    			label = "Green LED 3";
    		};
    	};
    
    	buttons {
    		compatible = "gpio-keys";
    		button0: button_0 {
    			gpios = <&gpio0 8 GPIO_PUD_PULL_UP>;
    			label = "Switch 1";
    		};
    		button1: button_1 {
    			gpios = <&gpio0 9 GPIO_PUD_PULL_UP>;
    			label = "Switch 2";
    		};
    		button2: button_2 {
    			gpios = <&gpio0 6 GPIO_PUD_PULL_UP>;
    			label = "Push button 1";
    		};
    		button3: button_3 {
    			gpios = <&gpio0 7 GPIO_PUD_PULL_UP>;
    			label = "Push button 2";
    		};
    	};
    
    	sram0_bsd: memory@20010000 {
    		device_type = "memory";
    		compatible = "mmio-sram";
    	};
    };
    
    &uart0 {
    	status = "ok";
    	current-speed = <115200>;
    	tx-pin = <29>;
    	rx-pin = <28>;
    	rts-pin = <27>;
    	cts-pin = <26>;
    };
    
    &uart1 {
    	status = "ok";
    	current-speed = <115200>;
    	tx-pin = <1>;
    	rx-pin = <0>;
    	rts-pin = <14>;
    	cts-pin = <15>;
    };
    
    &uart2 {
    	status = "ok";
    	current-speed = <115200>;
    	tx-pin = <10>;
    	rx-pin = <11>;
    };
    
    ...

  • nRF9160 UART logic level is originally 1.8V. I thought 3.3V. 

    Anyway, I disconnected P10(Tx) and saw the waveform, but always 1.8V. No signal. I have no idea of why UART signal does not come...

Related