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

UART communication on nRF9160DK

Hi,

I am trying to use UART interface on a nRF9160DK board to connect a rs-232 to rs-485 module for the purpose to  make nRF9160DK a Gateway.

But I have no idea where to find an example how to perform this task exactly using nRF9160DK.

I take SERRER Embedded Studio for ARM on windows 10 as the tool.

Many thanks if anyone can give me a hand. 

Parents
  • Hi,

    You can try this.

    #include <zephyr.h>
    #include <misc/printk.h>
    #include <uart.h>
    
    static u8_t uart_buf[1024];
    
    void uart_cb(struct device *x)
    {
    	uart_irq_update(x);
    	int data_length = 0;
    
    	if (uart_irq_rx_ready(x)) {
    		data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
    		uart_buf[data_length] = 0;
    	}
    	printk("%s", uart_buf);
    }
    
    void main(void)
    {
    	struct device *uart = device_get_binding("UART_0");
    
    	uart_irq_callback_set(uart, uart_cb);
    	uart_irq_rx_enable(uart);
    	printk("UART loopback start!\n");
    	while (1) {
    		k_cpu_idle();
    	}
    

Reply
  • Hi,

    You can try this.

    #include <zephyr.h>
    #include <misc/printk.h>
    #include <uart.h>
    
    static u8_t uart_buf[1024];
    
    void uart_cb(struct device *x)
    {
    	uart_irq_update(x);
    	int data_length = 0;
    
    	if (uart_irq_rx_ready(x)) {
    		data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
    		uart_buf[data_length] = 0;
    	}
    	printk("%s", uart_buf);
    }
    
    void main(void)
    {
    	struct device *uart = device_get_binding("UART_0");
    
    	uart_irq_callback_set(uart, uart_cb);
    	uart_irq_rx_enable(uart);
    	printk("UART loopback start!\n");
    	while (1) {
    		k_cpu_idle();
    	}
    

Children
Related