XIAO Sense nRF52840 - A Guide on How to set Battery Charging current : 0mA vs 50mA vs 100mA (non-mbed)

This guide is to help those using the non-mbed bootloader set the battery charging current (0mA vs 50mA vs 100 mA) on the Xiao Sense nRF52840. Just copy the desired code below and you’re good to go. The rest of this text is extra detail

The Seeed wiki page as of April 22nd, 2024 is wrong, and in short, PIN 22 is partly used to control the charging current. This thread attempted midway down to get to the bottom of this, but the shared information was also not totally correct. That said, without the commenters help, I would not have been able to solve this problem.

I have completed the appropriate tests with a current meter, so with the given libaries, the below code is working and correct:

IDE + Library Version:
Arduino IDE 1.8.16
Bootloader core: Seeed nRF52 Boards v1.1.8

To achive 0 mA charging current:

void setup() {
  pinMode(22, OUTPUT);                        // Set 22 to OUTPUT
  digitalWrite(22, HIGH);                      // Charge with 0mA
}

To achieve 50 mA charging current:

void setup() {
// Do Nothing
}

To achieve 100 mA charging current:

void setup() {
  pinMode(22, OUTPUT);                        // Set 22 to OUTPUT
  digitalWrite(22, LOW);                      // Charge with 100mA
}

Further notes:

The wiki page currently states to use P0_13 to adjust the charging current by setting HIGH/LOW for the inverse charging current (i.e. setting HIGH → 50 mA, setting LOW → 100mA). Yet, using the non-mbed bootloader, P0_13 won’t even be recognized and the code will not compile

Changing P0_13 to 13 means the code will compile and run, but both digitalWrite(13, HIGH); and digitalWrite(13, LOW); result in only 50 mA. In short, the code does nothing for battery charging! Without any code the standard battery charging rate appears to be set at 50mA. No code required!

In order to get 100 mA, it is necessary to use pin 22 with digitalWrite(22, LOW); If HIGH is used instead, the resulting current will be 0 mA

This was tested using a 3.7V LiPo measuring at ~3.05 V, so it needed charging and could accept the full current. As for actual values, “0 mA” was 0 mA, “50 mA” was closer to 50.6 mA, and “100 mA” closer to 99 mA

I have tried to look at the schematics to understand how this all works and I still don’t understand. This is principally because I don’t know what pin PIN 22 actually is…If anyone would care to enlighten me on how this all works, it’d be much appreciated!

Hope this helps others

When P0.13 is OPEN (default or input setting), R(ISET)=2.7k and the charge current is set to 50mA.
When P0.13 is LOW, R(ISET)2.7k is connected in parallel and the charge current is set to 100mA.

POST_nRF52_XIAO_CHARGE_VBAT_READ_TEST.zip (984 Bytes)

1 Like

Thanks for the reply! The code you posted is great; clean and understandable and has all the rest of the possible battery information

After looking up the R(ISET) you mentioned in the Xiao Sense schematic, and the BQ25100 Battery Charger Schematic I now understand why making the resistors goes into parallel doubles the current. As per the 2nd schematic, I(OUT) = K(ISET)/R(ISET), where K is the set gain and R the resistance. Halving R(ISET) means twice the battery charging current!

From the schematics I can see that the PIN ‘P0.13’ is called ‘P0.13_HICHG’ which you then seem to define in your code as:

#define PIN_HICHG (22)

Could you help me understand how to go from the schematic to knowing that ‘P0.13’ is PIN 22 in the code? Thanks!

As shown below, “13” is “element 22” of “const uint32_t g_ADigitalPinMap[]”.

\Arduino15\packages\Seeeduino\hardware\nrf52\1.1.8\variants\Seeed_XIAO_nRF52840_Sense\variant.cpp : 39

1 Like