Beginner
10 min

Provide essential functions for charging and managing battery power in electronic devices with nPM1300 and STM32F031K6

Advanced Power Management Integrated Circuit (PMIC) for rechargeable applications

PMIC Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

PMIC Click

Dev Board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Optimize battery life and performance in IoT applications and other portable electronics ensuring longer operation times

A

A

Hardware Overview

How does it work?

PMIC Click is based on the nPM1300, an advanced Power Management Integrated Circuit (PMIC) from Nordic Semiconductor designed for rechargeable applications. The nPM1300 integrates a variety of power and system management functionalities, offering a compact and efficient solution for managing power in devices. It supports battery charging for lithium-ion (Li-ion), lithium-polymer (Li-poly), and lithium iron phosphate (LiFePO4) batteries, using a flexible power regulation system. Housed in a space-saving QFN32 package, the nPM1300 is made for high efficiency and is fully configurable via an I2C interface, making it ideal for wearables, peripherals, asset tracking, interactive entertainment, IoT applications, and much more. The nPM1300 features an integrated 800mA linear battery charger that ensures safe and efficient charging by adhering to the JEITA standards, which adjusts the charging process based on temperature to protect the battery and extend its lifespan. A battery can be connected to a connector in the upper right corner that supports the integration of an NTC thermistor for precise battery temperature monitoring. If the used battery pack already includes an NTC, the NTC terminal on the BATTERY connector can be left unconnected. For scenarios where a battery without an NTC thermistor is used, the board provides options to bypass this requirement by using onboard resistors. An integrated 10K resistor is available by default, or you can customize the value via an empty resistor footprint (R7 0603) to match specific needs. This feature can be selected via an onboard NTC Bypass jumper. Besides the battery charger, the nPM1300 also integrates two 200mA buck regulators and two 100mA load switches or 50mA Low Dropout Regulators (LDOs). These load switches offer flexibility in managing power distribution across your device. Control of these load switches is achieved through I2C registers or GPIO pins, providing flexibility to tailor the power

configuration to your application's requirements. A notable feature is the ability to select the input source for a second load switch via the LSIN2 jumper, allowing you to choose between the output voltage of one of the buck regulators (VOUT1 or VOUT2). The regulated outputs, VOUT1 and VOUT2, are currently configured to output 1.8V, and VOUT2 is set to 3.3V. These configurations are achieved through specific resistor settings - R8 for VOUT1 and R9 for VOUT2, where VOUT1 can be adjusted within a range of 0V to 2.7V, while VOUT2 from 0V to 3.3V, depending on the selected resistor values. Unregulated output VBUSOUT is directly tied to the VBUS input, offering an unregulated power source that can be used for additional system needs, while VSYS serves as another unregulated output derived from the system's overall power supply. The primary power supply for the nPM1300 PMIC is provided by the VBUS connection, which is a dedicated USB Type-C input. Alongside VBUS, the complementary power supply is VBAT, which also acts as the output for the battery charger, ensuring that the connected battery is charged while maintaining a stable power supply to the system. In addition, the nPM1300 also enhances system reliability with a watchdog that resets the system if it becomes unresponsive, failed-boot recovery for system integrity, and an intelligent power-loss warning to prevent data loss or failure. PMIC Click uses a standard 2-wire I2C interface for communication with the host MCU, supporting a clock frequency of up to 400kHz in Standard mode. Besides interface pins, the board also features an interrupt (INT) pin providing real-time alerts to the host system for immediate action. To manage the power states, PMIC Click includes a SHPHLD button to exit Ship and Hibernation mode - two of the lowest quiescent current states available. These modes disconnect the battery from the system, reducing the quiescent current to extend the battery life. Hibernate mode, in

particular, can be used during normal operation, as the device can automatically wake up after a preconfigured timeout, maximizing battery efficiency. The SHPHLD button also allows users to reset or power cycle the nPM1300. For additional control, the board is equipped with a GPIO0 button, which directly manages the nPM1300's GPIO0 pin. Three LED indicators provide visual feedback: a red ERR LED that signals errors during operation, a green CHG LED that indicates the charging status, and a yellow HOST LED that shows host activity. These LEDs offer clear and immediate visual cues, making monitoring the board's status and troubleshooting any issues easier. Two headers, J1 and J2, provide easy access to power and control functions. The J1 header grants access to the PMIC's voltage outputs, VOUT1 and VOUT2, as well as the USB VBUS voltage through the VBUS pin and VBUSOUT from the nPM1300, allowing you to power external devices directly from the main IC. The J2 header serves multiple purposes, primarily enabling connections to PMIC GPIO pins located in the right column. These GPIOs, configured as inputs with weak pull-downs by default, can be used for custom workflows, standard GPIO functions, or as control pins for the board's buck regulators and load switches. Additionally, the J2 header supports connections for external LEDs and includes the previously mentioned VSYS pin, a system voltage output. This Click board™ can operate with either 3.3V or 3.3V provided from VOUT2 regulated PMIC output selected via the VDDIO SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.

PMIC Click hardware overview image

Features overview

Development board

Nucleo 32 with STM32F031K6 MCU board provides an affordable and flexible platform for experimenting with STM32 microcontrollers in 32-pin packages. Featuring Arduino™ Nano connectivity, it allows easy expansion with specialized shields, while being mbed-enabled for seamless integration with online resources. The

board includes an on-board ST-LINK/V2-1 debugger/programmer, supporting USB reenumeration with three interfaces: Virtual Com port, mass storage, and debug port. It offers a flexible power supply through either USB VBUS or an external source. Additionally, it includes three LEDs (LD1 for USB communication, LD2 for power,

and LD3 as a user LED) and a reset push button. The STM32 Nucleo-32 board is supported by various Integrated Development Environments (IDEs) such as IAR™, Keil®, and GCC-based IDEs like AC6 SW4STM32, making it a versatile tool for developers.

Nucleo 32 with STM32F031K6 MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

32

RAM (Bytes)

4096

You complete me!

Accessories

Click Shield for Nucleo-32 is the perfect way to expand your development board's functionalities with STM32 Nucleo-32 pinout. The Click Shield for Nucleo-32 provides two mikroBUS™ sockets to add any functionality from our ever-growing range of Click boards™. We are fully stocked with everything, from sensors and WiFi transceivers to motor control and audio amplifiers. The Click Shield for Nucleo-32 is compatible with the STM32 Nucleo-32 board, providing an affordable and flexible way for users to try out new ideas and quickly create prototypes with any STM32 microcontrollers, choosing from the various combinations of performance, power consumption, and features. The STM32 Nucleo-32 boards do not require any separate probe as they integrate the ST-LINK/V2-1 debugger/programmer and come with the STM32 comprehensive software HAL library and various packaged software examples. This development platform provides users with an effortless and common way to combine the STM32 Nucleo-32 footprint compatible board with their favorite Click boards™ in their upcoming projects.

Click Shield for Nucleo-32 accessories 1 image

Li-Polymer Battery is the ideal solution for devices that demand a dependable and long-lasting power supply while emphasizing mobility. Its compatibility with mikromedia boards ensures easy integration without additional modifications. With a voltage output of 3.7V, the battery meets the standard requirements of many electronic devices. Additionally, boasting a capacity of 2000mAh, it can store a substantial amount of energy, providing sustained power for extended periods. This feature minimizes the need for frequent recharging or replacement. Overall, the Li-Polymer Battery is a reliable and autonomous power source, ideally suited for devices requiring a stable and enduring energy solution.

PMIC Click accessories 2 image

This is a USB 3.1 cable with USB Type C male connectors on both sides. Cable comes with USB Type C Female to USB Type A Male adapter, making it compabitle with USB 2.0 and USB 3.0 host slots as well. Cable is 1.5 meters long and compatible with any USB type C development tools.

PMIC Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
ID COMM
PA4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PA12
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB6
SCL
I2C Data
PB7
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Schematic

PMIC Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 32 with STM32F031K6 MCU as your development board.

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Stepper 22 Click complete accessories setup image hardware assembly
Nucleo-32 with STM32 MCU Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
STM32 M4 Clicker HA MCU/Select Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for PMIC Click driver.

Key functions:

  • pmic_get_vbat - This function reads the VBAT measurement results in millivolts.

  • pmic_get_vbus - This function reads the VBUS measurement results in millivolts.

  • pmic_get_vsys - This function reads the VSYS measurement results in millivolts.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief PMIC Click example
 *
 * # Description
 * This example demonstrates the use of PMIC click board by enabling battery charging and
 * displaying the charging status.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration which enables charging.
 *
 * ## Application Task
 * Reads and displays the VBAT, VBUS, and VSYS voltage and the battery charging status on the USB UART
 * approximately once per second.
 *
 * @note
 * A charged battery or a USB at VBUS must be connected to communicate with the click board.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "pmic.h"

static pmic_t pmic;
static log_t logger;

/**
 * @brief PMIC display charger status function.
 * @details This function reads and parses the battery charger status register.
 * @param[in] ctx : Click context object.
 * See #pmic_t object definition for detailed explanation.
 * @return None.
 * @note None.
 */
void pmic_display_charger_status ( pmic_t *ctx );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    pmic_cfg_t pmic_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    pmic_cfg_setup( &pmic_cfg );
    PMIC_MAP_MIKROBUS( pmic_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == pmic_init( &pmic, &pmic_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( PMIC_ERROR == pmic_default_cfg ( &pmic ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }

    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    uint16_t vbat = 0, vbus = 0, vsys = 0;
    if ( PMIC_OK == pmic_get_vbat ( &pmic, &vbat ) )
    {
        log_printf( &logger, " VBAT : %u mV\r\n", vbat );
    }
    if ( PMIC_OK == pmic_get_vbus ( &pmic, &vbus ) )
    {
        log_printf( &logger, " VBUS : %u mV\r\n", vbus );
    }
    if ( PMIC_OK == pmic_get_vsys ( &pmic, &vsys ) )
    {
        log_printf( &logger, " VSYS : %u mV\r\n\n", vsys );
    }
    pmic_display_charger_status ( &pmic );
    Delay_ms ( 1000 );
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

void pmic_display_charger_status ( pmic_t *ctx )
{
    uint8_t charge_status = 0;
    if ( PMIC_OK == pmic_reg_read_byte ( &pmic, PMIC_REG_BCHARGER_BCHGCHARGESTATUS, &charge_status ) )
    {
        log_printf( &logger, " --- Battery Charge status ---\r\n" );
        if ( charge_status & PMIC_CHARGE_STATUS_BATTERYDETECTED )
        {
            log_printf( &logger, " Battery is connected\r\n" );
        }
        if ( charge_status & PMIC_CHARGE_STATUS_COMPLETED )
        {
            log_printf( &logger, " Charging completed (Battery Full)\r\n" );
        }
        if ( charge_status & PMIC_CHARGE_STATUS_TRICKLECHARGE )
        {
            log_printf( &logger, " Trickle charge\r\n" );
        }
        if ( charge_status & PMIC_CHARGE_STATUS_CONSTANTCURRENT )
        {
            log_printf( &logger, " Constant Current charging\r\n" );
        }
        if ( charge_status & PMIC_CHARGE_STATUS_CONSTANTVOLTAGE )
        {
            log_printf( &logger, " Constant Voltage charging\r\n" );
        }
        if ( charge_status & PMIC_CHARGE_STATUS_RECHARGE )
        {
            log_printf( &logger, " Battery re-charge is needed\r\n" );
        }
        if ( charge_status & PMIC_CHARGE_STATUS_DIETEMPHIGHCHGPAUSED )
        {
            log_printf( &logger, " Charging stopped due Die Temp high.\r\n" );
        }
        if ( charge_status & PMIC_CHARGE_STATUS_SUPPLEMENTACTIVE )
        {
            log_printf( &logger, " Supplement Mode Active\r\n" );
        }
        log_printf( &logger, " -----------------------------\r\n" );
    }
}
// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.