Skip to content

Commit f2f212f

Browse files
nordic-aukonordicjm
authored andcommitted
samples: npm2100_fuel_gauge: Fuel gauge sample added
nPM2100 fuel gauge sample application, which uses primary cell battery models. Signed-off-by: Audun Korneliussen <[email protected]>
1 parent cf8ba9d commit f2f212f

File tree

15 files changed

+612
-0
lines changed

15 files changed

+612
-0
lines changed

doc/nrf/links.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@
358358
.. _`nPM1300 EK product page`: https://www.nordicsemi.com/Products/Development-hardware/nPM1300-EK
359359
.. _`nPM1300 EK get started`: https://www.nordicsemi.com/Products/Development-hardware/nPM1300-EK/Get-started?lang=en#infotabs
360360

361+
.. _`nPM2100 product website`: https://www.nordicsemi.com/Products/nPM2100
362+
361363
.. _`nRF Desktop reference design page`: https://www.nordicsemi.com/Products/Reference-designs/nRF-Desktop
362364

363365
.. _`Nordic Semiconductor's IoT cloud platform`: https://www.nordicsemi.com/Products/Cloud-services

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,8 @@ Peripheral samples
537537
PMIC samples
538538
------------
539539

540+
* Added the :ref:`npm2100_fuel_gauge` sample that demonstrates how to calculate the battery state of charge of primary cell batteries using the :ref:`nrfxlib:nrf_fuel_gauge`.
541+
540542
* :ref:`npm1300_fuel_gauge` sample:
541543

542544
* Updated to accommodate API changes in nRF Fuel Gauge library v1.0.0.
Lines changed: 10 additions & 0 deletions
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)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menu "Zephyr"
8+
source "Kconfig.zephyr"
9+
endmenu
10+
11+
menu "Sample configuration"
12+
13+
choice BATTERY_MODEL
14+
prompt "Initial battery model"
15+
default BATTERY_MODEL_ALKALINE_AA
16+
help
17+
Select the initial battery model to use.
18+
The battery model can be changed at runtime using shell commands.
19+
20+
config BATTERY_MODEL_ALKALINE_AA
21+
bool "Alkaline AA"
22+
help
23+
Alkaline AA cylindrical battery.
24+
25+
config BATTERY_MODEL_ALKALINE_AAA
26+
bool "Alkaline AAA"
27+
help
28+
Alkaline AAA cylindrical battery.
29+
30+
config BATTERY_MODEL_ALKALINE_LR44
31+
bool "Alkaline LR44"
32+
help
33+
Alkaline LR44 coin cell battery.
34+
35+
config BATTERY_MODEL_LITHIUM_CR2032
36+
bool "Lithium CR2032"
37+
help
38+
Lithium-manganese dioxide CR2032 coin cell battery.
39+
40+
endchoice
41+
42+
endmenu
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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 the `nPM2100 <nPM2100 product website_>`_ and the :ref:`nrfxlib:nrf_fuel_gauge`.
11+
12+
Requirements
13+
************
14+
15+
The sample supports the following development kits:
16+
17+
.. table-from-sample-yaml::
18+
19+
The sample also requires an nPM2100 evaluation kit that you need to connect to the development kit as described in `Wiring`_.
20+
21+
Overview
22+
********
23+
24+
This sample allows the calculation of state of charge from a battery connected to the nPM2100 PMIC.
25+
26+
Battery models for Alkaline AA, AAA, LR44, and Lithium-manganese dioxide coin cell CR2032 batteries are included.
27+
You can change the active battery model using a shell command, as illustrated in `Testing`_.
28+
You can also change the battery model at compile time using the :kconfig:option:`CONFIG_BATTERY_MODEL` Kconfig option.
29+
30+
Wiring
31+
******
32+
33+
With this configuration, the nPM2100 EK is wired to supply power to the DK.
34+
This ensures that the TWI communication is at compatible voltage levels, and represents a realistic use case for the nPM2100 PMIC.
35+
36+
.. note::
37+
38+
To prevent leakage currents and program the DK, do not remove the USB connection.
39+
40+
Unplug the battery from the nPM2100 EK and set the DK power switch to "OFF" while applying the wiring described below.
41+
If you have issues communicating with the DK or programming it after applying the wiring, try to power cycle the DK and EK.
42+
43+
To connect your DK to the nPM2100 EK, complete the following steps:
44+
45+
#. Prepare the DK for being powered by the nPM2100 EK:
46+
47+
.. tabs::
48+
49+
.. group-tab:: nRF52840 and nRF5340 DKs
50+
51+
* Set switch **SW9** ("nRF power source") to position "VDD".
52+
* Set switch **SW10** ("VEXT -> VnRF") to position "ON".
53+
54+
.. group-tab:: nRF54L15 DK
55+
56+
* Remove jumper from **P6** ("VDDM CURRENT MEASURE").
57+
58+
#. Connect the TWI interface and power supply between the chosen DK and the nPM2100 EK as described in the following table:
59+
60+
.. list-table:: nPM2100 EK connections.
61+
:widths: auto
62+
:header-rows: 1
63+
64+
* - nPM2100 EK pins
65+
- nRF52840 DK pins
66+
- nRF5340 DK pins
67+
- nRF54L15 DK pins
68+
* - SDA
69+
- P0.26
70+
- P1.02
71+
- P1.11
72+
* - SCL
73+
- P0.27
74+
- P1.03
75+
- P1.12
76+
* - VOUT
77+
- P21 External supply
78+
- P21 External supply
79+
- P6 VDDM current measure, VDD:nRF pin
80+
* - GND
81+
- GND
82+
- GND
83+
- GND
84+
85+
#. Make the following connections on the nPM2100 EK:
86+
87+
* Remove the USB power supply from the **J4** connector.
88+
* On the **P6** pin header, connect pins 1 and 2 with a jumper.
89+
* On the **BOOTMON** pin header, select **OFF** with a jumper.
90+
* On the **VSET** pin header, select **3.0V** with a jumper.
91+
* On the **VBAT SEL** switch, select **VBAT** position.
92+
* Connect a battery board to the **BATTERY INPUT** connector.
93+
94+
Building and running
95+
********************
96+
97+
.. |sample path| replace:: :file:`samples/pmic/native/npm2100_fuel_gauge`
98+
99+
.. include:: /includes/build_and_run.txt
100+
101+
102+
Testing
103+
*******
104+
105+
|test_sample|
106+
107+
#. |connect_kit|
108+
#. |connect_terminal|
109+
110+
If the initialization was successful, the terminal displays the following message with status information:
111+
112+
.. code-block:: console
113+
114+
PMIC device ok
115+
nRF Fuel Gauge version: 1.0.0
116+
Fuel gauge initialised for Alkaline AA battery.
117+
V: 1.188, T: 20.62, SoC: 25.00
118+
119+
.. _table::
120+
:widths: auto
121+
122+
====== =============== ==================================================
123+
Symbol Description Units
124+
====== =============== ==================================================
125+
V Battery voltage Volts
126+
T Temperature Degrees C
127+
SoC State of Charge Percent
128+
====== =============== ==================================================
129+
130+
Determine the active battery type using the following shell command:
131+
132+
.. code-block:: console
133+
134+
$ battery_model
135+
Battery model: Alkaline AA
136+
137+
Use the same shell command to change the active battery type:
138+
139+
.. code-block:: console
140+
141+
$ battery_model Lithium_CR2032
142+
Fuel gauge initialised for Lithium CR2032 battery.
143+
144+
Dependencies
145+
************
146+
147+
The sample uses the following `sdk-nrfxlib`_ library:
148+
149+
* :ref:`nrfxlib:nrf_fuel_gauge`
150+
151+
In addition, it uses the following Zephyr libraries:
152+
153+
* :ref:`zephyr:logging_api`
154+
* :ref:`zephyr:shell_api`
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
npm2100ek_pmic: pmic@74 {
10+
compatible = "nordic,npm2100";
11+
reg = <0x74>;
12+
13+
npm2100ek_gpio: gpio-controller {
14+
compatible = "nordic,npm2100-gpio";
15+
gpio-controller;
16+
#gpio-cells = <2>;
17+
ngpios = <2>;
18+
};
19+
20+
npm2100ek_regulators: regulators {
21+
compatible = "nordic,npm2100-regulator";
22+
23+
/* limits are set to min/max allowed values */
24+
npm2100ek_boost: BOOST {
25+
regulator-min-microvolt = <1800000>;
26+
regulator-max-microvolt = <3300000>;
27+
regulator-init-microamp = <0>;
28+
};
29+
30+
npm2100ek_ldosw: LDOSW {
31+
regulator-min-microvolt = <800000>;
32+
regulator-max-microvolt = <3000000>;
33+
};
34+
};
35+
36+
npm2100ek_wdt: watchdog {
37+
compatible = "nordic,npm2100-wdt";
38+
};
39+
40+
npm2100ek_vbat: vbat {
41+
compatible = "nordic,npm2100-vbat";
42+
};
43+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&i2c0_default {
8+
group1 {
9+
bias-pull-up;
10+
};
11+
};
12+
13+
&arduino_i2c {
14+
#include "npm2100ek_pmic.dtsi"
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&i2c1_default {
8+
group1 {
9+
bias-pull-up;
10+
};
11+
};
12+
13+
&arduino_i2c {
14+
#include "npm2100ek_pmic.dtsi"
15+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
&pinctrl {
8+
i2c21_default_alt: i2c21_default_alt {
9+
group1 {
10+
psels = <NRF_PSEL(TWIM_SDA, 1, 11)>,
11+
<NRF_PSEL(TWIM_SCL, 1, 12)>;
12+
bias-pull-up;
13+
};
14+
};
15+
16+
i2c21_sleep_alt: i2c21_sleep_alt {
17+
group1 {
18+
psels = <NRF_PSEL(TWIM_SDA, 1, 11)>,
19+
<NRF_PSEL(TWIM_SCL, 1, 12)>;
20+
low-power-enable;
21+
};
22+
};
23+
};
24+
25+
&i2c21 {
26+
status = "okay";
27+
pinctrl-0 = <&i2c21_default_alt>;
28+
pinctrl-1 = <&i2c21_sleep_alt>;
29+
pinctrl-names = "default", "sleep";
30+
31+
#include "npm2100ek_pmic.dtsi"
32+
};
Lines changed: 13 additions & 0 deletions
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

0 commit comments

Comments
 (0)