Intermediate
30 min

Charge into the future with BQ25601 and ATmega644P

Plug, Charge, Conquer

Charger 6 Click with EasyAVR v7

Published May 14, 2023

Click board™

Charger 6 Click

Dev. board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega644P

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

EasyAVR v7 is the seventh generation of AVR development boards specially designed for the needs of rapid development of embedded applications. It supports a wide range of 16-bit AVR microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyAVR v7 allows you to connect accessory boards, sensors, and custom electronics more

efficiently than ever. Each part of the EasyAVR v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B)

connector. Communication options such as USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets which cover a wide range of 16-bit AVR MCUs. EasyAVR v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyAVR v7 horizontal image

Microcontroller Overview

MCU Card / MCU

Architecture

AVR

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

4096

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.

Charger 6 Click accessories image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Reset Control
PA6
RST
Charging Process Enable
PA5
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Power Source Selection
PD4
PWM
Interrupt
PD2
INT
NC
NC
TX
NC
NC
RX
I2C Clock
PC0
SCL
I2C Data
PC1
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

EasyAVR v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v7 as your development board.

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyAVR v7 Access DIP 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 Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image 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.