Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "BQ25896.h" 00003 00004 Serial pc(p29, p30, "debug", 115200); 00005 00006 BQ25896 bq25896(p28, p2); 00007 00008 uint8_t chargeState = 0; 00009 00010 void initBQ25896(void){ 00011 pc.printf("init BQ25896\n\r"); 00012 bq25896.reset(); 00013 bq25896.disableWATCHDOG(); // disable Watchdog 00014 bq25896.disableILIMPin(); 00015 bq25896.setIINLIM(3250); // mA 00016 bq25896.setBOOSTV(4900);//5000);// 00017 bq25896.setICHG(1280); // Fast Charge Current Limit 1280 00018 bq25896.setBOOST_LIM(6); // BOOST_LIM 2.15A 00019 wait(1); 00020 bq25896.oneShotADC(); 00021 if(bq25896.getVBUSV() < 4.00){ 00022 bq25896.enableOTG(); 00023 } 00024 } 00025 00026 void checkChargingState(void){ 00027 00028 bq25896.oneShotADC(); 00029 float voltage = bq25896.getVBUSV(); 00030 if(chargeState == 0){ 00031 if (voltage >= 4.95){ 00032 pc.printf("charger detected %2.3f\n\r", voltage); 00033 chargeState = 1; 00034 bq25896.disableOTG(); 00035 } 00036 } else if (chargeState == 1){ 00037 if (voltage < 4.00){ 00038 pc.printf("charger removed %2.3f\n\r", voltage); 00039 chargeState = 0; 00040 bq25896.enableOTG(); 00041 } 00042 } 00043 } 00044 00045 int main() 00046 { 00047 initBQ25896(); 00048 while(true){ 00049 wait(1); 00050 checkChargingState(); 00051 } 00052 }
Generated on Fri Jul 29 2022 06:40:07 by
1.7.2