Need to get nRF 9151 UART <=> IOT to work

hello,

I have nRF9151 and would like to connect UART1  (Rx PO.28 & Tx PO.29) to an external IOT device.  it only supports the Tx/Rx port. There is HW control.

My goal is to send one character 'A' on the port and then receive 2 characters. i can't make it to work. I followed the instructions to configure the device but not able to make it work!

Attached provide the configuration of application with simply loop at the to do the actual Tx/Tx and would greatly appreciate any help to make this work for me.

Thanks for your help in advance.

regards

Ramizblinky-UART.zip

Parents
  • the issue is that the SW is not able to activate the UART port. i need help some looking at the software, makefile, ... config

  • I tried building the sample you uploaded and got a build error because the uart1 node is disabled. It is disabled by default since it is used by for logging by the TF-M image. If you want to use this uart instance in your application, you should first disable UART logging in TF-M by adding CONFIG_TFM_SECURE_UART=n and CONFIG_TFM_LOG_LEVEL_SILENCE=y to your project configuration (prj.conf), then create a devicetree overlay to change the status to "okay":

    &uart1 {
        status = "okay";
    };

  • Excellent. 

    RamizB said:
    also changed the filename as directed (did not make impact).

    Yes, the overlay file (nrf9161dk_nrf9161_ns.overlay) in the project you uploaded was empty anyway, so it would not make any difference if it got included in the build or not.

  • Vidar,  so much for your help. Things are working a bit bitter.  I am able to make the Tx port work (i.e i can send signal on the Tx PO.29 and receive it on the MCU).  However the nrf can't see message coming from the MCU (on PO.28).  i tested with different cables - no impact. i tried to connect PO.28 to PO.29 - did not make a difference. i tried with nrf9161 and nrf9151 - did not make a difference. 

    In the debug mode i don't get the event UART_RX_RDY in the uart_cb function.  Kindly appreciate your help and advice.

    Thanks for your help in advance.

    Attached is the code along with config files.native_tty-UART.zip

  • prj.conf
    CONFIG_GPIO=y
    #CONFIG_UART_INTERRUPT_DRIVEN=n
    CONFIG_TFM_SECURE_UART=n
    CONFIG_TFM_LOG_LEVEL_SILENCE=y
    CONFIG_UART_USE_RUNTIME_CONFIGURE=y
    # Enable UART driver support
    CONFIG_UART_ASYNC_API=n
    CONFIG_UART_INTERRUPT_DRIVEN=n
    CONFIG_SERIAL=y
    CONFIG_UART_NRFX=y
    # CONFIG_UART_1=y
    
    
    # Logging (optional for debugging)
    CONFIG_LOG=y
    CONFIG_LOG_DEFAULT_LEVEL=3
    CONFIG_UART_CONSOLE=y
    # Enable minimal kernel settings
    CONFIG_THREAD_STACK_INFO=y
    
    
    # Kernel options
    CONFIG_MAIN_STACK_SIZE=1024
    CONFIG_HEAP_MEM_POOL_SIZE=4096
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    ===========================================
    nrf9161dk_nrf9161_ns.overlay
    &uart0 {
        status = "okay";
    };
    
    =============================================
    main.c
    
    
    
    
    
    #include <zephyr/kernel.h>
    #include <zephyr/device.h>
    #include <zephyr/drivers/uart.h>
    #include <zephyr/sys/printk.h>
    #include <string.h>
    #include <stdio.h>
    
    
    #define UART_DEVICE_NODE DT_NODELABEL(uart0)  // Replace 'uart0' with your UART node label
    #define BUFFER_SIZE 32
    
    static const struct device *uart_dev;
    static uint8_t rx_buffer[BUFFER_SIZE];
    static uint8_t tx_buffer[BUFFER_SIZE];
    
    struct uart_config uart_cfg = {
        .baudrate = 9600,
        .data_bits = UART_CFG_DATA_BITS_8,
        .parity = UART_CFG_PARITY_NONE,
        .stop_bits = UART_CFG_STOP_BITS_1,
        .flow_ctrl = UART_CFG_FLOW_CTRL_NONE,
    
    };
    
    void uart_poll_init() {
    
        int rc;
    
        uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);
        if (!device_is_ready(uart_dev)) {
            printk("UART device not ready\n");
            return;
        }
    
        rc = uart_configure(uart_dev, &uart_cfg);
        if (rc != 0) {
            printf("Could not configure device uart1\n");
        } else {
            printf("Configure device uart1\n");
        }
    
        printf("UART initialized successfully\n");
    }
    
    void uart_poll_write(const uint8_t *data, size_t length) {
        for (size_t i = 0; i < length; i++) {
            uart_poll_out(uart_dev, data[i]);
        }
    }
    
    size_t uart_poll_read(uint8_t *buffer, size_t buffer_len) {
        size_t bytes_read = 0;
        int received_byte;
    
        while (bytes_read < buffer_len) {
            received_byte = uart_poll_in(uart_dev, &buffer[bytes_read]);
            if (received_byte == 0) {  // 0 indicates a byte was successfully read
                bytes_read++;
            } else {
                break;  // Exit loop if no more data is available
            }
        }
    
        return bytes_read;
    }
    
    int main(void) {
    
        uart_poll_init();
    
        strcpy((char *)tx_buffer, "Hello, UART!\n");
        uart_poll_write(tx_buffer, strlen((char *)tx_buffer));
    
        printf("Waiting for UART input...\n");
    
        while (1) {
            size_t len = uart_poll_read(rx_buffer, BUFFER_SIZE);
            if (len > 0) {
                rx_buffer[len] = '\0';  // Null-terminate the received string
                printf("Received: %s\n", rx_buffer);
    
    //        k_sleep(K_MSEC(1));  // Poll every 100 ms
        }
    }
    

    why uart0 Rx pollin read 7 bytes only.docx

    Thanks for your help. I was able to get Tx work but not the Rx. So, switch my scheme to use the polling method to the Tx/Rx.  this worked per the following code.  However. i was able to get receive ONLY 7 Character! Disappointed

    in my application the MCU generates a long sream (1000-2000 characters); but i am only receiving 7 characters!

    after much search i thought that the rx_buffer is the controller factor for how many charters can be received.

    but then i discover this article from Nordic Support AI. how to solve this issue?  I need to be able to receive large number of charters!

  • Hi, 

    I recommend using the Asynchronous API from the UART driver. This allows you to utilize DMA for receiving data in the background.

    Best regards,

    Vidar

  • does the Asynch API clears the FIFO HW to make room for incoming data stream?

    Do you know why the polling method, configured in blocking mode (where the CPU is locked to receive data), does not clear the FIFO hardware to make room for the incoming data stream?

Reply Children
Related