This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

UART Enable/Disable with sdk v1.3.0

Greeting,

We are in process of upgrading from sdk1.1.0 to sdk 1.3.0.
In order to use less current, we have to enable and disable uarts during program exectution:

Our code this far has been as follows:

void uart_0_disable(void)
{
    uart_0_is_enabled = false;
    // stop tx and rx
    NRF_UARTE0->TASKS_STOPTX = 1;
    NRF_UARTE0->TASKS_STOPRX = 1;
    // disable whole UART 0 interface
    NRF_UARTE0->ENABLE = 0;

    // deselect rx and tx pins and clear them
    NRF_UARTE0->PSEL.TXD = 0xFFFFFFFF;
    NRF_P0_NS->OUTCLR = (1 << PIN_UART_0_TX);

    NRF_UARTE0->PSEL.RXD = 0xFFFFFFFF;
    NRF_P0_NS->OUTCLR = (1 << PIN_UART_0_RX);

    // reconfigure them as GPIO pins and set them to output/0
    gpio_pin_configure(gpio_dev, PIN_UART_0_RX, GPIO_DIR_OUT);
    gpio_pin_write(gpio_dev, PIN_UART_0_RX, 0);

    gpio_pin_configure(gpio_dev, PIN_UART_0_TX, GPIO_DIR_OUT);
    gpio_pin_write(gpio_dev, PIN_UART_0_TX, 0);
}

void uart_0_enable(void)
{
    uart_0_is_enabled = true;
    // select pins
    NRF_UARTE0->PSEL.TXD = PIN_UART_0_TX;
    NRF_UARTE0->PSEL.RXD = PIN_UART_0_RX;

    // enable interface
    NRF_UARTE0->ENABLE = 8;
    NRF_UARTE0->TASKS_STARTRX = 1;
    NRF_UARTE0->TASKS_STARTTX = 1;
}

With this code, afer uart is disabled, we see a cca 680 μA power consumption drop.

With sdk v1.3.0 (and thus also new zephyr version), this code still runs (i.e. does not crash) and disables uart (LOG_INF after disable does nothing), but there is no drop in power consumption.

I have also tried using the new power management api:

void uart_0_disable(void)
{
   struct device *uart0_dev = device_get_binding("UART_0");
    device_set_power_state(uart0_dev, DEVICE_PM_OFF_STATE, NULL, NULL);
    
    gpio_pin_configure(gpio_dev, PIN_UART_0_RX, GPIO_OUTPUT);
    gpio_pin_set(gpio_dev, PIN_UART_0_RX, 0);

    gpio_pin_configure(gpio_dev, PIN_UART_0_TX, GPIO_OUTPUT);
    gpio_pin_set(gpio_dev, PIN_UART_0_TX, 0);
}

void uart_0_enable(void)
{
    struct device *uart0_dev = device_get_binding("UART_0");
    device_set_power_state(uart0_dev, DEVICE_PM_ACTIVE_STATE, NULL, NULL);
}

But the result is the same (aka printing gets disabled, but no consumption drop).

I ask if anything has changed regarding this and if so, how is this to be done now?

Regards,
Tjaž

  • Hello Tjaž,

    For lowest current consumption, the pins should be set to disconnected input. Can you please try to set this in the uart_0_disable() function?

    when you set it to output, the nRF will use power to keep the pin low. Especially if there is something else in the other end trying to pull it high. 

    Best regards,

    Edvin

  • Hello,

    I have tried both GPIO_INPUT and GPIO_DISCONNECTED insted of GPIO_OUTPUT:

    gpio_pin_configure(gpio_dev, PIN_UART_0_RX, GPIO_DISCONNECTED);
    gpio_pin_configure(gpio_dev, PIN_UART_0_TX, GPIO_DISCONNECTED);

    and

    gpio_pin_configure(gpio_dev, PIN_UART_0_RX, GPIO_INPUT);
    gpio_pin_configure(gpio_dev, PIN_UART_0_TX, GPIO_INPUT);

    Both have the same effect on power consumption as GPIO_OUTPUT - none.

    Again, to reiterate
    The code I posted used to work for us, and we saw power consumption drop, this means that the UART peripheral device did in fact "shut down" and get cut from power.

    Now, with sdk v1.3.0, this no longer happens.

    Even if setting the pins to output causes the nRF to "use power to keep it low" as you stated, the power consumption should still change (drop), since the UART device should be disabled.

  • Hello again,

    sorry.

    We use uart0 and uart1 (one for debug, and one to communicate with another chip). I was testing by enabling/disabling only uart1, but turns out, if I disable both, power consumption drops as expected.

    Sorry for the trouble.

    For others looking at this thread, both methods work (using the new power management api and using the registers directly).

    Regards,
    Tjaž

  • Hello  

    At which level did you succeed to reduce the power consumption ?

    Do you have code sample for your UART shutdown ?

    Best regards,

    Lam

Related