tick_basse_conso.c
The battery sensor pattern: the board sleeps 30 seconds, wakes, blinks 1 ms, sleeps again. Between wakeups the CPU idles and PM powers down drivers — the base of multi-month coin-cell runtimes.
Hardware
An nRF52833-DK board (Nordic, nRF52833 Cortex-M4F SoC, BLE 5) powered over USB: 4 LEDs on P0.13-P0.16 (active-low) and 4 buttons on P0.11, P0.12, P0.24, P0.25 (active-low, internal pull-up must be enabled). The board on a battery (the MDK has no charger: plan a regulator or LiPo on pads) and ideally a micro-ammeter.
Wiring
No wiring for the test. In the field, power through the VDD pad and measure in series with a PPK2 or nano-ammeter.
How it works
k_sleep(K_SECONDS(30)) parks the core in deep idle (WFI); only the RTC counts time. The LED lights for one millisecond only, keeping energy per cycle negligible.
Running it
Zephyr project: west build -b nrf52833dk/nrf52833 then west flash (on-board J-Link); 115200 serial console on the USB UART connector.
Variants
Wake on GPIO (button, sensor alarm) instead of timer, batch measurements into one BLE burst, or gate unused clock domains.
tick_basse_conso.c
/* Battement basse consommation : réveil toutes les 30 s.
* Kconfig : CONFIG_PM=y, CONFIG_PM_DEVICE=y pour éteindre les
* pilotes inutilisés ; le CPU dort en idle entre deux réveils.
* À mesurer avec un PPK2 : l'éclair LED doit durer < 1 ms. */
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
static const struct gpio_dt_spec led =
GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
int main(void)
{
gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);
while (1) {
/* k_sleep = System ON idle : le noyau WFI, seule
l'horloge temps réel reste armée. */
k_sleep(K_SECONDS(30));
/* Signal visuel bref : 1 flash = un cycle de 30 s */
gpio_pin_set_dt(&led, 1);
k_msleep(1);
gpio_pin_set_dt(&led, 0);
/* Ici : lecture capteur + envoi BLE, puis redormir */
}
return 0;
}