Skip to content

Commit 05c7fad

Browse files
seov-nordickartben
authored andcommitted
samples: shields: npm2100_ek sample
A sample show-casing the core functionalities of the nPM2100 PMIC using the nPM2100 EK as a shield. Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
1 parent a5fdddf commit 05c7fad

File tree

9 files changed

+310
-2
lines changed

9 files changed

+310
-2
lines changed

boards/shields/npm2100_ek/npm2100_ek.overlay

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343

4444
npm2100_buttons: buttons {
4545
compatible = "gpio-keys";
46+
4647
pmic_button0: pmic_button_0 {
47-
gpios = < &npm2100_gpio 0 GPIO_ACTIVE_LOW>;
48+
gpios = <&npm2100_gpio 0 GPIO_ACTIVE_LOW>;
4849
label = "Pmic button switch 0";
4950
zephyr,code = <INPUT_KEY_0>;
5051
};
52+
5153
pmic_button1: pmic_button_1 {
52-
gpios = < &npm2100_gpio 1 GPIO_ACTIVE_LOW>;
54+
gpios = <&npm2100_gpio 1 GPIO_ACTIVE_LOW>;
5355
label = "Pmic button switch 1";
5456
zephyr,code = <INPUT_KEY_1>;
5557
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
set(SHIELD npm2100_ek)
7+
set(EXTRA_DTC_OVERLAY_FILE npm2100_ek_buttons.overlay)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
11+
project(npm2100_ek)
12+
target_sources(app PRIVATE src/main.c)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (C) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
&i2c0_default {
7+
group1 {
8+
bias-pull-up;
9+
};
10+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright (C) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
&i2c1_default {
7+
group1 {
8+
bias-pull-up;
9+
};
10+
};
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
.. zephyr:code-sample:: npm2100_ek
2+
:name: nPM2100 EK
3+
4+
Interact with the nPM2100 PMIC using the EK buttons and the shell interface.
5+
6+
Overview
7+
********
8+
9+
This sample is provided for evaluation of the :ref:`npm2100_ek`.
10+
It is an example of how the nPM2100 GPIO pins and the shell
11+
interface can be used to control the following features:
12+
13+
- Regulators (BOOST, LDOSW)
14+
- GPIO
15+
16+
Requirements
17+
************
18+
19+
The sample supports the following boards: :zephyr:board:`nrf52840dk`, :zephyr:board:`nrf5340dk`
20+
21+
The sample also requires an nPM2100 Evaluation Kit (EK) that you need to connect to the
22+
development kit as described in `Wiring`_.
23+
24+
Wiring
25+
******
26+
27+
With this configuration, the nPM2100 EK is wired to supply power to the DK.
28+
This ensures that the TWI communication is at compatible voltage level, and represents a realistic use case for the nPM2100 PMIC.
29+
30+
.. note::
31+
32+
To prevent leakage currents and program the DK, do not remove the USB connection.
33+
34+
Unplug the battery from the nPM2100 EK and set the DK power switch to "OFF" while
35+
applying the wiring.
36+
If you have issues communicating with the DK or programming it after applying the wiring, try to power cycle the DK and EK.
37+
38+
To connect your DK to the nPM2100 EK, complete the following steps:
39+
40+
#. Prepare the DK for being powered by the nPM2100 EK:
41+
42+
- Set switch **SW9** ("nRF power source") to position "VDD".
43+
- Set switch **SW10** ("VEXT -> VnRF") to position "ON".
44+
45+
#. Connect the TWI interface and power supply between the chosen DK and the nPM2100 EK
46+
as described in the following table:
47+
48+
+------------------+-------+-------+-----------------------+-----+
49+
| nPM2100 EK pins | SDA | SCL | VOUT | GND |
50+
+------------------+-------+-------+-----------------------+-----+
51+
| nRF52840 DK pins | P0.26 | P0.27 | P21 External supply + | GND |
52+
+------------------+-------+-------+-----------------------+-----+
53+
| nRF5340 DK pins | P1.02 | P1.03 | P21 External supply + | GND |
54+
+------------------+-------+-------+-----------------------+-----+
55+
56+
#. Make the following connections on the nPM2100 EK:
57+
58+
- Remove the USB power supply from the **J4** connector.
59+
- On the **P6** pin header, connect pins 1 and 2 with a jumper.
60+
- On the **BOOTMON** pin header, select **OFF** with a jumper.
61+
- On the **VSET** pin header, select **3.0V** with a jumper.
62+
- On the **VBAT SEL** switch, select **VBAT** position.
63+
- Connect a battery board to the **BATTERY INPUT** connector.
64+
65+
Building and Running
66+
********************
67+
68+
To build the sample use the following command:
69+
70+
.. zephyr-app-commands::
71+
:zephyr-app: samples/shields/npm2100_ek
72+
:board: nrf52840dk/nrf52840
73+
:goals: build
74+
:compact:
75+
76+
.. note::
77+
This sample automatically sets the ``SHIELD`` to ``npm2100_ek``.
78+
Once you have flashed the software to your device, boot into the shell interface.
79+
Use the ``regulator`` command to test the PMIC.
80+
See the following section for details on the subcommands.
81+
82+
Regulator control
83+
*****************
84+
85+
If the initialization was successful, the terminal displays the following message
86+
with status information:
87+
88+
.. code-block:: console
89+
90+
PMIC device ok
91+
92+
The sample also reports the battery and boost output voltages as well as the die
93+
temperature measured every two seconds.
94+
95+
Use the buttons on the EK to control the regulators as follows:
96+
97+
+---------------------------+----------------------------------+
98+
| Operation | Outcome |
99+
+---------------------------+----------------------------------+
100+
| Button **GPIO0** pressed | BOOST output forced into HP mode |
101+
+---------------------------+----------------------------------+
102+
| Button **GPIO0** released | BOOST output operates in LP mode |
103+
+---------------------------+----------------------------------+
104+
| Button **GPIO1** pressed | Load Switch on |
105+
+---------------------------+----------------------------------+
106+
| Button **GPIO1** released | Load Switch off |
107+
+---------------------------+----------------------------------+
108+
109+
The ``regulator`` shell interface provides several subcommand to test
110+
the regulators embedded in the PMIC.
111+
112+
To list all supported voltages for a regulator, run the following command:
113+
114+
.. code-block:: console
115+
116+
uart:~$ regulator vlist BOOST
117+
1.800000 V
118+
1.850000 V
119+
...
120+
121+
To enable or disable a regulator, run the following commands:
122+
123+
.. code-block:: console
124+
125+
uart:~$ regulator enable LDOSW
126+
uart:~$ regulator disable LDOSW
127+
128+
.. note::
129+
The BOOST regulator is always enabled.
130+
131+
To set the output voltage of a regulator, run the following command:
132+
133+
.. code-block:: console
134+
135+
uart:~$ regulator vset BOOST 2.5v
136+
uart:~$ regulator vget BOOST
137+
2.500000 V
138+
139+
.. note::
140+
The BOOST regulator cannot provide a voltage lower than the battery voltage.
141+
142+
To get the GPIO status, run the following command:
143+
144+
.. code-block:: console
145+
146+
uart:~$ gpio get npm2100_gpio 0
147+
0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (C) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/* Set GPIO pins as inputs controlling features of the respective regulators */
7+
8+
&npm2100_boost {
9+
mode-gpios = <&npm2100_gpio 0 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
10+
};
11+
12+
&npm2100_ldosw {
13+
mode-gpios = <&npm2100_gpio 1 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
14+
};

samples/shields/npm2100_ek/prj.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_SHELL=y
5+
CONFIG_LOG=y
6+
CONFIG_LOG_CMDS=y
7+
CONFIG_GPIO=y
8+
CONFIG_GPIO_SHELL=y
9+
CONFIG_REGULATOR=y
10+
CONFIG_REGULATOR_SHELL=y
11+
CONFIG_WATCHDOG=y
12+
CONFIG_WDT_SHELL=y
13+
CONFIG_SENSOR=y
14+
CONFIG_SENSOR_SHELL=y
15+
CONFIG_I2C=y
16+
CONFIG_I2C_SHELL=y
17+
CONFIG_I2C_LOG_LEVEL_WRN=y
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: Apache-2.0
3+
4+
sample:
5+
name: nPM2100 EK
6+
tests:
7+
sample.shields.npm2100_ek:
8+
harness: shield
9+
tags: shield
10+
depends_on: arduino_i2c

samples/shields/npm2100_ek/src/main.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/device.h>
7+
#include <zephyr/drivers/gpio.h>
8+
#include <zephyr/drivers/regulator.h>
9+
#include <zephyr/drivers/sensor.h>
10+
#include <zephyr/dt-bindings/regulator/npm2100.h>
11+
12+
#define UPDATE_TIME_MS 2000
13+
14+
static const struct device *boost = DEVICE_DT_GET(DT_NODELABEL(npm2100_boost));
15+
static const struct device *ldosw = DEVICE_DT_GET(DT_NODELABEL(npm2100_ldosw));
16+
static const struct device *vbat = DEVICE_DT_GET(DT_NODELABEL(npm2100_vbat));
17+
18+
int setup_regulators(void)
19+
{
20+
int err;
21+
22+
/* boost to operate in Low Power mode by default, force High Power on GPIO0 active */
23+
err = regulator_set_mode(boost, NPM2100_REG_OPER_LP | NPM2100_REG_FORCE_HP);
24+
if (err != 0) {
25+
return err;
26+
}
27+
28+
/* LDOSW to operate as a Load Switch: off by default, on when GPIO1 active */
29+
err = regulator_set_mode(ldosw,
30+
NPM2100_REG_OPER_OFF | NPM2100_REG_FORCE_HP | NPM2100_REG_LDSW_EN);
31+
if (err != 0) {
32+
return err;
33+
}
34+
35+
return regulator_enable(ldosw);
36+
}
37+
38+
void display_sensor_values(void)
39+
{
40+
struct sensor_value v_battery;
41+
struct sensor_value v_out;
42+
struct sensor_value temp;
43+
44+
sensor_sample_fetch(vbat);
45+
sensor_channel_get(vbat, SENSOR_CHAN_GAUGE_VOLTAGE, &v_battery);
46+
sensor_channel_get(vbat, SENSOR_CHAN_VOLTAGE, &v_out);
47+
sensor_channel_get(vbat, SENSOR_CHAN_DIE_TEMP, &temp);
48+
49+
printk("VBat: %d.%03d ", v_battery.val1, v_battery.val2 / 1000);
50+
printk("VOut: %d.%03d ", v_out.val1, v_out.val2 / 1000);
51+
printk("T: %s%d.%02d\n", ((temp.val1 < 0) || (temp.val2 < 0)) ? "-" : "", abs(temp.val1),
52+
abs(temp.val2) / 10000);
53+
}
54+
55+
int main(void)
56+
{
57+
int err;
58+
59+
if (!device_is_ready(ldosw)) {
60+
printk("Error: LDOSW device is not ready\n");
61+
return -ENODEV;
62+
}
63+
64+
if (!device_is_ready(boost)) {
65+
printk("Error: BOOST device is not ready\n");
66+
return -ENODEV;
67+
}
68+
69+
if (!device_is_ready(vbat)) {
70+
printk("Error: vbat device is not ready\n");
71+
return -ENODEV;
72+
}
73+
74+
err = setup_regulators();
75+
if (err != 0) {
76+
printk("Error: failed to set regulator modes\n");
77+
return err;
78+
}
79+
80+
printk("PMIC device ok\n");
81+
82+
while (1) {
83+
display_sensor_values();
84+
k_msleep(UPDATE_TIME_MS);
85+
}
86+
}

0 commit comments

Comments
 (0)