Intermediate
30 min

Create a battery monitor with MAX17262 and STM32F302VC

Real-time battery management

BATT-MON 2 Click with CLICKER 4 for STM32F302VCT6

Published Jul 22, 2025

Click board™

BATT-MON 2 Click

Dev. board

CLICKER 4 for STM32F302VCT6

Compiler

NECTO Studio

MCU

STM32F302VC

Monitors the state and health of your single-cell battery

A

A

Hardware Overview

How does it work?

BATT-MON 2 Click is based on the MAX17262, an ultra-low power fuel-gauge IC that implements the ModelGauge™ m5 algorithm from Analog Devices. It provides, at the same time, tolerance against battery diversity for most lithium batteries (providing good performance for most cell types) and applications. The MAX17262 features internal current measurement for up to 3.1A pulse currents and accurately measures voltage, current, and temperature to produce fuel gauge results. It shows the best performance for batteries with 100mAhr to 6Ahr capacity. The ModelGauge™ m5 EZ algorithm combines a Coulomb counter's short-term accuracy and linearity with the long-term stability of a voltage-based fuel gauge, along with temperature compensation, to provide industry-leading fuel-gauge accuracy. 

The MAX17262 automatically compensates for cell aging, temperature, and discharge rate, providing accurate state-of-charge in percentage (%) and remaining capacity in milliampere-hours (mAh) over a wide range of operating conditions. As the battery approaches the critical region near empty, the ModelGauge™ m5 algorithm invokes a unique correction mechanism that eliminates errors. The MAX17262 accurately estimates time-to-empty and time-to-full through three methods for reporting the battery age: reduction in capacity, increase in battery resistance and cycle odometer. BATT-MON 2 Click communicates with MCU using the standard I2C 2-Wire interface to read data and configure settings with a maximum frequency of 400kHz. An alert/interrupt function is also available that outputs an interrupt signal

to the ALR pin of the mikroBUS™ socket, indicating fuel-gauge alerts. This feature is visually presented by a red LED marked as ALR. Besides, this Click board™ also features battery pack temperature sensing through an integrated temperature sensor or an external NTC thermistor which can be connected to the onboard terminal labeled TH. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VIO SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. However, the 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.

batt-mon_2_click_hardware_overview

Features overview

Development board

Clicker 4 for STM32F3 is a compact development board designed as a complete solution, you can use it to quickly build your own gadgets with unique functionalities. Featuring a STM32F302VCT6, four mikroBUS™ sockets for Click boards™ connectivity, power managment, and more, it represents a perfect solution for the rapid development of many different types of applications. At its core, there is a STM32F302VCT6 MCU, a powerful microcontroller by STMicroelectronics, based on the high-

performance Arm® Cortex®-M4 32-bit processor core operating at up to 168 MHz frequency. It provides sufficient processing power for the most demanding tasks, allowing Clicker 4 to adapt to any specific application requirements. Besides two 1x20 pin headers, four improved mikroBUS™ sockets represent the most distinctive connectivity feature, allowing access to a huge base of Click boards™, growing on a daily basis. Each section of Clicker 4 is clearly marked, offering an intuitive and clean interface. This makes working with the development

board much simpler and thus, faster. The usability of Clicker 4 doesn’t end with its ability to accelerate the prototyping and application development stages: it is designed as a complete solution which can be implemented directly into any project, with no additional hardware modifications required. Four mounting holes [4.2mm/0.165”] at all four corners allow simple installation by using mounting screws. For most applications, a nice stylish casing is all that is needed to turn the Clicker 4 development board into a fully functional, custom design.

CLICKER 4 for STM32F302VCT6 double image

Microcontroller Overview

MCU Card / MCU

STM32F302VC Image

Architecture

ARM Cortex-M4

MCU Memory (KB)

256

Silicon Vendor

STMicroelectronics

Pin count

100

RAM (Bytes)

40960

You complete me!

Accessories

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. You can find a more extensive choice of Li-Polymer batteries in our offer.

BATT-MON 2 Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Alert
PD0
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PB10
SCL
I2C Data
PB11
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

BATT-MON 2 Click Schematic schematic

Step by step

Project assembly

PIC32MZ MXS Data Capture Board front image hardware assembly

Start by selecting your development board and Click board™. Begin with the CLICKER 4 for STM32F302VCT6 as your development board.

PIC32MZ MXS Data Capture Board front image hardware assembly
Thermo 21 Click front image hardware assembly
Thermo 21 Click complete accessories setup image hardware assembly
Board mapper by product6 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
PIC32MZ MXS Data Capture Board NECTO MCU Selection Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto image step 11 hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for BATT-MON 2 Click driver.

Key functions:

  • battmon2_get_battery_voltage This function reads the battery voltage in mV.

  • battmon2_get_battery_current This function reads the battery current in mA.

  • battmon2_get_battery_percentage This function reads the battery's remaining SOC percentage.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * @file main.c
 * @brief BATTMON2 Click example
 *
 * # Description
 * This example demonstrates the use of BATT-MON 2 Click board by monitoring
 * the measurements of battery voltage, current, capacity, percentage, time-to-empty or time-to-full,
 * as well as the chip internal temperature.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and checks the communication by reading and verifying the device ID.
 *
 * ## Application Task
 * Reads and displays on the USB UART the measurements of battery voltage, current, capacity, percentage, 
 * time-to-empty or time-to-full, as well as the chip internal temperature approximately once per second.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "battmon2.h"

static battmon2_t battmon2;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    battmon2_cfg_t battmon2_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.
    battmon2_cfg_setup( &battmon2_cfg );
    BATTMON2_MAP_MIKROBUS( battmon2_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == battmon2_init( &battmon2, &battmon2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( BATTMON2_ERROR == battmon2_check_communication ( &battmon2 ) )
    {
        log_error( &logger, " Check communication." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float voltage, capacity, percentage, current, die_temp;
    if ( BATTMON2_OK == battmon2_get_battery_voltage ( &battmon2, &voltage ) )
    {
        log_printf ( &logger, " Voltage: %.1f mV \r\n", voltage );
    }
    if ( BATTMON2_OK == battmon2_get_battery_current ( &battmon2, &current ) )
    {
        log_printf ( &logger, " Current: %.1f mA \r\n", current );
    }
    if ( BATTMON2_OK == battmon2_get_battery_capacity ( &battmon2, &capacity ) )
    {
        log_printf ( &logger, " Capacity: %.1f mAh \r\n", capacity );
    }
    if ( BATTMON2_OK == battmon2_get_battery_percentage ( &battmon2, &percentage ) )
    {
        log_printf ( &logger, " Percentage: %.1f %% \r\n", percentage );
    }
    if ( current > 0 )
    {
        uint32_t time_to_full;
        if ( BATTMON2_OK == battmon2_get_battery_ttf ( &battmon2, &time_to_full ) )
        {
            log_printf ( &logger, " Time to full: %uh %umin %usec \r\n", ( uint16_t ) ( time_to_full / 3600 ), 
                                                                         ( uint16_t ) ( time_to_full % 3600 ) / 60,
                                                                         ( uint16_t ) ( time_to_full % 60 ) );
        }
    }
    else if ( current < 0 )
    {
        uint32_t time_to_empty;
        if ( BATTMON2_OK == battmon2_get_battery_tte ( &battmon2, &time_to_empty ) )
        {
            log_printf ( &logger, " Time to empty: %uh %umin %usec \r\n", ( uint16_t ) ( time_to_empty / 3600 ), 
                                                                          ( uint16_t ) ( time_to_empty % 3600 ) / 60,
                                                                          ( uint16_t ) ( time_to_empty % 60 ) );
        }
    }
    if ( BATTMON2_OK == battmon2_get_die_temperature ( &battmon2, &die_temp ) )
    {
        log_printf ( &logger, " Internal temperature: %.2f C \r\n\n", die_temp );
    }
    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;
}

// ------------------------------------------------------------------------ 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.