Using 4 uarts of NRF5340 at the same time

Hi

I am using NRF5340 chip in my custom designed board and I want to use all the 4 UARTs available in this chip at the same time.

The interesting problem which I am confronting is that three of these UARTs work properly and answer to their interrupts. The forth

UART can send data but it doesn't response to its receiving data. It's call back routine doesn't work. Another interesting matter is 

that when I change the initializing sequence of these UARTs the non responding UART is also changes. For example when I 

initialize the UARTs in my main as: uart0,uart1,uart2,uart3 the non responding uart is the last one ie. uart3. When I change the 

initializing sequence for example as: uart0,uart1,uart3,uart2 the non responding uart is uart2 . Always the last initialized uart 

doesn't respond. It seems that only three receiving interrupts are active.

I would be very thankful if you could guide me to solve this problem, because I need all 4 UARTs in my project.

Best regards

 

    

Parents
  • Hi Sigurd

    Is this means only 3 uarts can be used simultaneously? 

  • /*
     * Copyright (c) 2018 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    /** @file
     *  @brief Nordic UART Bridge Service (NUS) sample
     */
    
    #include <zephyr/types.h>
    #include <zephyr.h>
    #include <drivers/uart.h>
    #include <drivers/gpio.h>
    
    #include <device.h>
    #include <soc.h>
    
    #include <bluetooth/bluetooth.h>
    #include <bluetooth/uuid.h>
    #include <bluetooth/gatt.h>
    #include <bluetooth/hci.h>
    
    #include <bluetooth/services/nus.h>
    
    #include <dk_buttons_and_leds.h>
    
    #include <settings/settings.h>
    
    #include <stdio.h>
    
    #include <logging/log.h>
    
    #include <stdlib.h>
    
    #include <kernel.h>
    #include <devicetree.h>
    // #include <pm/device.h>
    
    #define LOG_MODULE_NAME peripheral_uart
    LOG_MODULE_REGISTER(LOG_MODULE_NAME);
    
    #define STACKSIZE CONFIG_BT_NUS_THREAD_STACK_SIZE
    #define PRIORITY 7
    
    #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
    #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
    
    #define RUN_STATUS_LED1 DK_LED1
    #define RUN_STATUS_LED2 DK_LED2
    #define RUN_STATUS_LED3 DK_LED3
    #define RUN_STATUS_LED4 DK_LED4
    
    static uint8_t led1flg;
    static uint8_t led2flg;
    static uint8_t led3flg;
    static uint8_t led4flg;
    
    #define led5 28	  // pin number for led5
    #define rscon 12  // pin number for rscon
    #define rscon1 27 // pin number for rscon1
    #define rscon2 26 // pin number for rscon2
    #define rscon3 25 // pin number for rscon3
    
    #define rs0_connect_led DK_LED1
    #define rs1_connect_led DK_LED2
    #define rs2_connect_led DK_LED3
    #define rs3_connect_led DK_LED4
    
    #define UART_BUF_SIZE CONFIG_BT_NUS_UART_BUFFER_SIZE
    
    #define UART_WAIT_FOR_BUF_DELAY K_MSEC(50)
    #define UART_WAIT_FOR_RX CONFIG_BT_NUS_UART_RX_WAIT_TIME
    
    #define baudrate38400 NRF_UARTE0->BAUDRATE = UARTE_BAUDRATE_BAUDRATE_Baud38400
    #define baudrate9600 NRF_UARTE0->BAUDRATE = UARTE_BAUDRATE_BAUDRATE_Baud9600
    #define baudrate115200 NRF_UARTE0->BAUDRATE = UARTE_BAUDRATE_BAUDRATE_Baud115200
    
    static const struct device *uart;
    static uint8_t datarx0[250];
    static uint8_t rxupdate0 = 0;
    static uint8_t rxdatalen0;
    static struct k_work_delayable uart_work;
    
    struct uart_data_t
    {
    	void *fifo_reserved;
    	uint8_t data[UART_BUF_SIZE];
    	uint16_t len;
    };
    
    
    static const struct device *uart1;
    static uint8_t datarx1[250];
    static uint8_t rxupdate1 = 0;
    static uint8_t rxdatalen1;
    static struct k_work_delayable uart1_work;
    
    struct uart1_data_t
    {
    	void *fifo_reserved;
    	uint8_t data1[UART_BUF_SIZE];
    	uint16_t len1;
    };
    
    static const struct device *uart2;
    static uint8_t datarx2[250];
    static uint8_t rxupdate2 = 0;
    static uint8_t rxdatalen2;
    static struct k_work_delayable uart2_work;
    
    struct uart2_data_t
    {
    	void *fifo_reserved;
    	uint8_t data2[UART_BUF_SIZE];
    	uint16_t len2;
    };
    
    static const struct device *uart3;
    static uint8_t datarx3[250];
    static uint8_t rxupdate3 = 0;
    static uint8_t rxdatalen3;
    static struct k_work_delayable uart3_work;
    
    struct uart3_data_t
    {
    	void *fifo_reserved;
    	uint8_t data3[UART_BUF_SIZE];
    	uint16_t len3;
    };
    
    // static K_FIFO_DEFINE(fifo_uart_tx_data);
    // static K_FIFO_DEFINE(fifo_uart_rx_data);
    
    static void uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    	int k;
    	ARG_UNUSED(dev);
    	//    static uint8_t *current_buf;
    	//    static size_t aborted_len;
    	static bool buf_release;
    	struct uart_data_t *buf;
    	//    static uint8_t *aborted_buf;
    
    	switch (evt->type)
    	{
    	case UART_RX_RDY:
    		buf = CONTAINER_OF(evt->data.rx.buf, struct uart_data_t, data);
    		buf->len += evt->data.rx.len;
    		buf_release = false;
    		if (led1flg == 0)
    		{
    			led1flg = 1;
    			dk_set_led_on(rs0_connect_led);
    		}
    		else
    		{
    			led1flg = 0;
    			dk_set_led_off(rs0_connect_led);
    		}
    
    		// dk_set_led_on(rs0_connect_led);
    		rxdatalen0 = buf->len;
    		for (k = 0; k < buf->len; k++)
    		{
    			datarx0[k] = buf->data[k]; // buf->data[k];
    		}
    
    		// k_fifo_put(&fifo_uart_rx_data, buf);
    		buf->len = 0;
    		buf_release = true;
    		// uart_rx_disable(uart);
    		uart_rx_enable(uart, buf->data, sizeof(buf->data), 10);
    		rxupdate0 = 1;
    		break;
    	}
    }
    static void uart_work_handler(struct k_work *item)
    {
    	// dk_set_led_on(rs0_connect_led);
    	struct uart_data_t *buf;
    	buf = k_malloc(sizeof(*buf));
    	if (buf)
    	{
    		buf->len = 0;
    	}
    	else
    	{
    		LOG_WRN("Not able to allocate UART receive buffer");
    		k_work_reschedule(&uart_work, UART_WAIT_FOR_BUF_DELAY);
    		return;
    	}
    	uart_rx_enable(uart, buf->data, sizeof(buf->data), 10);
    }
    
    
    static void uart1_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    	int k;
    	ARG_UNUSED(dev);
    	//    static uint8_t *current_buf;
    	//    static size_t aborted_len;
    	static bool buf_release;
    	struct uart1_data_t *buf;
    	//    static uint8_t *aborted_buf;
    
    	switch (evt->type)
    	{
    	case UART_RX_RDY:
    		buf = CONTAINER_OF(evt->data.rx.buf, struct uart1_data_t, data1);
    		buf->len1 += evt->data.rx.len;
    		buf_release = false;
    		if (led2flg == 0)
    		{
    			led2flg = 1;
    			dk_set_led_on(rs1_connect_led);
    		}
    		else
    		{
    			led2flg = 0;
    			dk_set_led_off(rs1_connect_led);
    		}
    
    		// dk_set_led_on(rs0_connect_led);
    		rxdatalen1 = buf->len1;
    		for (k = 0; k < buf->len1; k++)
    		{
    			datarx1[k] = buf->data1[k]; // buf->data[k];
    		}
    
    		// k_fifo_put(&fifo_uart_rx_data, buf);
    		buf->len1 = 0;
    		buf_release = true;
    		// uart_rx_disable(uart);
    		uart_rx_enable(uart1, buf->data1, sizeof(buf->data1), 10);
    		rxupdate1 = 1;
    		break;
    	}
    }
    static void uart1_work_handler(struct k_work *item)
    {
    	// dk_set_led_on(rs0_connect_led);
    	struct uart1_data_t *buf;
    	buf = k_malloc(sizeof(*buf));
    	if (buf)
    	{
    		buf->len1 = 0;
    	}
    	else
    	{
    		LOG_WRN("Not able to allocate UART receive buffer");
    		k_work_reschedule(&uart1_work, UART_WAIT_FOR_BUF_DELAY);
    		return;
    	}
    	uart_rx_enable(uart1, buf->data1, sizeof(buf->data1), 10);
    }
    
    
    static void uart2_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    	int k;
    	ARG_UNUSED(dev);
    	//    static uint8_t *current_buf;
    	//    static size_t aborted_len;
    	static bool buf_release;
    	struct uart2_data_t *buf;
    	//    static uint8_t *aborted_buf;
    
    	switch (evt->type)
    	{
    	case UART_RX_RDY:
    		buf = CONTAINER_OF(evt->data.rx.buf, struct uart2_data_t, data2);
    		buf->len2 += evt->data.rx.len;
    		buf_release = false;
    		if (led3flg == 0)
    		{
    			led3flg = 1;
    			dk_set_led_on(rs2_connect_led);
    		}
    		else
    		{
    			led3flg = 0;
    			dk_set_led_off(rs2_connect_led);
    		}
    
    		// dk_set_led_on(rs0_connect_led);
    		rxdatalen2 = buf->len2;
    		for (k = 0; k < buf->len2; k++)
    		{
    			datarx2[k] = buf->data2[k]; // buf->data[k];
    		}
    
    		// k_fifo_put(&fifo_uart_rx_data, buf);
    		buf->len2 = 0;
    		buf_release = true;
    		// uart_rx_disable(uart);
    		uart_rx_enable(uart2, buf->data2, sizeof(buf->data2), 10);
    		rxupdate2 = 1;
    		break;
    	}
    }
    static void uart2_work_handler(struct k_work *item)
    {
    	// dk_set_led_on(rs0_connect_led);
    	struct uart2_data_t *buf;
    	buf = k_malloc(sizeof(*buf));
    	if (buf)
    	{
    		buf->len2 = 0;
    	}
    	else
    	{
    		LOG_WRN("Not able to allocate UART receive buffer");
    		k_work_reschedule(&uart2_work, UART_WAIT_FOR_BUF_DELAY);
    		return;
    	}
    	uart_rx_enable(uart2, buf->data2, sizeof(buf->data2), 10);
    }
    
    static void uart3_cb(const struct device *dev, struct uart_event *evt, void *user_data)
    {
    	int k;
    	ARG_UNUSED(dev);
    	//    static uint8_t *current_buf;
    	//    static size_t aborted_len;
    	static bool buf_release;
    	struct uart3_data_t *buf;
    	//    static uint8_t *aborted_buf;
    
    	switch (evt->type)
    	{
    	case UART_RX_RDY:
    		buf = CONTAINER_OF(evt->data.rx.buf, struct uart3_data_t, data3);
    		buf->len3 += evt->data.rx.len;
    		buf_release = false;
    		if (led4flg == 0)
    		{
    			led4flg = 1;
    			dk_set_led_on(rs3_connect_led);
    		}
    		else
    		{
    			led4flg = 0;
    			dk_set_led_off(rs3_connect_led);
    		}
    
    		// dk_set_led_on(rs0_connect_led);
    		rxdatalen3 = buf->len3;
    		for (k = 0; k < buf->len3; k++)
    		{
    			datarx3[k] = buf->data3[k]; // buf->data[k];
    		}
    
    		// k_fifo_put(&fifo_uart_rx_data, buf);
    		buf->len3 = 0;
    		buf_release = true;
    		// uart_rx_disable(uart);
    		uart_rx_enable(uart3, buf->data3, sizeof(buf->data3), 10);
    		rxupdate3 = 1;
    		break;
    	}
    }
    static void uart3_work_handler(struct k_work *item)
    {
    	// dk_set_led_on(rs0_connect_led);
    	struct uart3_data_t *buf;
    	buf = k_malloc(sizeof(*buf));
    	if (buf)
    	{
    		buf->len3 = 0;
    	}
    	else
    	{
    		LOG_WRN("Not able to allocate UART receive buffer");
    		k_work_reschedule(&uart3_work, UART_WAIT_FOR_BUF_DELAY);
    		return;
    	}
    	uart_rx_enable(uart3, buf->data3, sizeof(buf->data3), 10);
    }
    
    
    static int uart_init(void)
    {
    	uart_irq_rx_enable(uart);
    	int err;
    	struct uart_data_t *rx;
    	uart = device_get_binding(DT_LABEL(DT_NODELABEL(uart0)));
    	
    	rx = k_malloc(sizeof(*rx));
    	if (rx)
    	{
    		rx->len = 0;
    	}
    	else
    	{
    		return -ENOMEM;
    	}
    	
    	k_work_init_delayable(&uart_work, uart_work_handler);
    	
            err = uart_callback_set(uart, uart_cb, NULL);
    	if (err)
    	{
    		return err;
    	}
    	
    	return uart_rx_enable(uart, rx->data, sizeof(rx->data), 10);
    	
    }
    
    static int uart1_init(void)
    {
    	uart_irq_rx_enable(uart1);
    	int err;
    	struct uart1_data_t *rx1;
    	uart1 = device_get_binding(DT_LABEL(DT_NODELABEL(uart1)));
    	
    	rx1 = k_malloc(sizeof(*rx1));
    	if (rx1)
    	{
    		rx1->len1 = 0;
    	}
    	else
    	{
    		return -ENOMEM;
    	}
    	
    	k_work_init_delayable(&uart1_work, uart1_work_handler);
    	
            err = uart_callback_set(uart1, uart1_cb, NULL);
    	if (err)
    	{
    		return err;
    	}
    	
    	return uart_rx_enable(uart1, rx1->data1, sizeof(rx1->data1), 10);
    	
    }
    
    
    static int uart2_init(void)
    {
    	uart_irq_rx_enable(uart2);
    	int err;
    	struct uart2_data_t *rx2;
    	uart2 = device_get_binding(DT_LABEL(DT_NODELABEL(uart2)));
    	
    	rx2 = k_malloc(sizeof(*rx2));
    	if (rx2)
    	{
    		rx2->len2 = 0;
    	}
    	else
    	{
    		return -ENOMEM;
    	}
    	
    	k_work_init_delayable(&uart2_work, uart2_work_handler);
    	
            err = uart_callback_set(uart2, uart2_cb, NULL);
    	if (err)
    	{
    		return err;
    	}
    	
    	return uart_rx_enable(uart2, rx2->data2, sizeof(rx2->data2), 10);
    	
    }
    static int uart3_init(void)
    {
    	uart_irq_rx_enable(uart3);
    	int err;
    	struct uart3_data_t *rx3;
    	uart3 = device_get_binding(DT_LABEL(DT_NODELABEL(uart3)));
    	
    	rx3 = k_malloc(sizeof(*rx3));
    	if (rx3)
    	{
    		rx3->len3 = 0;
    	}
    	else
    	{
    		return -ENOMEM;
    	}
    	
    	k_work_init_delayable(&uart3_work, uart3_work_handler);
    	
            err = uart_callback_set(uart3, uart3_cb, NULL);
    	if (err)
    	{
    		return err;
    	}
    	
    	return uart_rx_enable(uart3, rx3->data3, sizeof(rx3->data3), 10);
    	
    }
    
    static K_SEM_DEFINE(ble_init_ok, 0, 1);
    static uint8_t adv_array[29] = {0};
    // static uint8_t sdv_array[29] = {0};
    //  Set advertise Response data //
    static struct bt_data ad[] = {
    	//        BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    	BT_DATA(BT_DATA_MANUFACTURER_DATA, adv_array, sizeof(adv_array)),
    
    };
    // Set Scan Response data //
    /*static  struct bt_data sd[] = {
    	//BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    		BT_DATA(BT_DATA_BROADCAST_CODE, sdv_array, sizeof(sdv_array)),
    
    };*/
    static uint8_t adv_array1[29];
    // static uint8_t sdv_array1[29];
    
    void bluetoothupdate(void)
    {
    	struct bt_data ad[] = {
    		// BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
    		BT_DATA(BT_DATA_MANUFACTURER_DATA, adv_array1, sizeof(adv_array1)),
    	};
    	//    struct bt_data sd[] = {
    	// BT_DATA(BT_DATA_BROADCAST_CODE, sdv_array1, sizeof(sdv_array1)),
    	// };
    
    	bt_le_adv_update_data(ad, ARRAY_SIZE(ad), 0, 0); // sd, ARRAY_SIZE(sd));
    }
    
    uint8_t carrier1[13] = {0x30, 0x00, 0xEF, 0x00, 0x03, 0x00, 0x00,
    						0x0B, 0x00, 0x07, 0x09, 0x84, 0x26}; // sensor command
    uint8_t carrier2[13] = {0x30, 0x00, 0xEF, 0x00, 0x03, 0x00, 0x00,
    						0x0B, 0x00, 0x0F, 0x02, 0xC2, 0x21}; // set point
    uint8_t carrier3[13] = {0x30, 0x00, 0xEF, 0x00, 0x03, 0x00, 0x00,
    						0x0B, 0x00, 0x05, 0x01, 0x84, 0x80}; // container ID
    uint8_t carrier4[13] = {0x30, 0x00, 0xEF, 0x00, 0x03, 0x00, 0x00,
    						0x0B, 0x00, 0x07, 0x08, 0x45, 0xE6}; // alarm&inrange
    
    uint8_t daikin1[9] = {
    	0x16, 0x16, 0x76, 0x60, 0xFF, 0xFF, 0xFF, 0xE6, 0x4B};					 // container ID command
    uint8_t daikin2[9] = {0x16, 0x16, 0x07, 0x0C, 0xFF, 0xFF, 0xFF, 0x87, 0x10}; // sensors command
    
    static uint8_t index0p0[29], index1p0[29], index2p0[29], index3p0[29];
    static uint8_t index0p1[29], index1p1[29], index2p1[29], index3p1[29];
    static uint8_t index0p2[29], index1p2[29], index2p2[29], index3p2[29];
    static uint8_t index0p3[29], index1p3[29], index2p3[29], index3p3[29];
    
    static uint8_t thread0flg = 0, thread1flg = 0,thread2flg = 0,thread3flg = 0;
    
    const struct uart_config uart_cfg9600 = {.baudrate = 9600,
    										 .parity = UART_CFG_PARITY_NONE,
    										 .stop_bits = UART_CFG_STOP_BITS_1,
    										 .data_bits = UART_CFG_DATA_BITS_8,
    										 .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    
    const struct uart_config uart_cfg38400 = {.baudrate = 38400,
    										  .parity = UART_CFG_PARITY_NONE,
    										  .stop_bits = UART_CFG_STOP_BITS_1,
    										  .data_bits = UART_CFG_DATA_BITS_8,
    										  .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    
    const struct uart_config uart1_cfg9600 = {.baudrate = 9600,
    										  .parity = UART_CFG_PARITY_NONE,
    										  .stop_bits = UART_CFG_STOP_BITS_1,
    										  .data_bits = UART_CFG_DATA_BITS_8,
    										  .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    
    const struct uart_config uart1_cfg38400 = {.baudrate = 38400,
    										   .parity = UART_CFG_PARITY_NONE,
    										   .stop_bits = UART_CFG_STOP_BITS_1,
    										   .data_bits = UART_CFG_DATA_BITS_8,
    										   .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    
    const struct uart_config uart2_cfg9600 = {.baudrate = 9600,
    										  .parity = UART_CFG_PARITY_NONE,
    										  .stop_bits = UART_CFG_STOP_BITS_1,
    										  .data_bits = UART_CFG_DATA_BITS_8,
    										  .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    
    const struct uart_config uart2_cfg38400 = {.baudrate = 38400,
    										   .parity = UART_CFG_PARITY_NONE,
    										   .stop_bits = UART_CFG_STOP_BITS_1,
    										   .data_bits = UART_CFG_DATA_BITS_8,
    										   .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    													   
    const struct uart_config uart3_cfg9600 = {.baudrate = 9600,
    										  .parity = UART_CFG_PARITY_NONE,
    										  .stop_bits = UART_CFG_STOP_BITS_1,
    										  .data_bits = UART_CFG_DATA_BITS_8,
    										  .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    
    const struct uart_config uart3_cfg38400 = {.baudrate = 38400,
    										   .parity = UART_CFG_PARITY_NONE,
    										   .stop_bits = UART_CFG_STOP_BITS_1,
    										   .data_bits = UART_CFG_DATA_BITS_8,
    										   .flow_ctrl = UART_CFG_FLOW_CTRL_NONE};
    			
    ////////////////////////////////////////////////////////////////////////
    
    void main()
    {
    	uint8_t j, data[13];
        const struct device* port1 =device_get_binding("GPIO_1"); // get the device address of port1
        k_sleep(K_MSEC(100));
        const struct device* port0 =device_get_binding("GPIO_0"); // get the device address of port0
    	k_sleep(K_MSEC(100));
        gpio_pin_configure(port0, led5,	GPIO_OUTPUT); //set the pin for led5 as output high
    	k_sleep(K_MSEC(100));
    	gpio_pin_configure(port0, rscon, GPIO_INPUT); // set the pin for rscon as input 
    	k_sleep(K_MSEC(100));
    	gpio_pin_configure(port0, rscon1, GPIO_INPUT); // set the pin for rscon1 as input
    	k_sleep(K_MSEC(100));
    	gpio_pin_configure(port0, rscon2, GPIO_INPUT); // set the pin for rscon2 as input
    	k_sleep(K_MSEC(100));
    	gpio_pin_configure(port0, rscon3, GPIO_INPUT); // set the pin for rscon3 as input
    	k_sleep(K_MSEC(100));
            
        uart_init();
    	uart1_init();
        uart2_init();
        uart3_init();
        dk_leds_init();
    
    	bt_enable(NULL);
    	k_sem_give(&ble_init_ok);
    	if (IS_ENABLED(CONFIG_SETTINGS))
    	{
    		settings_load();
    	}
    	bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad), 0, 0);
    
    	
        uart_configure(uart2, &uart2_cfg9600);
        uart_configure(uart3, &uart3_cfg9600);
        while(1)
    	{    
    /*  ////////////////////////////////send data test  
    	for (int k = 0; k < 13; k++)
    	{
    	 data[k] = carrier3[k];
    	}
        uart_tx(uart2, data, 13, SYS_FOREVER_MS);
    */
        ///////////////////////////////recieve data test
    	if(rxupdate3==1)
    	{
    		rxupdate3 = 0;
    		for ( int k =0; k< rxdatalen3 ; ++k)
    		{
    			data[k] = datarx3[k];
    		}
            uart_tx(uart3, data, rxdatalen3, SYS_FOREVER_MS); 
    	}
    	
    	if(rxupdate2==1)
    	{
    		rxupdate2 = 0;
    		for ( int k =0; k< rxdatalen2 ; ++k)
    		{
    			data[k] = datarx2[k];
    		}
            uart_tx(uart2, data, rxdatalen2, SYS_FOREVER_MS); 
    	}
        
    	k_sleep(K_MSEC(1000));
    	gpio_pin_toggle(port0,led5);
    
    	}
    }
                  

    Hi Sigurd

    I tried to insert my sample code at top. I don't know if you can see it correctly. If you can't see please guide me how I

    can send it for you. Any how, in this program all four uarts initializations and call backs are present. A terminal program

    ( doclight for example) will send some serial data to uarts 2 or 3 and send it back to terminal to test its functionality.

    As I mentioned before when the uart_init() routine sequence in the main routine is changed the forth uart responding

    is changed. All the three other uarts are working perfectly. This is not my actual project. I have just written this to test

    all four uarts functionality. 

    B.S.

  • I can see your code yes, thanks for the sample!

    When I run the code in a sample project of mine, it crashes. Could you add the prj.conf you used as well?

    Regard,
    Sigurd Hellesvik

  • 
    &uart0 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0x8000 0x1000 >;
    				interrupts = < 0x8 0x1 >;
    				status = "okay";
    				label = "UART_0";
    				current-speed = < 9600 >;
    				tx-pin = < 0x14 >;
    				rx-pin = < 0x16 >;
    				
    			};
    
    
    &uart1 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0x9000 0x1000 >;
    				interrupts = < 0x9 0x1 >;
    				status = "okay";
    				label = "UART_1";
    				current-speed = < 9600 >;
    				tx-pin = < 0x21 >;
    				rx-pin = < 0x20 >;
    				rx-pull-up;
    			};
    
    
    &uart2 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				status = "okay";
    				label = "UART_2";
    				current-speed = < 9600 >;
    				tx-pin = < 0x1F >;
    				rx-pin = < 0x0B >;
    				rx-pull-up;
    			};
    
    
    &uart3 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0xc000 0x1000 >;
    				interrupts = < 0xc 0x1 >;
    				status = "okay";
    				label = "UART_3";
    				current-speed = < 9600 >;
    				tx-pin = < 0x2E >;
    				rx-pin = < 0x2D >;
    				rx-pull-up;
    			};
    
    
    
    &led0  {
    			gpios = < &gpio0 0x1d 0x1 >;
    			label = "Green LED 0";
    		};
    &led1  {
    			gpios = < &gpio0 0x1e 0x1 >;
    			label = "Green LED 1";
    		};		
    &led2  {
    			gpios = < &gpio0 0x11 0x1 >;
    			label = "Green LED 2";
    		};         
    
    &led3  {
    			gpios = < &gpio0 0x12 0x1 >;
    			label = "Green LED 3";
    		};
    
    
    
    &adc {
    	compatible = "nordic,nrf-saadc";
    	reg = < 0xe000 0x1000 >;
    	interrupts = < 0xe 0x1 >;
    	status = "disabled";
    	label = "ADC_0";
    	#io-channel-cells = < 0x1 >;
    	phandle = < 0x6 >;
    };
    
    
    
    

    Hi again

    Its my overlay file too. I think it might be useful too.

    B.S. 

  • Hi Sigurd

    I want to inform you by changing the uart_init() functions as below the fourth uart also beccomes

    functional.

    static int uart3_init(void)
    {
    	uart_irq_rx_enable(uart3);
    	int err;
    	struct uart3_data_t *rx3;
    	uart3 = device_get_binding(DT_LABEL(DT_NODELABEL(uart3)));
    	
    	rx3 = k_malloc(256);       //k_malloc(sizeof(*rx3));
    	if (rx3)
    	{
    		rx3->len3 = 0;
    	}
    	else
    	{
    		return -ENOMEM;
    	}
    	
    	k_work_init_delayable(&uart3_work, uart3_work_handler);
    	
            err = uart_callback_set(uart3, uart3_cb, NULL);
    	if (err)
    	{
    		return err;
    	}
    	
    	return uart_rx_enable(uart3, rx3->data3, sizeof(rx3->data3), 10);
    	
    }

    Actually by allocating memory statically ( rx3 = k_malloc(256) ) the problem was solved.

    The maximum number of bytes in my application will never exceed 250 .

    Any how ,I am so thankful for your paying attention.

    B.S.

    Saeed Mahvis

  • Hi Saeed,

    Good job with fixing this!

    I were still working on a test for 4 uarts on my end, but met some bugs myself and was had not been able to complete it yet.

    I will mark your answer as the answer then.
    Good luck with your project

    Regards,
    Sigurd Hellesvik

Reply Children
No Data
Related