nRF52840 pin phantom low transitions

Hi there,

I'm using an nRF52840 pin to monitor GPIO state transitions, but it keeps reporting frequent phantom low transitions without high transitions in between. According to my Saleae Logic 4 analyzer, the pin is always low.

Devicetree fragment:

/ {
    gpios {
        compatible = "gpio-keys";

        charger_stat: charger_stat {
            gpios = <&gpio0 22 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
            label = "charger_stat";
        };
    }
}

Code fragment:

const struct gpio_dt_spec chargerStatDt = GPIO_DT_SPEC_GET(DT_ALIAS(charger_stat), gpios);

void chargerStatCallback(const struct device *port, struct gpio_callback *cb, gpio_port_pins_t pins) {
    if (Shell.statLog) {
        printk("STAT changed to %i\n", gpio_pin_get_dt(&chargerStatDt) ? 1 : 0);
    }
}

gpio_pin_configure_dt(&chargerStatDt, GPIO_INPUT);
gpio_pin_interrupt_configure_dt(&chargerStatDt, GPIO_INT_EDGE_BOTH);
gpio_init_callback(&callbackStruct, chargerStatCallback, BIT(chargerStatDt.pin));
gpio_add_callback(chargerStatDt.port, &callbackStruct);

Thanks in advance for your help!

- Laci

Parents
  • Hi Laci

    Is the pin connected to anything? 

    According to my Saleae Logic 4 analyzer, the pin is always low.

    Are you using the logic analyzer in analog or digital mode? 

    If it is in digital mode there might be spikes on the pin that will not be detected, if the voltage is below the detection threshold. 

    It is theoretically possible for the GPIO module to miss events if the pin is toggling too fast, especially if you add a lot of code to the callback function directly. You could try to remove the logging call from the callback and see if this solves the problem of missing events (as an alternative you could push the value of the pin to a message queue, or set a variable or semaphore that you can process from a thread). 

    Best regards
    Torbjørn

Reply
  • Hi Laci

    Is the pin connected to anything? 

    According to my Saleae Logic 4 analyzer, the pin is always low.

    Are you using the logic analyzer in analog or digital mode? 

    If it is in digital mode there might be spikes on the pin that will not be detected, if the voltage is below the detection threshold. 

    It is theoretically possible for the GPIO module to miss events if the pin is toggling too fast, especially if you add a lot of code to the callback function directly. You could try to remove the logging call from the callback and see if this solves the problem of missing events (as an alternative you could push the value of the pin to a message queue, or set a variable or semaphore that you can process from a thread). 

    Best regards
    Torbjørn

Children
  • Hi Torbjørn,

    The GPIO pin is connected to the STAT pin of a BQ25303J battery charger IC. When no battery is connected to the IC, and charging is enabled, the IC toggles the pin on a half-second basis, which is correctly detected.

    I used my logic analyzer in analog mode, and it measured a constant of zero volts.

    The GPIO module doesn't miss any events. Rather, it detects phantom events and shouldn't detect any phantom event regardless of the callback function.

    Do you have other ideas? If not, I'll build another prototype to determine whether it's a one-off.

  • Hi Laci

    I don't really have any immediate ideas, no, but if you are using custom hardware then it is definitely possible that it is somehow hardware related. 

    When you say prototype do you mean a full prototype PCB, or are you using some kind of nRF52840 module? 

    Would you be able to provide a picture of your PCB, and schematics if you have some? 

    Best regards
    Torbjørn

Related