Skip to content

Commit c0eb5bf

Browse files
authored
Merge pull request #212 from fdlamotte/xiao_nrf52-batread
xiao-nrf keep vbat_en to low to prevent issues ...
2 parents 1b25a63 + 6735960 commit c0eb5bf

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

src/helpers/nrf52/XiaoNrf52Board.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,16 @@ class XiaoNrf52Board : public mesh::MainBoard {
4949
// Please read befor going further ;)
5050
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
5151

52-
pinMode(BAT_NOT_CHARGING, INPUT);
53-
if (digitalRead(BAT_NOT_CHARGING) == HIGH) {
54-
int adcvalue = 0;
55-
analogReadResolution(12);
56-
analogReference(AR_INTERNAL_3_0);
57-
digitalWrite(VBAT_ENABLE, LOW);
58-
delay(10);
59-
adcvalue = analogRead(PIN_VBAT);
60-
digitalWrite(VBAT_ENABLE, HIGH);
61-
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
62-
} else {
63-
digitalWrite(VBAT_ENABLE, HIGH); // ensures high !
64-
return 4200; // charging value
65-
}
52+
// We can't drive VBAT_ENABLE to HIGH as long
53+
// as we don't know wether we are charging or not ...
54+
// this is a 3mA loss (4/1500)
55+
digitalWrite(VBAT_ENABLE, LOW);
56+
int adcvalue = 0;
57+
analogReadResolution(12);
58+
analogReference(AR_INTERNAL_3_0);
59+
delay(10);
60+
adcvalue = analogRead(PIN_VBAT);
61+
return (adcvalue * ADC_MULTIPLIER * AREF_VOLTAGE) / 4.096;
6662
}
6763

6864
const char* getManufacturerName() const override {

variants/xiao_nrf52/variant.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ void initVariant()
6060
// Disable reading of the BAT voltage.
6161
// https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
6262
pinMode(VBAT_ENABLE, OUTPUT);
63-
digitalWrite(VBAT_ENABLE, HIGH);
63+
//digitalWrite(VBAT_ENABLE, HIGH);
64+
// This was taken from Seeed github butis not coherent with the doc,
65+
// VBAT_ENABLE should be kept to LOW to protect P0.14, (1500/500)*(4.2-3.3)+3.3 = 3.9V > 3.6V
66+
// This induces a 3mA current in the resistors :( but it's better than burning the nrf
67+
digitalWrite(VBAT_ENABLE, LOW);
6468

65-
// Low charging current.
69+
// Low charging current (50mA)
6670
// https://wiki.seeedstudio.com/XIAO_BLE#battery-charging-current
67-
pinMode(PIN_CHARGING_CURRENT, INPUT);
71+
//pinMode(PIN_CHARGING_CURRENT, INPUT);
72+
73+
// High charging current (100mA)
74+
pinMode(PIN_CHARGING_CURRENT, OUTPUT);
75+
digitalWrite(PIN_CHARGING_CURRENT, LOW);
6876

6977
pinMode(PIN_QSPI_CS, OUTPUT);
7078
digitalWrite(PIN_QSPI_CS, HIGH);

0 commit comments

Comments
 (0)