From 6735960a4e77f2d0a0f8d74ee5f61df8a0b18afe Mon Sep 17 00:00:00 2001 From: Florent Date: Sun, 20 Apr 2025 16:32:46 +0200 Subject: [PATCH] xiao-nrf keep vbat_en to low to prevent issues ... --- src/helpers/nrf52/XiaoNrf52Board.h | 24 ++++++++++-------------- variants/xiao_nrf52/variant.cpp | 14 +++++++++++--- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/helpers/nrf52/XiaoNrf52Board.h b/src/helpers/nrf52/XiaoNrf52Board.h index 1474892e..386001a2 100644 --- a/src/helpers/nrf52/XiaoNrf52Board.h +++ b/src/helpers/nrf52/XiaoNrf52Board.h @@ -49,20 +49,16 @@ public: // Please read befor going further ;) // https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging - pinMode(BAT_NOT_CHARGING, INPUT); - if (digitalRead(BAT_NOT_CHARGING) == HIGH) { - int adcvalue = 0; - analogReadResolution(12); - analogReference(AR_INTERNAL_3_0); - digitalWrite(VBAT_ENABLE, LOW); - delay(10); - adcvalue = analogRead(PIN_VBAT); - digitalWrite(VBAT_ENABLE, HIGH); - return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096; - } else { - digitalWrite(VBAT_ENABLE, HIGH); // ensures high ! - return 4200; // charging value - } + // We can't drive VBAT_ENABLE to HIGH as long + // as we don't know wether we are charging or not ... + // this is a 3mA loss (4/1500) + digitalWrite(VBAT_ENABLE, LOW); + int adcvalue = 0; + analogReadResolution(12); + analogReference(AR_INTERNAL_3_0); + delay(10); + adcvalue = analogRead(PIN_VBAT); + return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096; } const char* getManufacturerName() const override { diff --git a/variants/xiao_nrf52/variant.cpp b/variants/xiao_nrf52/variant.cpp index 3c99b98d..16542e27 100644 --- a/variants/xiao_nrf52/variant.cpp +++ b/variants/xiao_nrf52/variant.cpp @@ -60,11 +60,19 @@ void initVariant() // Disable reading of the BAT voltage. // https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging pinMode(VBAT_ENABLE, OUTPUT); - digitalWrite(VBAT_ENABLE, HIGH); + //digitalWrite(VBAT_ENABLE, HIGH); + // This was taken from Seeed github butis not coherent with the doc, + // VBAT_ENABLE should be kept to LOW to protect P0.14, (1500/500)*(4.2-3.3)+3.3 = 3.9V > 3.6V + // This induces a 3mA current in the resistors :( but it's better than burning the nrf + digitalWrite(VBAT_ENABLE, LOW); - // Low charging current. + // Low charging current (50mA) // https://wiki.seeedstudio.com/XIAO_BLE#battery-charging-current - pinMode(PIN_CHARGING_CURRENT, INPUT); + //pinMode(PIN_CHARGING_CURRENT, INPUT); + + // High charging current (100mA) + pinMode(PIN_CHARGING_CURRENT, OUTPUT); + digitalWrite(PIN_CHARGING_CURRENT, LOW); pinMode(PIN_QSPI_CS, OUTPUT); digitalWrite(PIN_QSPI_CS, HIGH);