Intermediate
30 min

Charge into the future with BQ25601 and ATmega328

Plug, Charge, Conquer

Charger 6 Click with Arduino UNO Rev3

Published Feb 14, 2024

Click board™

Charger 6 Click

Dev. board

Arduino UNO Rev3

Compiler

NECTO Studio

MCU

ATmega328

Take the first step towards a better charging solution for your device - choose our advanced battery charger today

A

A

Hardware Overview

How does it work?

Charger 6 Click is based on the BQ25601, a fast-charging solution for single-cell Li-Ion and Li-polymer batteries with high input voltage suitable for a wide range of smartphones, tablets, and portable devices from Texas Instruments. The low-impedance power path optimizes switch-mode operation efficiency, reduces battery charging time, and extends battery life during discharge. It is optimized for USB 5V voltage input, has a programmable current limiting based on the built-in USB interface, and allows an external power supply from 3.9 to 13.5V. The BQ25601 also meets USB On-the-Go (OTG) operation power rating specification by supplying 5.15 V on the VBUS line with a constant current limit of up to 1.2A. The device provides automatic power path selection on the SYS line from the VBUS input source, battery, or both. The power path management regulates the system slightly above the battery voltage but does not drop below the 3.5V minimum system voltage. With this feature, the system maintains operation even when the battery is completely removed.

When the input current limit or voltage limit is reached, the power path management automatically reduces the charge current to zero. As the system load increases, the power path discharges the battery until the system power requirement is met. Charger 6 Click communicates with MCU using the standard I2C 2-Wire interface and supports both Standard and Fast Mode with a transfer rate of 100 and 400kbit/s. The I2C serial interface with charging and system settings makes this Click board™ a truly flexible solution. Also, it uses several GPIO pins, one of which is an interrupt pin, the INT pin of the mikroBUS™ socket, used as a ‘fault’ indicator. This pin sets immediately notifies the host when a fault occurs. This Click board™ also uses two LED indicators, PG and STAT, as power good and charging status indicators. PG indicates a good input source if the input voltage is above the SLEEP mode threshold and the current limit is above 30mA, while STAT reports the charging status and any fault conditions. The CE pin routed to the CS pin on the mikroBUS™ socket enables the battery charging

process by setting this pin into a low logic state. PSEL pin routed to the PWM pin on the mikroBUS™ socket is used as a power source selection input and sets a 500mA input current limit by pulling this pin high; otherwise, set 2.4A input current limit by pulling this pin low. The BQ25601 also provides a QON pin, routed to the RST pin on the mikroBUS™ socket, for BATFET enable and reset control, to exit low-power mode or the whole system reset function. The charger provides a selectable temperature monitoring feature via a TEMP SEL jumper, where the user can choose between external or internal monitoring. A single thermistor input for the battery temperature monitor is provided for external mode. This Click board™ can only be operated with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. However, the Click board™ comes equipped with a library containing functions and an example code that can be used as a reference for further development.

Charger 6 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

32

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

Charger 6 Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset Control
PD2
RST
Charging Process Enable
PB2
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Power Source Selection
PD6
PWM
Interrupt
PC3
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC5
SCL
I2C Data
PC4
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Charger 6 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
Arduino UNO Rev3 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
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

This library contains API for Charger 6 Click driver.

Key functions:

  • charger6_cfg_setup - Config Object Initialization function.
  • charger6_init - Initialization function.
  • charger6_default_cfg - Click Default Configuration function.

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 Charger6 Click example
 *
 * # Description
 * This library contains API for the Charger 6 Click driver.
 * The library contains drivers to enable/disable battery charging, 
 * set current limit, set system min voltage, set fast charge current,
 * set charge voltage, etc.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes I2C driver and set default configuration:
 * input current limit set to 500 mA, system minimum voltage to 3500 mV,
 * fast charge current set to 360 mA, charge voltage to 4112 mV and
 * enable battery charging.  
 *
 * ## Application Task
 * This example monitors the operation of the Charger 6 Click and all its charging states. 
 * The user can observe information such as charging status, selected mode, 
 * charging current value, and the momentary value of the supply voltage relative to the battery voltage.
 * Results are being sent to the Usart Terminal where you can track their changes.
 *
 * @author Nenad Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "charger6.h"

static charger6_t charger6;
static log_t logger;

charger6_status_t chg_status;
static uint16_t charge_current;

void display_chrg_status ( void ) {
    log_printf( &logger, " Charging   :" );
    switch ( chg_status.chrg_stat ) {
        case CHARGER6_R08_CHRG_STAT_NOT_CHARGING : {
            log_printf( &logger, " Not Charging\r\n" );
            break;
        }
        case CHARGER6_R08_CHRG_STAT_PRE_CHARGE : {
            log_printf( &logger, " Pre-charge\r\n" );
            break;
        }
        case CHARGER6_R08_CHRG_STAT_FAST_CHARGING : {
            log_printf( &logger, " Fast Charging\r\n" );
            charge_current = charger6_get_fast_charge_current( &charger6 );
            log_printf( &logger, " Chg Current: %u mA\r\n", charge_current );
            break;
        }
        case CHARGER6_R08_CHRG_STAT_CHARGE_TERMINATION : {
            log_printf( &logger, " Charge Termination\r\n" );
            break;
        }
        default : {
            log_printf( &logger, " Unknown\r\n" );
            break;
        }
    }
}

void display_power_good_status ( void ) {
    log_printf( &logger, " Power      :" );
    switch ( chg_status.pg_stat ) {
        case CHARGER6_R08_PG_STAT_POWER_NOT_GOOD : {
            log_printf( &logger, " Power Not Good\r\n" );
            break;
        }
        case CHARGER6_R08_PG_STAT_POWER_GOOD : {
            log_printf( &logger, " Power Good\r\n" );
            break;
        }
        default : {
            log_printf( &logger, " Unknown\r\n" );
            break;
        }
    }
}

void display_vsys_status ( void ) {
    log_printf( &logger, " Vsys       :" );
    switch ( chg_status.vsys_stat ) {
        case CHARGER6_R08_VSYS_STAT_NOT : {
            log_printf( &logger, " BAT > Vsys Min\r\n" );
            break;
        }
        case CHARGER6_R08_VSYS_STAT_VSYSM : {
            log_printf( &logger, " BAT < Vsys Min\r\n" );
            break;
        }
        default : {
            log_printf( &logger, " Unknown\r\n" );
            break;
        }
    }
}


void display_bat_status ( void ) {
    log_printf( &logger, " Battery    :" );
    switch ( chg_status.bat_fault ) {
        case CHARGER6_R09_BAT_FAULT_NORMAL : {
            log_printf( &logger, " Normal\r\n" );
            break;
        }
        case CHARGER6_R08_VSYS_STAT_VSYSM : {
            log_printf( &logger, " Overvoltage\r\n" );
            break;
        }
        default : {
            log_printf( &logger, " Unknown\r\n" );
            break;
        }
    }
}

void display_chrg_fault_status ( void ) {
    log_printf( &logger, " Chrg fault :" );
    switch ( chg_status.chrg_fault ) {
        case CHARGER6_R09_CHRG_FAULT_NORMAL : {
            log_printf( &logger, " Normal\r\n" );
            break;
        }
        case CHARGER6_R09_CHRG_FAULT_INPUT_FAULT : {
            log_printf( &logger, " Input fault\r\n" );
            break;
        }
        case CHARGER6_R09_CHRG_FAULT_THERMAL_SHUTDOWN : {
            log_printf( &logger, " Thermal shutdown\r\n" );
            break;
        }
        case CHARGER6_R09_CHRG_FAULT_CHG_SAFETY_TIMER_EXP : {
            log_printf( &logger, " Charge Safety Timer Expiration\r\n" );
            break;
        }
        default : {
            log_printf( &logger, " Unknown\r\n" );
            break;
        }
    }
}

void application_init ( void ) {
    log_cfg_t log_cfg;            /**< Logger config object. */
    charger6_cfg_t charger6_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.

    charger6_cfg_setup( &charger6_cfg );
    CHARGER6_MAP_MIKROBUS( charger6_cfg, MIKROBUS_1 );
    err_t init_flag = charger6_init( &charger6, &charger6_cfg );
    if ( init_flag == I2C_MASTER_ERROR ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }

    charger6_default_cfg ( &charger6 );
    log_info( &logger, " Application Task " );
    Delay_ms( 1000 );

    log_printf( &logger, "-------------------------------\r\n" );
    log_printf( &logger, " Set Current Limit   :  500 mA \r\n" );
    charger6_set_input_current_limit( &charger6, 500 );
    Delay_ms( 100 );
    
    log_printf( &logger, " Set Sys Min Voltage : 3500 mV \r\n" );
    charger6_set_system_minimum_voltage( &charger6, 3500 );
    Delay_ms( 100 );
    
    log_printf( &logger, " Set Fast Chg Current:  360 mA \r\n" );
    charger6_set_fast_charge_current( &charger6, 360 );
    Delay_ms( 100 );
    
    log_printf( &logger, " Set Charge Voltage  : 4112 mV \r\n" );
    charger6_set_charge_voltage( &charger6, 4112 );
    Delay_ms( 100 );
    
    log_printf( &logger, " >> Enable Battery Charging << \r\n" );
    charger6_enable_battery_charging( &charger6 );
    Delay_ms( 1000 );
    
    log_printf( &logger, "-------------------------------\r\n" );
    log_printf( &logger, "       >>>   Status   <<<      \r\n" );
    log_printf( &logger, "-------------------------------\r\n" );
}

void application_task ( void ) {
    charger6_get_status( &charger6, &chg_status );
    Delay_ms( 100 );
    
    display_power_good_status( );
    Delay_ms( 100 );
    
    display_chrg_status( );
    Delay_ms( 100 );
    
    display_bat_status( );
    Delay_ms( 100 );
    
    display_chrg_fault_status( );
    Delay_ms( 100 );
    
    display_vsys_status( );
    log_printf( &logger, "-------------------------------\r\n" );
    Delay_ms( 2000 );
}

void main ( void ) {
    application_init( );

    for ( ; ; ) {
        application_task( );
    }
}

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