NRF9160 Disable UART and RX pin into an interrupt pin

Hello everyone,

I'm working on a project with NRF9160 nRF Connect SDK v2.3.0.

In my project i use UART0 to exchange data and i disable the UART when is not use.

I need an interrupt to wake up my device when data come on the UART pin (TX/RX).

I have found different topic to disable and enable UART on runinng time. 

Now, when my uart is disable, i would like to convert RX pin into an interrupt pin which allow me to re-enable the UART to get data when interrupt occur.

Could you tell me if you have any advice about that ?

Best regards,

Lam

Parents
  • Hello,

    I'm able to disable my uart with this part of code : 

    uint8_t disable_uart(void){
    
        //Disable uart0 which use to exchange message between modem and an external device
        NRF_UARTE0_NS->TASKS_STOPTX = 1;
        NRF_UARTE0_NS->TASKS_STOPRX = 1;
        NRF_UARTE0_NS->ENABLE = 0;
    
        //configure RX pin int o input gpio
        const struct device * gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
        gpio_pin_configure(gpio_dev,6, GPIO_INPUT);
       
    }

    And i obtain an power consumption arround 6uA.

    Now i'm trying to convert my RX gpio into an interrupt GPIO but without success.

    I have try this after checking information in the sample button in SDK

    #define SWIN3_NODE	DT_ALIAS(swin3)
    #if !DT_NODE_HAS_STATUS(SWIN3_NODE, okay)
    #error "Unsupported board: SWIN3 devicetree alias is not defined"
    #endif
    
    static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SWIN3, gpios,{0}); 
    static struct gpio_callback button_cb_data;
    
    void button_pressed(const struct device *dev, struct gpio_callback *cb,
    		    uint32_t pins)
    {
    	printk("Button pressed\r\n");
    }
    
    //gpio for UART interrupt definition
    void configure_int_rx(void){
    	int ret;
    
    	printk("configure interrupt\r\n");
    
    	ret = gpio_pin_configure_dt(&button,GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error");// %d: failed to configure %s pin %d\n",
    		      // ret, button.port->name, button.pin);
    		return;
    	}
    
    	printk("test1\r\n");
    
    	ret = gpio_pin_interrupt_configure_dt(&button,GPIO_INT_EDGE_TO_ACTIVE);		//GPIO_INT_EDGE_BOTH
    	if (ret != 0) {
    		printk("Error");// %d: failed to configure interrupt on %s pin %d\n",
    			//ret, button.port->name, button.pin);
    		return;
    	}
    
    	printk("test2\r\n");
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));
    	gpio_add_callback(button.port, &button_cb_data);
    	printk("Set up button");// at %s pin %d\n", button.port->name, button.pin);
    
    }
    
    

    The resultat that i obtain is a reboot of my board every time the code start to execute "configure_int_rx" function.

    Update below

    thanks for your help,

    Best regards,

    Lam

Reply
  • Hello,

    I'm able to disable my uart with this part of code : 

    uint8_t disable_uart(void){
    
        //Disable uart0 which use to exchange message between modem and an external device
        NRF_UARTE0_NS->TASKS_STOPTX = 1;
        NRF_UARTE0_NS->TASKS_STOPRX = 1;
        NRF_UARTE0_NS->ENABLE = 0;
    
        //configure RX pin int o input gpio
        const struct device * gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
        gpio_pin_configure(gpio_dev,6, GPIO_INPUT);
       
    }

    And i obtain an power consumption arround 6uA.

    Now i'm trying to convert my RX gpio into an interrupt GPIO but without success.

    I have try this after checking information in the sample button in SDK

    #define SWIN3_NODE	DT_ALIAS(swin3)
    #if !DT_NODE_HAS_STATUS(SWIN3_NODE, okay)
    #error "Unsupported board: SWIN3 devicetree alias is not defined"
    #endif
    
    static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SWIN3, gpios,{0}); 
    static struct gpio_callback button_cb_data;
    
    void button_pressed(const struct device *dev, struct gpio_callback *cb,
    		    uint32_t pins)
    {
    	printk("Button pressed\r\n");
    }
    
    //gpio for UART interrupt definition
    void configure_int_rx(void){
    	int ret;
    
    	printk("configure interrupt\r\n");
    
    	ret = gpio_pin_configure_dt(&button,GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error");// %d: failed to configure %s pin %d\n",
    		      // ret, button.port->name, button.pin);
    		return;
    	}
    
    	printk("test1\r\n");
    
    	ret = gpio_pin_interrupt_configure_dt(&button,GPIO_INT_EDGE_TO_ACTIVE);		//GPIO_INT_EDGE_BOTH
    	if (ret != 0) {
    		printk("Error");// %d: failed to configure interrupt on %s pin %d\n",
    			//ret, button.port->name, button.pin);
    		return;
    	}
    
    	printk("test2\r\n");
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));
    	gpio_add_callback(button.port, &button_cb_data);
    	printk("Set up button");// at %s pin %d\n", button.port->name, button.pin);
    
    }
    
    

    The resultat that i obtain is a reboot of my board every time the code start to execute "configure_int_rx" function.

    Update below

    thanks for your help,

    Best regards,

    Lam

Children
  • I found my error, lin 1, I define SWIN3_NODE and line 6 i use SWIN3. That wrong, i need to write on line 6 : "SWIN3_NODE"

    I have add in "configure_int_rx" function, 

    if (!device_is_ready(button.port)) {
    		printk("Error");
    		return;
    	}

    At the top of the function

    //gpio for UART interrupt definition
    void configure_int_rx(void){
    	int ret;
    
    	printk("configure interrupt\r\n");
    
    	if (!device_is_ready(button.port)) {
    		printk("Error");
    		return;
    	}
    
    	ret = gpio_pin_configure_dt(&button,GPIO_INPUT);
    	if (ret != 0) {
    		printk("Error");// %d: failed to configure %s pin %d\n",
    		      // ret, button.port->name, button.pin);
    		return;
    	}
    
    	printk("test1\r\n");
    
    	ret = gpio_pin_interrupt_configure_dt(&button,GPIO_INT_EDGE_TO_ACTIVE);		//GPIO_INT_EDGE_BOTH
    	if (ret != 0) {
    		printk("Error");// %d: failed to configure interrupt on %s pin %d\n",
    			//ret, button.port->name, button.pin);
    		return;
    	}
    
    	printk("test2\r\n");
    
    	gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin));
    	gpio_add_callback(button.port, &button_cb_data);
    	printk("Set up button");// at %s pin %d\n", button.port->name, button.pin);
    }

    No I'm trying to disable, my interrupt to reenable the uart when my interrupt occur.

    When my interrupt occur, my callback function do that :

    void button_pressed(const struct device *dev, struct gpio_callback *cb,
    		    uint32_t pins)
    {
    	const struct device * gpio_dev = DEVICE_DT_GET(DT_NODELABEL(gpio0));
        gpio_pin_configure(gpio_dev,6, GPIO_DISCONNECTED);
    	printk("Button pressed\r\n");
    	restart_uart();
    
    }

    In my "restart_uart", i do that

    uint8_t restart_uart(void){
    
    
       const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));
    
        if (!device_is_ready(uart)) {
            printk("error device ready\r\n");
            return;
        }
        initControlUart();
        printk("restart uart\r\n");
    }

    When my initControlUart is executed, i have an error in this code: 

     error = uart_rx_enable(uart_info.dev, buffer, RX_BUFF_LEN, RX_RCV_TIMEOUT);
        if(error != 0){
            printk("ERROR : Unable to init RX\n");
            return -1;
        }

    That works great at init but when i try to restart that's not work. It seems that RX gpio stay unable to be configure in RX

    Update below

    Best regards,

    lam

Related