Problem using UART using NCS 2.9.0

Hi,

I've just migrated my project from NCS 2.6.1 to 2.9.0 and I'm having some problems with the UART.

I'm using the nRF52833 DK to communicate with another device and I noticed that I can send data from the nRF to the other device, however, I can't send data from the device to the nRF.

I decided to test with an example from Nordic (UART echo bot) and noticed that when I use the default pins of the UART, the communication works as it should (nRF <-> device). However, when I switch to the pins I'm using in the main project, communication only works in one direction (nRF -> device), i.e. there's no more communication (nrf <- device).

These are the pins I'm using:

&uart0 {
    hw-flow-control;    // Enable RTS and CTS
    current-speed = <115200>;
	data-bits = <8>;
	stop-bits = "1";
	parity = "none";
    pinctrl-0 = <&uart0_default_alt>;
    pinctrl-1 = <&uart0_sleep_alt>;
    status = "okay";
};
 
&pinctrl {
    uart0_default_alt: uart0_default_alt {
            
        group1 {
            psels = <NRF_PSEL(UART_TX, 0, 30)>,
                    <NRF_PSEL(UART_RX, 0,  8)>,
                    <NRF_PSEL(UART_RTS, 0, 6)>,
                    <NRF_PSEL(UART_CTS, 0, 7)>;
        };
        
    };
    uart0_sleep_alt: uart0_sleep_alt {
        group1 {
            psels = <NRF_PSEL(UART_TX, 0, 30)>,      
                    <NRF_PSEL(UART_RX, 0,  8)>,      
                    <NRF_PSEL(UART_RTS, 0, 6)>,     
                    <NRF_PSEL(UART_CTS, 0, 7)>;     
            
                    low-power-enable;
        };
    };
};



I disabled spi, i2c, adc, leds and buttons to make sure that there were no conflicts between pins.

Thank you!

Parents
  • Hello,

    The default pin number of MOSI is P0.30 in the default pincontrol (nrf52833dk_nrf52820-pinctrl.dtsi) file (C:\ncs\v2.9.0\zephyr\boards\nordic\nrf52833dk\nrf52833dk_nrf52820-pinctrl.dtsi)). 

    'I disabled spi, i2c, adc, leds and buttons to make sure that there were no conflicts between pins.''

    Can you share the board file of your application with me then I can see if disabling the peripheral is ok or not? 

    ''However, when I switch to the pins I'm using in the main project, communication only works in one direction (nRF -> device), i.e. there's no more communication (nrf <- device).

    Do you have any output log that you can share with us?

    Thanks.

    BR

    Kazi

  • Hello,

    These are my project files:

    /*
     * Copyright (c) 2022 Libre Solar Technologies GmbH
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/uart.h>
    
    #include <string.h>
    
    /* change this to any other UART peripheral if desired */
    #define UART_DEVICE_NODE DT_CHOSEN(zephyr_shell_uart)
    
    #define MSG_SIZE 32
    
    /* queue to store up to 10 messages (aligned to 4-byte boundary) */
    K_MSGQ_DEFINE(uart_msgq, MSG_SIZE, 10, 4);
    
    static const struct device *const uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);
    
    /* receive buffer used in UART ISR callback */
    static char rx_buf[MSG_SIZE];
    static int rx_buf_pos;
    
    /*
     * Read characters from UART until line end is detected. Afterwards push the
     * data to the message queue.
     */
    void serial_cb(const struct device *dev, void *user_data)
    {
    	uint8_t c;
    
    	if (!uart_irq_update(uart_dev)) {
    		return;
    	}
    
    	if (!uart_irq_rx_ready(uart_dev)) {
    		return;
    	}
    
    	/* read until FIFO empty */
    	while (uart_fifo_read(uart_dev, &c, 1) == 1) {
    		if ((c == '\n' || c == '\r') && rx_buf_pos > 0) {
    			/* terminate string */
    			rx_buf[rx_buf_pos] = '\0';
    
    			/* if queue is full, message is silently dropped */
    			k_msgq_put(&uart_msgq, &rx_buf, K_NO_WAIT);
    
    			/* reset the buffer (it was copied to the msgq) */
    			rx_buf_pos = 0;
    		} else if (rx_buf_pos < (sizeof(rx_buf) - 1)) {
    			rx_buf[rx_buf_pos++] = c;
    		}
    		/* else: characters beyond buffer size are dropped */
    	}
    }
    
    /*
     * Print a null-terminated string character by character to the UART interface
     */
    void print_uart(char *buf)
    {
    	int msg_len = strlen(buf);
    
    	for (int i = 0; i < msg_len; i++) {
    		uart_poll_out(uart_dev, buf[i]);
    	}
    }
    
    int main(void)
    {
    	char tx_buf[MSG_SIZE];
    
    	if (!device_is_ready(uart_dev)) {
    		printk("UART device not found!");
    		return 0;
    	}
    
    	/* configure interrupt and callback to receive data */
    	int ret = uart_irq_callback_user_data_set(uart_dev, serial_cb, NULL);
    
    	if (ret < 0) {
    		if (ret == -ENOTSUP) {
    			printk("Interrupt-driven UART API support not enabled\n");
    		} else if (ret == -ENOSYS) {
    			printk("UART device does not support interrupt-driven API\n");
    		} else {
    			printk("Error setting UART callback: %d\n", ret);
    		}
    		return 0;
    	}
    	uart_irq_rx_enable(uart_dev);
    
    	print_uart("Hello! I'm your echo bot.\r\n");
    	print_uart("Tell me something and press enter:\r\n");
    
    	/* indefinitely wait for input from the user */
    	while (k_msgq_get(&uart_msgq, &tx_buf, K_FOREVER) == 0) {
    		print_uart("Echo: ");
    		print_uart(tx_buf);
    		print_uart("\r\n");
    	}
    	return 0;
    }
    
    3301.prj.conf4466.nrf52833dk_nrf52833.overlay

    Regarding the output, I don't have nothing that can help. But I can try to explain the problem better.


    I have a USB serial converter connected to a PC with hterm (PC B). And a nRF52833 DK connected to other PC with nRF Connec for VS Code (PC A).

    Using the default UART pins of the nRF52833 DK, I send “test1” via VCOM0 from PC A to PC B and the data appears in PC B hterm. Then, for example, I send “test1_ans” via PC B hterm and this data appears on PC A.

    When I change the pins to those described above, I send “test1” via VCOM0 from PC A to PC B and the data appears in PC B hterm. However, when I send “test1_ans” via PC B hterm, this data does not appear on PC A.

    Thank you

  • Hello,

    Pins P0.06 and P0.08 are specifically used by the interface MCU for UART communication. source: Virtual serial port

    When you're trying to use these pins for external communication (to your USB serial converter), they're already being used by the interface MCU for the virtual COM port. I guess for this reason, it does not work from PC B to PC A through external USB serial converter.

    Can try to change your UART pins to avoid using P0.06 and P0.08, which are already used by the interface MCU?

  • Hello,

    Using the default pins, it works. But I need to change to the ones mentioned above.

    Why in ncs 2.6.1 it works with my pins and in ncs 2.9.0 it doesn't?

  • Hello,

    The reason this worked in NCS 2.6.1 but not in 2.9.0 might be related to changes in how the interface MCU interacts with these pins.

    Which version of nRF52833DK you are using?

    It could be a side effect on the new boards that use the nRF5340 as the interface chip, versus older boards that used third-party IC for this. The solution is to use different GPIO pins that are not used by the interface chip as I said before as well. 

Reply Children
No Data
Related