Connecting the npm1300 to a custom board

Good Day.

I'm trying to run the "npm1300_fuel_gauge" example on a custom board (nRF52840), but I'm getting errors that I don't know how to fix. 

The first thing I did was to get the PMIC configuration overlay file (config.overlay) through nPM PowerUP. Then I transferred the code from config.overlay to the custom board device tree file (custom_board_nrf52840.dts). I plan to connect the PMIC via I2C1. 

custom_board_nrf52840.dts -->

&i2c1 {
	compatible = "nordic,nrf-twi";
	/* Cannot be used together with spi1. */
	status = "okay";
	pinctrl-0 = <&i2c1_default>;
	pinctrl-1 = <&i2c1_sleep>;
	pinctrl-names = "default", "sleep";

	npm1300_ek_pmic: pmic@6b {
		compatible = "nordic,npm1300";
		reg = <0x6b>;

		npm1300_ek_gpio: gpio-controller {
			compatible = "nordic,npm1300-gpio";
			gpio-controller;
			#gpio-cells = <2>;
			ngpios = <5>;
		};

		npm1300_ek_regulators: regulators {
			compatible = "nordic,npm1300-regulator";

	npm1300_ek_buck1: BUCK1 {
	 regulator-min-microvolt = <1000000>;
	 regulator-max-microvolt = <3300000>;
	 retention-microvolt = <1200000>;
	};

	npm1300_ek_buck2: BUCK2 {
	 regulator-min-microvolt = <1000000>;
	 regulator-max-microvolt = <3300000>;
	 retention-microvolt = <1800000>;
	};

	npm1300_ek_ldo1: LDO1 {
	 regulator-min-microvolt = <1000000>;
	 regulator-max-microvolt = <3300000>;

	 regulator-initial-mode = <NPM1300_LDSW_MODE_LDSW>;
	 // soft-start-microamp = <10000>;
	};

	npm1300_ek_ldo2: LDO2 {
	 regulator-min-microvolt = <1000000>;
	 regulator-max-microvolt = <3300000>;

	 regulator-initial-mode = <NPM1300_LDSW_MODE_LDSW>;
	 // soft-start-microamp = <10000>;
	};
	};

	npm1300_ek_charger: charger {
	 compatible = "nordic,npm1300-charger";
	 term-microvolt = <4200000>;
	 term-warm-microvolt = <3600000>;
	 // term-current-percent = <10>;
	 current-microamp = <100000>;
	 // trickle-microvolt = <2900000>;
	 dischg-limit-microamp = <1000000>;
	 vbus-limit-microamp = <500000>;
	 thermistor-ohms = <10000>;
	 thermistor-beta = <3380>;
	 charging-enable;
	};

	npm1300_ek_leds: leds {
	 compatible = "nordic,npm1300-led";
	 nordic,led0-mode = "error";
	  nordic,led1-mode = "charging";
	  nordic,led2-mode = "host";
	};
	};
};

custom_board_nrf52840-pinctrl.dtsi -->

i2c1_default: i2c1_default {
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 15)>,
				<NRF_PSEL(TWIM_SCL, 0, 17)>;
			bias-pull-up;
		};
	};

	i2c1_sleep: i2c1_sleep {
		group1 {
			psels = <NRF_PSEL(TWIM_SDA, 0, 15)>,
				<NRF_PSEL(TWIM_SCL, 0, 17)>;
			low-power-enable;
		};
	};

The following errors occur in the .dts file (see screenshot).

I know that these values should be taken from the "fuel_gauge.h" file, but that doesn't happen for some reason.

I see an error in the prj.conf file too (see screenshot). 

When building the project, I see the following information -->

I have not changed the CMakeLists.txt files. 

# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause

cmake_minimum_required(VERSION 3.20.0)

set(SHIELD npm1300_ek)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(my_npm1300_fuel_gauge)

add_subdirectory(src)

Can you please tell me where I am making a mistake when transferring this example to my custom board?

Thank you.

  • Hi,

    Looks like NPM1300_LDSW_MODE_LDSW is not defined for that file.

    So I searched for that in the nRF Connect SDK and found it used in zephyr/boards/shields/npm1300_ek/npm1300_ek.overlay.

    At the top of this file, there is an include:

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

    Could you by chance, be missing this?

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd, thank you for your response.

    Yes indeed, I didn't add that inclusion to the device tree file. After that, there was no error with the NPM1300_LDSW_MODE_LDSW detection.

    But cmake errors were still present.

    These errors were resolved by modifying the CMakeLists.txt file -->

    # Copyright (c) 2023 Nordic Semiconductor ASA
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    
    cmake_minimum_required(VERSION 3.20.0)
    
    set(SHIELD npm1300_ek)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(NONE)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE
      src/main.c
      src/fuel_gauge.c
    )
    
    # NORDIC SDK APP END
    zephyr_library_include_directories(.)
    

    After that, the project build went through without errors. 

    But the application terminates (return 0) after -->

    if (!device_is_ready(charger)) {
    		LOG_DBG("Charger device not ready.\n");
    		return 0;
    	}

    Do you have any idea what this could be related to? All connections and jumpers are set according to the example.

    Also, I would like to ask if it is mandatory to use npm1300_ek.overlay? What is the point of using the config.overlay file from nPM PowerUP if it will be overwritten by npm1300_ek.overlay?

    Thanks.

  • Hi. I also have additional questions:

    1. When the nPM1300 EK is connected to the custom board and USB is connected to J3, should the CHG LED light up? Or will it only light up after initialization in the software? In my case, none of the LEDs are lit.

    2. Should I2C be initialized (and include an I2C driver ) when connecting to a custom board? I got the I2C1 structure and checked for hardware readiness, there were no errors and I got the response "I2C bus i2c@40004000 is ready". So hopefully the error is not in the I2C1 line in that the npm1300 is not being detected.

    And a couple more questions about EK behavior in nPM PowerUP:

    3. When I connect the battery (custom model profile) I see a different percentage of charge each time. For example, I connect the battery and the program shows 82 %, I immediately disconnect the EK from the computer and reconnect it and PowerUP shows already 88 % charge. On average, the charge value differs by 5% when you turn it on again. Is this normal program behavior or is something wrong?

    4. The charging end time is almost never displayed when charging is turned on (see screenshot). Is this normal?

    I look forward to your help.

    Thank you.

  • Hi.

    I've identified the reason the device wasn't not ready. The cause was a missing contact on the I2C line. I have also solved questions 1 and 2 (from the previous message).

    But I would like to get answers to questions 3 and 4, as well as another new question:

    5. In the fuel_gauge example, there is a file called battery_model.inc in the src folder. I understand that this is the battery profile for the example. How do I add my own battery profile (which I already have)? Do I need to rename it to "battery_model" and replace the existing file or can I add it with an arbitrary name (for example, my_battery.inc)?

    Thanks.

  • Good to hear that you figured some of it out.
    We are just back from Easter vacation, so I  will get back to you  on your questions in some days.

Related