Intermediate
20 min

Charge single-cell Li-Ion/Polymer batteries with BQ25638 and ATmega328P

Safe, fast, and efficient Li-Ion/Polymer battery charging solution with advanced features

Charger 28 Click with Arduino UNO Rev3

Published May 07, 2025

Click board™

Charger 28 Click

Dev. board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328P

Deliver fast, safe, and intelligent charging for single-cell Li-Ion and Li-Polymer batteries using USB Type-C input

A

A

Hardware Overview

How does it work?

Charger 28 Click is based on the BQ25638, a 5A switch-mode battery charger from Texas Instruments, featuring NVDC (Narrow VDC) power path management designed to provide fast and reliable charging for single-cell Li-Ion and Li-Polymer batteries. This advanced charger architecture allows the system to maintain operation even when the battery is deeply discharged or temporarily removed, making it ideal for applications in gaming and computer accessories where stable power delivery is crucial. Power is supplied to the Charger 28 Click through a USB Type-C connector, providing the necessary input voltage for proper operation. The BQ25638’s integrated Input Current Optimizer (ICO) enables the system to detect and use the maximum available power from the input source without risking overload. Furthermore, it fully supports USB On-the-Go (OTG) specifications, delivering a constant current limit of up to 3.2A, ensuring compatibility with a wide range of modern portable devices. The power path management system maintains the system voltage slightly above the battery voltage but prevents it from dropping below a programmable minimum system voltage. When the input voltage or current limits are reached, it automatically reduces the battery charge current to protect the source. If the system load continues to increase, the battery supplements the system power until the demand is met, effectively preventing input overload and ensuring continuous operation. In addition to the charging input,

Charger 28 Click provides a dedicated battery connector for attaching compatible batteries with voltages up to 4.8V. The middle pin of the battery connector is reserved for connecting an external thermistor if temperature monitoring is required. The BQ25638 operates autonomously to initiate and complete the charging cycle by monitoring the battery voltage and adapting the charging process across four distinct phases: trickle charge, pre-charge, constant current (CC) charge, and constant voltage (CV) charge. Upon completing the charging cycle, the charger terminates the process once the battery voltage exceeds the recharge threshold and the charge current falls below a preset level. Charging termination is supported across various temperature zones, including COOL, PRECOOL, NORMAL, WARM, and PREWARM, ensuring safe and optimized battery management under different conditions. If the battery voltage later drops below the programmed recharge threshold, the charging cycle restarts automatically to maintain optimal battery health. For powering external loads, a LOAD connector is available next to the battery connector, enabling easy connection to the device or system that requires a power supply. Additionally, a VPMID connector is provided, carrying the positive rail of the charger’s output voltage, specifically designed for use in reverse boost mode applications such as power banks, where OTG functionality is required. This Click board™ uses an I2C interface with clock speeds of up to 1MHz, ensuring fast communication with the

host MCU. In addition to the I2C interface pins, Charger 28 Click features CE pin for charging enabling feature, an interrupt (INT) pin to report charger device status and fault to the host MCU, and a RESET button for resitting the charger. The board also features some visual indicators to provide real-time status updates. The STATUS LED reports the charging status and any fault conditions, while the PGOOD LED indicates if a good power source is present and above the programmable threshold. Both of these indicators are also available in digital format through STS and PG pins. The board also features pins routed to a 12-bit analog-to-digital converter (ADC) for monitoring charge current and input/battery/system voltages. The charger provides various safety features for battery charging and system operations, including battery negative temperature coefficient (NTC) thermistor monitoring, charging safety timer and overvoltage and overcurrent protections. The thermal regulation reduces charge current when the junction temperature exceeds the programmable threshold. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC 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.

Charger 28 Click hardware overview image

Features overview

Development board

Arduino UNO is a versatile microcontroller board built around the ATmega328P chip. It offers extensive connectivity options for various projects, featuring 14 digital input/output pins, six of which are PWM-capable, along with six analog inputs. Its core components include a 16MHz ceramic resonator, a USB connection, a power jack, an

ICSP header, and a reset button, providing everything necessary to power and program the board. The Uno is ready to go, whether connected to a computer via USB or powered by an AC-to-DC adapter or battery. As the first USB Arduino board, it serves as the benchmark for the Arduino platform, with "Uno" symbolizing its status as the

first in a series. This name choice, meaning "one" in Italian, commemorates the launch of Arduino Software (IDE) 1.0. Initially introduced alongside version 1.0 of the Arduino Software (IDE), the Uno has since become the foundational model for subsequent Arduino releases, embodying the platform's evolution.

Arduino UNO Rev3 double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

32

Silicon Vendor

Microchip

Pin count

28

RAM (Bytes)

2048

You complete me!

Accessories

Click Shield for Arduino UNO has two proprietary mikroBUS™ sockets, allowing all the Click board™ devices to be interfaced with the Arduino UNO board without effort. The Arduino Uno, a microcontroller board based on the ATmega328P, provides an affordable and flexible way for users to try out new concepts and build prototypes with the ATmega328P microcontroller from various combinations of performance, power consumption, and features. The Arduino Uno has 14 digital input/output pins (of which six can be used as PWM outputs), six analog inputs, a 16 MHz ceramic resonator (CSTCE16M0V53-R0), a USB connection, a power jack, an ICSP header, and reset button. Most of the ATmega328P microcontroller pins are brought to the IO pins on the left and right edge of the board, which are then connected to two existing mikroBUS™ sockets. This Click Shield also has several switches that perform functions such as selecting the logic levels of analog signals on mikroBUS™ sockets and selecting logic voltage levels of the mikroBUS™ sockets themselves. Besides, the user is offered the possibility of using any Click board™ with the help of existing bidirectional level-shifting voltage translators, regardless of whether the Click board™ operates at a 3.3V or 5V logic voltage level. Once you connect the Arduino UNO board with our Click Shield for Arduino UNO, you can access hundreds of Click boards™, working with 3.3V or 5V logic voltage levels.

Click Shield for Arduino UNO 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.

Charger 28 Click accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Power-Good Indicator
PC0
AN
Charger Enable
PD2
RST
ID COMM
PB2
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Charger Status Indicator
PD6
PWM
Interrupt
PC3
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Charger 28 Click Schematic schematic

Step by step

Project assembly

Click Shield for Arduino UNO front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Arduino UNO Rev3 as your development board.

Click Shield for Arduino UNO front image hardware assembly
Arduino UNO Rev3 front image hardware assembly
Charger 27 Click front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Board mapper by product8 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
Arduino UNO MCU 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

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

Charger 28 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.

Example Description
This example demonstrates the use of the Charger 28 Click board by monitoring various parameters of the charging system, such as input voltage (VBUS), battery voltage (VBAT), system voltage (VSYS), charging current (IBAT), and chip temperature (TDIE). Additionally, it reads and interprets the charger status and fault registers to provide detailed status and error feedback during operation.

Key functions:

  • charger28_cfg_setup - Config Object Initialization function.

  • charger28_init - Initialization function.

  • charger28_default_cfg - Click Default Configuration function.

  • charger28_get_vbus - This function reads and calculates the bus voltage in millivolts.

  • charger28_get_ibus - This function reads and calculates the input current in milliamperes.

  • charger28_get_vbat - This function reads and calculates the battery voltage in millivolts.

Application Init
Initializes the driver and performs the default configuration of the Charger 28 Click by disabling charging, resetting registers, disabling the TS pin, configuring the ADC, and re-enabling charging.

Application Task
Periodically retrieves and logs charging parameters such as input voltage, battery voltage, system voltage, charging current, and temperature. The application also reads the status and fault registers to determine the current charging state and logs the information for debugging or monitoring purposes.

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 Charger 28 Click example
 *
 * # Description
 * This example demonstrates the use of the Charger 28 Click board by monitoring various parameters
 * of the charging system, such as input voltage (VBUS), battery voltage (VBAT), system voltage (VSYS),
 * charging current (IBAT), and chip temperature (TDIE). Additionally, it reads and interprets the
 * charger status and fault registers to provide detailed status and error feedback during operation.
 *
 * The demo application is composed of two sections:
 *
 * ## Application Init
 * Initializes the driver and performs the default configuration of the Charger 28 Click by disabling
 * charging, resetting registers, disabling the TS pin, configuring the ADC, and re-enabling charging.
 *
 * ## Application Task
 * Periodically retrieves and logs charging parameters such as input voltage, battery voltage,
 * system voltage, charging current, and temperature. The application also reads the status and 
 * fault registers to determine the current charging state and logs the information for debugging 
 * or monitoring purposes.
 *
 * @note
 * The application is designed to continuously monitor the charging system, providing real-time 
 * feedback on its operation. The detailed charge status parsing includes states such as "Not Charging", 
 * "Trickle Charge", "Fast Charge", and "Charge Done", among others, to help track the charging process.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "charger28.h"

static charger28_t charger28;
static log_t logger;

/**
 * @brief Charger 28 parse charge status function.
 * @details This function parses the given charge status value and logs the corresponding charge state.
 * @param[in] status : Charge status byte.
 * The status byte contains the charge status information as per the device Charger status 1 register.
 * @return None.
 * @note This function logs the charge status details using the logger object.
 */
static void charger28_parse_charge_status ( uint8_t status );

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    charger28_cfg_t charger28_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.
    charger28_cfg_setup( &charger28_cfg );
    CHARGER28_MAP_MIKROBUS( charger28_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == charger28_init( &charger28, &charger28_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( CHARGER28_ERROR == charger28_default_cfg ( &charger28 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float ibus = 0, vbat = 0, vsys = 0, adcin = 0, tdie = 0;
    uint8_t status_0 = 0, status_1 = 0, fault = 0;
    uint16_t vbus = 0, vpmid = 0;
    int16_t ibat = 0;

    if ( CHARGER28_OK == charger28_get_vbus ( &charger28, &vbus ) )
    {
        log_printf ( &logger, "\r\n VBUS: %u mV\r\n", vbus );
    }

    if ( CHARGER28_OK == charger28_get_ibus ( &charger28, &ibus ) )
    {
        log_printf ( &logger, " IBUS: %.1f mA\r\n", ibus );
    }

    if ( CHARGER28_OK == charger28_get_vbat ( &charger28, &vbat ) )
    {
        log_printf ( &logger, " VBAT: %.2f mV\r\n", vbat );
    }

    if ( CHARGER28_OK == charger28_get_ibat ( &charger28, &ibat ) )
    {
        log_printf ( &logger, " IBAT: %d mA\r\n", ibat );
    }

    if ( CHARGER28_OK == charger28_get_vsys ( &charger28, &vsys ) )
    {
        log_printf ( &logger, " VSYS: %.2f mV\r\n", vsys );
    }

    if ( CHARGER28_OK == charger28_get_vpmid ( &charger28, &vpmid ) )
    {
        log_printf ( &logger, " VPMID: %u mV\r\n", vpmid );
    }

    if ( CHARGER28_OK == charger28_get_adcin ( &charger28, &adcin ) )
    {
        log_printf ( &logger, " ADCIN: %.2f mV\r\n", adcin );
    }

    if ( CHARGER28_OK == charger28_get_tdie ( &charger28, &tdie ) )
    {
        log_printf ( &logger, " TDIE: %.1f degC\r\n", tdie );
    }

    if ( CHARGER28_OK == charger28_read_reg_byte ( &charger28, CHARGER28_REG_CHARGER_STATUS_0, &status_0 ) )
    {
        log_printf ( &logger, " Status 0: 0x%.2X\r\n", ( uint16_t ) status_0 );
    }
    
    if ( CHARGER28_OK == charger28_read_reg_byte ( &charger28, CHARGER28_REG_CHARGER_STATUS_1, &status_1 ) )
    {
        log_printf ( &logger, " Status 1: 0x%.2X\r\n", ( uint16_t ) status_1 );
        charger28_parse_charge_status ( status_1 );
    }

    if ( CHARGER28_OK == charger28_read_reg_byte ( &charger28, CHARGER28_REG_FAULT_STATUS, &fault ) )
    {
        log_printf ( &logger, " Fault: 0x%.2X\r\n", ( uint16_t ) fault );
    }

    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;
}

static void charger28_parse_charge_status ( uint8_t status )
{
    log_printf ( &logger, " Charge Status: " );
    switch ( CHARGER28_CHARGER_STATUS_1_CHG_STAT_MASK & status )
    {
        case CHARGER28_CHARGER_STATUS_1_CHG_STAT_NOT_CHARGING:
        {
            log_printf ( &logger, "Not Charging\r\n" );
            break;
        }
        case CHARGER28_CHARGER_STATUS_1_CHG_STAT_TRICKLE_CHARGE:
        {
            log_printf ( &logger, "Trickle Charge (VBAT < VBAT_SHORTZ)\r\n" );
            break;
        }
        case CHARGER28_CHARGER_STATUS_1_CHG_STAT_PRE_CHARGE:
        {
            log_printf ( &logger, "Pre-charge (VBAT_SHORTZ < VBAT < VBAT_LOWV)\r\n" );
            break;
        }
        case CHARGER28_CHARGER_STATUS_1_CHG_STAT_FAST_CHARGE:
        {
            log_printf ( &logger, "Fast Charge (CC mode)\r\n" );
            break;
        }
        case CHARGER28_CHARGER_STATUS_1_CHG_STAT_TAPER_CHARGE:
        {
            log_printf ( &logger, "Taper Charge (CV mode)\r\n" );
            break;
        }
        case CHARGER28_CHARGER_STATUS_1_CHG_STAT_TO_TIMER_ACT_CH:
        {
            log_printf ( &logger, "Top-off Timer Active Charging\r\n" );
            break;
        }
        case CHARGER28_CHARGER_STATUS_1_CHG_STAT_CHARGE_DONE:
        {
            log_printf ( &logger, "Charge Termination Done\r\n" );
            break;
        }
        default:
        {
            log_printf ( &logger, "Unknown\r\n" );
            break;
        }
    }
}

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