VRaktion
/
demo-BQ25896
Demo Application for the BQ25896 driver
Revision 3:193555f31269, committed 2019-06-19
- Comitter:
- vraktion
- Date:
- Wed Jun 19 14:23:44 2019 +0200
- Parent:
- 2:874ba79e51f1
- Commit message:
- added charge detection feature with OTG switch
Changed in this revision
.DS_Store | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
Binary file .DS_Store has changed
--- a/main.cpp Wed Jun 19 12:15:55 2019 +0200 +++ b/main.cpp Wed Jun 19 14:23:44 2019 +0200 @@ -1,25 +1,52 @@ #include "mbed.h" #include "BQ25896.h" -Serial pc(p13, p12, "debug", 115200); +Serial pc(p29, p30, "debug", 115200); + +BQ25896 bq25896(p28, p2); + +uint8_t chargeState = 0; -BQ25896 bq25896(p26, p27); +void initBQ25896(void){ + pc.printf("init BQ25896\n\r"); + bq25896.reset(); + bq25896.disableWATCHDOG(); // disable Watchdog + bq25896.disableILIMPin(); + bq25896.setIINLIM(3250); // mA + bq25896.setBOOSTV(4900);//5000);// + bq25896.setICHG(1280); // Fast Charge Current Limit 1280 + bq25896.setBOOST_LIM(6); // BOOST_LIM 2.15A + wait(1); + bq25896.oneShotADC(); + if(bq25896.getVBUSV() < 4.00){ + bq25896.enableOTG(); + } +} + +void checkChargingState(void){ + + bq25896.oneShotADC(); + float voltage = bq25896.getVBUSV(); + if(chargeState == 0){ + if (voltage >= 4.95){ + pc.printf("charger detected %2.3f\n\r", voltage); + chargeState = 1; + bq25896.disableOTG(); + } + } else if (chargeState == 1){ + if (voltage < 4.00){ + pc.printf("charger removed %2.3f\n\r", voltage); + chargeState = 0; + bq25896.enableOTG(); + } + } +} int main() { - pc.printf("init BQ25896\n\r"); - bq25896.reset(); - bq25896.disableWATCHDOG(); // disable Watchdog - bq25896.disableILIMPin(); - bq25896.setIINLIM(3250); // mA - bq25896.enableOTG(); - bq25896.setBOOSTV(5000); // - bq25896.setICHG(1280); // Fast Charge Current Limit 1280 - bq25896.setBOOST_LIM(6); // BOOST_LIM 2.15A - // bq25896.enableFORCE_VINDPM();//absolute VINDPM - // bq25896.setVINDPM(4000); - // pc->printf("VINDPM: %d\n\r", bq25896.getVINDPM()); + initBQ25896(); while(true){ wait(1); + checkChargingState(); } } \ No newline at end of file