Can't read from gpio

Trying to read button 3 on the npm1300-ek, which is gpio 1 according to the schematic. The following #defines represent the gpio related registers on the npm1300:

#define GPIOS_MSB         0x06                     // GPIO registers MSB=0x600, individual registers below are added to this 
#define GPIO_MODE1      0x01                     // mode for gpio one (pin)
#define GPIO_STATUS_LOWER    0x1e       // gpio status (all five pins)

I verified that gpio 1 is set to an input using the following:

uint8_t regsy[] = {GPIOS_MSB, GPIO_MODE1};                            
ret = i2c_write_read_dt(&dev_i2c_pmic, regsy, 2, &valRead, 1); 
valRead came back zero indicating to me that the pin is an input
But when I press the button and read the inputs with the following:
uint8_t regsy[] = {GPIOS_MSB, GPIO_STATUS_LOWER};                            
ret = i2c_write_read_dt(&dev_i2c_pmicregsy2&valRead1); 
valRead comes back zero, indicating that the button hasn't affected the pin (it's also zero when the button isn't pressed)
Note that I can perform a write/read to an adc register and get the correct value back, so i2c should be working.
What am I missing?
  • Hello,

    I did not get around to testing this today, but we have a sample demonstrating how you can use the Zephyr GPIO driver API with the PMIC here: https://docs.nordicsemi.com/bundle/ncs-latest/page/nrf/samples/pmic/native/npm13xx_one_button/README.html. Have you tried this already? 

    The PMIC GPIO driver/shim can be found here: https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/gpio/gpio_npm13xx.c 

    Best regards,

    Vidar

  • Vidar,

    I don't know what I'm supposed to do with a PMIC GPIO driver/shim.

    I tried the npm13xx_one_button sample, but I'm not seeing the callback event (I put a printk() in

    event_callback()).
    I'm not testing the battery at this point, just trying to see a button, so I didn't set any of the jumpers mentioned in the readMe. But I did make the following connections:

    SDA

    P0.26

    SCL

    P0.27

    GPIO3

    P0.04

    VDDIO

    VDD

    GND

    GND

    Without adding the npm1300.overlay or the Extra CMake argument, I see "PMIC device ok" (but no call back). However, when I add either the overlay or the cmake argument, I get "Error: led device is not ready"

    I'm not sure where to go from here

  • Hi,

    Please try the modified version of this sample that I’ve included below. The zip also includes the changes I made (a diff), screenshot of build configuration and expected log output, and the hex file from my build.

    npm13xx_two_button.zip

    Note: it seems that sometimes after power up, you have to press Button 3 on the DK first before it can detect any GPIO events from the PMIC. I’ll discuss this issue with the developers.

  • Vidar,

    Thank you for the effort you put into this, but I can't seem to build what you sent me. In npm1300.overlay, I needed to change 

    #include <dt-bindings/regulator/npm13xx.h>

    to 
    #include <dt-bindings/regulator/npm1300.h>

    But now I'm getting another error in npm1300.overlay. Here's the output:

    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: C:/myNordic/fromDevZone/npm13xx_two_button
    -- CMake version: 3.21.0
    -- Found Python3: C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe (found suitable version "3.12.4", minimum required is "3.10") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v3.0.2/zephyr/.cache
    -- Zephyr version: 4.0.99 (C:/ncs/v3.0.2/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf52833dk, qualifiers: nrf52833
    -- Found host-tools: zephyr 0.17.0 (C:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.17.0 (C:/ncs/toolchains/0b393f9e1b/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/0b393f9e1b/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: C:/ncs/v3.0.2/zephyr/boards/nordic/nrf52833dk/nrf52833dk_nrf52833.dts
    -- Found devicetree overlay: npm1300.overlay
    devicetree error: ./npm1300.overlay:10 (column 1): parse error: undefined node label 'npm1300_ek_ldo1'
    CMake Error at C:/ncs/v3.0.2/zephyr/cmake/modules/dts.cmake:305 (execute_process):
    execute_process failed command indexes:

    1: "Child return code: 1"

    Call Stack (most recent call first):
    C:/ncs/v3.0.2/zephyr/cmake/modules/zephyr_default.cmake:133 (include)
    C:/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
    C:/ncs/v3.0.2/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
    CMakeLists.txt:8 (find_package)


    -- Configuring incomplete, errors occurred!
    ←[91mFATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\0b393f9e1b\opt\bin\cmake.EXE' -DWEST_PYTHON=C:/ncs/toolchains/0b393f9e1b/opt/bin/python.exe '-Bc:\myNordic\fromDevZone\npm13xx_two_bu
    tton\build' -GNinja -DBOARD=nrf52833dk/nrf52833 -DEXTRA_DTC_OVERLAY_FILE=npm1300.overlay '-Sc:\myNordic\fromDevZone\npm13xx_two_button'
    ←[0m
    * The terminal process terminated with exit code: 1.
    * Terminal will be reused by tasks, press any key to close it.

    Thank you

  • Sorry, I forgot to specify that I was testing against nrf connect sdk version 3.1.x and there looks to be some naming changes between these 2 sdk releases. Are you able to try with this SDK version too? I can also backport my changes if needed. 

Related