UART0, UART1 and I2C0 utilization and Initialization

Hi, I need to use UART0, UART1 and I2C0 in my application. I initialized these in overlay file (attached). When, debug is run, it is observed that the I2C binding is not successful see attached image file. I am using UART0 and UART1 in asynchrounous mode.  The zypher.dts fie also is attached. 

8176.bms_nrf5340_cpuapp.overlay5023.zephyr.dts   

  • Hello, I studied about Peripheral Resource Sharing. I could not find method to switch shared resources between competetive peripherals alernatively. UART1 and I2C0 share same address space and only one should be enabled at a time. Did, you find any ways to multiplex such pripherals ? I need to send the data to UART1 and to I2C0 alternatively and never need both at time. What is metod to use these alteranatively ? 

  • Hi

    Have you tried to disable UART1 in software when using I2C0?

    Regards,
    Sigurd Hellesvik

  • Yes, I tried to initializae the I2C0 peripheral using

    void init_i2c_master()
    {
    dev_i2c = device_get_binding("I2C_0");
    if (dev_i2c == NULL) {
    printk("Failed to get I2C0 binding\n");
    return;
    }
    }

    after disable of UART1 using  

    void disable_uart1(){
    NRF_UARTE0->TASKS_STOPTX = 1;
    NRF_UARTE0->TASKS_STOPRX = 1;
    }

    but, I2C initilaize fail, when run Debug .. though build and Compile is successful.

  • Hi

    Could you post the error message you receive?

    To get more debug information, set the following configurations in prj.conf:

    CONFIG_RESET_ON_FATAL_ERROR=n
    CONFIG_LOG=y
    CONFIG_THREAD_NAME=y

    Regards,
    Sigurd Hellesvik

  • Hello, I tried after adding the configurations in prj.conf, but I2C0 binding is not successful.

    Please, test the following Code:

    //************ Add to prj.conf file ******
    CONFIG_SERIAL=y
    CONFIG_UART_ASYNC_API=y
    CONFIG_RESET_ON_FATAL_ERROR=n
    CONFIG_LOG=y
    CONFIG_THREAD_NAME=y
    //***************add to the overlay file
    &uart0{
        current-speed = <115200>;
    };
    &uart1{
    current-speed = <9600>;
    status = "okay";
    };
    &i2c0{
      status = "okay";
      clock-frequency = < 400 >;
    };
    
    //***************************************
    static const struct device *wifi_uart;
    static const struct device *bms_uart;
    //*************************************
    void init_i2c_master()
    {
      dev_i2c = device_get_binding("I2C_0");
      if (dev_i2c == NULL) {
    		printk("Failed to get I2C0 binding\n");
    		return;        
    	}
    }
    void wifi_uart_init(void)
    {
            
    	wifi_uart = device_get_binding("UART_0");
    	if (wifi_uart == NULL) {
    		printk("Failed to get UART0 binding\n");
    		return;        
    	}
    }
    void bms_uart_init(void)
    {
            
    	bms_uart = device_get_binding("UART_1");
    	if (bms_uart == NULL) {
    		printk("Failed to get UART1 binding\n");
    		return;        
    	}
    }
    void disable_uart1(){
            NRF_UARTE0->TASKS_STOPTX = 1;
            NRF_UARTE0->TASKS_STOPRX = 1;
    }
    
    void enable_uart1(){
            NRF_UARTE0->TASKS_STARTRX = 1;
            NRF_UARTE3->TASKS_STARTRX = 1;
    }
    
    void main()
    {
    	wifi_uart_init();
    	bms_uart_init();
            disable_uart1();// disable UART1 to enable I2C0
            init_i2c_master();// I2C0 enable 
    }
     

Related