Skip to content

Commit b0dd059

Browse files
committed
samples: npm2100_fuel_gauge: Fuel gauge sample added
nPM2100 fuel gauge sample application, which uses primary cell battery models. Signed-off-by: Audun Korneliussen <audun.korneliussen@nordicsemi.no>
1 parent 5697b09 commit b0dd059

11 files changed

+616
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
8+
project(npm2100_fuel_gauge)
9+
10+
add_subdirectory(src)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
.. _npm2100_fuel_gauge:
2+
3+
nPM2100: Fuel gauge
4+
###################
5+
6+
.. contents::
7+
:local:
8+
:depth: 2
9+
10+
The fuel gauge sample demonstrates how to calculate the state of charge of a supported primary cell battery using `nPM2100 <nPM2100 product website_>`_ and the :ref:`nrfxlib:nrf_fuel_gauge`.
11+
12+
For more information about fuel gauging, see `Using the nPM1300 Fuel Gauge`_.
13+
14+
Requirements
15+
************
16+
17+
The sample supports the following development kits:
18+
19+
.. table-from-sample-yaml::
20+
21+
The sample also requires an `nPM2100 EK <nPM2100 EK product page_>`_ that you need to connect to the development kit as described in `Wiring`_.
22+
23+
Overview
24+
********
25+
26+
This sample allows the calculation of state of charge from a battery connected to the nPM2100 PMIC.
27+
28+
Battery models for Alkaline AA, AA, LR44, and Lithium-manganese dioxide coin cell CR2032 batteries are included. The active battery model can be changed using a shell command, as illustrated in `Testing`_.
29+
30+
Wiring
31+
******
32+
33+
Note that the nPM2100 EK is here configured to supply power to your DK.
34+
In order prevent leakage currents and to continue being able to program the DK, do not remove the DK USB connection.
35+
36+
The following preparations should be made to the DK in order to power the nRF5x SoC from nPM2100 EK:
37+
38+
#. nRF52840 DK:
39+
40+
* Set switch **SW9** ("nRF power source") to position "VDD".
41+
* Set switch **SW10** ("VEXT -> VnRF") to position "ON".
42+
43+
#. nRF5340 DK:
44+
45+
* Set switch **SW9** ("nRF power source") to position "VDD".
46+
* Set switch **SW10** ("VEXT -> VnRF") to position "ON".
47+
48+
49+
#. nRF54L15 DK:
50+
51+
* Remove jumper from **P6** ("VDDM CURRENT MEASURE").
52+
53+
#. Connect the TWI interface and power supply between the chosen DK and the nPM2100 EK as described in the following table:
54+
55+
.. list-table:: nPM2100 EK connections.
56+
:widths: auto
57+
:header-rows: 1
58+
59+
* - nPM2100 EK pins
60+
- nRF52840 DK pins
61+
- nRF5340 DK pins
62+
- nRF54L15 DK pins
63+
* - SDA
64+
- P0.26
65+
- P1.02
66+
- P1.11
67+
* - SCL
68+
- P0.27
69+
- P1.03
70+
- P1.12
71+
* - VOUT
72+
- P21 External supply
73+
- P21 External supply
74+
- P6 VDDM current measure, middle pin
75+
* - GND
76+
- GND
77+
- GND
78+
- GND
79+
80+
#. Make the following connections on the nPM2100 EK:
81+
82+
* Remove the USB power supply from the **J4** connector.
83+
* On the **P6** pin header, connect pins 1 and 2 with a jumper.
84+
* On the **BOOTMON** pin header, select **OFF** with a jumper.
85+
* On the **VSET** pin header, select **3.0V** with a jumper.
86+
* On the **VBAT SEL** pin header, select **VBAT** with a jumper.
87+
* Connect a battery board to the **BATTERY INPUT** connector.
88+
89+
Building and running
90+
********************
91+
92+
.. |sample path| replace:: :file:`samples/pmic/native/npm1300_one_button`
93+
94+
.. include:: /includes/build_and_run.txt
95+
96+
97+
Testing
98+
*******
99+
100+
|test_sample|
101+
102+
#. |connect_kit|
103+
#. |connect_terminal|
104+
105+
If the initialization was successful, the terminal displays the following message with status information:
106+
107+
.. code-block:: console
108+
109+
PMIC device ok
110+
V: 1.5, T: 23.06, SoC: 90.00
111+
nRF Fuel Gauge version: 1.0.0
112+
Fuel gauge initialised for Alkaline AA battery.
113+
V: 1.188, T: 20.62, SoC: 25.00
114+
115+
.. _table::
116+
:widths: auto
117+
118+
====== =============== ==================================================
119+
Symbol Description Units
120+
====== =============== ==================================================
121+
V Battery voltage Volts
122+
T Temperature Degrees C
123+
SoC State of Charge Percent
124+
====== =============== ==================================================
125+
126+
The active battery type can be determined by using the following shell command:
127+
128+
.. code-block:: console
129+
130+
$ battery_model
131+
Battery model: Alkaline AA
132+
133+
The same shell command can be used to change the active battery type:
134+
135+
.. code-block:: console
136+
137+
$ battery_model Lithium_CR2032
138+
Fuel gauge initialised for Lithium CR2032 battery.
139+
140+
Dependencies
141+
************
142+
143+
The sample uses the following `sdk-nrfxlib`_ library:
144+
145+
* :ref:`nrfxlib:nrf_fuel_gauge`
146+
147+
In addition, it uses the following Zephyr libraries:
148+
149+
* :ref:`zephyr:logging_api`
150+
* :ref:`zephyr:shell_api`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <dt-bindings/regulator/npm2100.h>
8+
9+
&i2c0_default {
10+
group1 {
11+
bias-pull-up;
12+
};
13+
};
14+
15+
&arduino_i2c {
16+
npm2100ek_pmic: pmic@74 {
17+
compatible = "nordic,npm2100";
18+
reg = <0x74>;
19+
20+
npm2100ek_gpio: gpio-controller {
21+
compatible = "nordic,npm2100-gpio";
22+
gpio-controller;
23+
#gpio-cells = <2>;
24+
ngpios = <2>;
25+
};
26+
27+
npm2100ek_regulators: regulators {
28+
compatible = "nordic,npm2100-regulator";
29+
30+
/* limits are set to min/max allowed values */
31+
npm2100ek_boost: BOOST {
32+
regulator-min-microvolt = <1800000>;
33+
regulator-max-microvolt = <3300000>;
34+
regulator-init-microamp = <0>;
35+
};
36+
37+
npm2100ek_ldosw: LDOSW {
38+
regulator-min-microvolt = <800000>;
39+
regulator-max-microvolt = <3000000>;
40+
};
41+
};
42+
43+
npm2100ek_wdt: watchdog {
44+
compatible = "nordic,npm2100-wdt";
45+
};
46+
47+
npm2100ek_vbat: vbat {
48+
compatible = "nordic,npm2100-vbat";
49+
};
50+
};
51+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <dt-bindings/regulator/npm2100.h>
8+
9+
&i2c1_default {
10+
group1 {
11+
bias-pull-up;
12+
};
13+
};
14+
15+
&arduino_i2c {
16+
npm2100ek_pmic: pmic@74 {
17+
compatible = "nordic,npm2100";
18+
reg = <0x74>;
19+
20+
npm2100ek_gpio: gpio-controller {
21+
compatible = "nordic,npm2100-gpio";
22+
gpio-controller;
23+
#gpio-cells = <2>;
24+
ngpios = <2>;
25+
};
26+
27+
npm2100ek_regulators: regulators {
28+
compatible = "nordic,npm2100-regulator";
29+
30+
/* limits are set to min/max allowed values */
31+
npm2100ek_boost: BOOST {
32+
regulator-min-microvolt = <1800000>;
33+
regulator-max-microvolt = <3300000>;
34+
regulator-init-microamp = <0>;
35+
};
36+
37+
npm2100ek_ldosw: LDOSW {
38+
regulator-min-microvolt = <800000>;
39+
regulator-max-microvolt = <3000000>;
40+
};
41+
};
42+
43+
npm2100ek_wdt: watchdog {
44+
compatible = "nordic,npm2100-wdt";
45+
};
46+
47+
npm2100ek_vbat: vbat {
48+
compatible = "nordic,npm2100-vbat";
49+
};
50+
};
51+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <dt-bindings/regulator/npm2100.h>
7+
8+
&pinctrl {
9+
i2c21_default_alt: i2c21_default_alt {
10+
group1 {
11+
psels = <NRF_PSEL(TWIM_SDA, 1, 11)>,
12+
<NRF_PSEL(TWIM_SCL, 1, 12)>;
13+
bias-pull-up;
14+
};
15+
};
16+
17+
i2c21_sleep_alt: i2c21_sleep_alt {
18+
group1 {
19+
psels = <NRF_PSEL(TWIM_SDA, 1, 11)>,
20+
<NRF_PSEL(TWIM_SCL, 1, 12)>;
21+
low-power-enable;
22+
};
23+
};
24+
};
25+
26+
arduino_i2c: &i2c21 {
27+
compatible = "nordic,nrf-twim";
28+
status = "okay";
29+
pinctrl-0 = <&i2c21_default_alt>;
30+
pinctrl-1 = <&i2c21_sleep_alt>;
31+
pinctrl-names = "default", "sleep";
32+
};
33+
34+
&arduino_i2c {
35+
npm2100ek_pmic: pmic@74 {
36+
compatible = "nordic,npm2100";
37+
reg = <0x74>;
38+
39+
npm2100ek_gpio: gpio-controller {
40+
compatible = "nordic,npm2100-gpio";
41+
gpio-controller;
42+
#gpio-cells = <2>;
43+
ngpios = <2>;
44+
};
45+
46+
npm2100ek_regulators: regulators {
47+
compatible = "nordic,npm2100-regulator";
48+
49+
/* limits are set to min/max allowed values */
50+
npm2100ek_boost: BOOST {
51+
regulator-min-microvolt = <1800000>;
52+
regulator-max-microvolt = <3300000>;
53+
regulator-init-microamp = <0>;
54+
};
55+
56+
npm2100ek_ldosw: LDOSW {
57+
regulator-min-microvolt = <800000>;
58+
regulator-max-microvolt = <3000000>;
59+
};
60+
};
61+
62+
npm2100ek_wdt: watchdog {
63+
compatible = "nordic,npm2100-wdt";
64+
};
65+
66+
npm2100ek_vbat: vbat {
67+
compatible = "nordic,npm2100-vbat";
68+
};
69+
};
70+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
CONFIG_SHELL=y
5+
CONFIG_LOG=y
6+
CONFIG_LOG_CMDS=y
7+
CONFIG_GPIO=y
8+
CONFIG_REGULATOR=y
9+
CONFIG_SENSOR=y
10+
CONFIG_I2C_SHELL=y
11+
CONFIG_NRF_FUEL_GAUGE=y
12+
CONFIG_NRF_FUEL_GAUGE_VARIANT_PRIMARY_CELL=y
13+
CONFIG_REQUIRES_FLOAT_PRINTF=y
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
sample:
4+
name: nPM2100 fuel gauge
5+
6+
common:
7+
integration_platforms:
8+
- nrf52840dk/nrf52840
9+
- nrf5340dk/nrf5340/cpuapp
10+
- nrf54l15dk/nrf54l15/cpuapp
11+
platform_allow:
12+
- nrf52840dk/nrf52840
13+
- nrf5340dk/nrf5340/cpuapp
14+
- nrf54l15dk/nrf54l15/cpuapp
15+
tags:
16+
- pmic
17+
- ci_samples_pmic
18+
tests:
19+
samples.compile:
20+
sysbuild: true
21+
platform_allow:
22+
- nrf52840dk/nrf52840
23+
- nrf5340dk/nrf5340/cpuapp
24+
- nrf54l15dk/nrf54l15/cpuapp
25+
tags:
26+
- sysbuild
27+
- ci_samples_pmic
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2025 Nordic Semiconductor
2+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
3+
4+
target_sources(app PRIVATE main.c)
5+
target_sources(app PRIVATE fuel_gauge.c)

0 commit comments

Comments
 (0)