How LiFePO4 cells communicate

How LiFePO4 cells communicate
Zoomed in part of the circuit diagram

My reason to use the ATtiny85V microcontroller is that it has a power-down sleep mode where it consumes as little as 1 µA, which equals zero for any practical purposes. The reason for consuming anything at all is that we can wake it up by changing the state of an input pin: what we call a hardware interrupt.

When the central ESP32 controller wants to wake the cell boards up, it sends out a pulse, which arrives at every cell board on the SYNC pins of the COM1 pin header on the right in the diagram. The SYNC pins connect to the LED that is inside U3, one of the optocouplers. So basically, when the ESP32 sends out that pulse, the LEDs inside U3 of every cell board light up.

Now we look at the other side of U3, the phototransistor part of the optocoupler. When the LED is off, the transistor is off. Now R2 is a pull-up resistor, keeping pin PB3 of the MCU high, at Vcc. But when the transistor switches on because of the LED illuminating it, the transistor pulls PB3 low, to Vss/GND and this is the state change of the pin that wakes up the MCU. So simple!

Software. We have a main loop which starts with enabling the pin-change interrupt, then immediately goes into power down sleep.
When a pulse arrives, all the ISR does is disable the pin-change interrupt. This means that after that, the main loop continues where it previously was, so right after the power down sleep call. Now we determine which kind of pulse we got: a 20ms heartbeat pulse or a 100ms sync/reset pulse. The main loop waits 40ms then looks at PB3 again. If it is still low, the pulse is longer than that of the 20ms heartbeat pulse so it must be the 100ms sync pulse.

So the main loop splits into an IF statement for each type of pulse. If we have a 100ms sync pulse, we first turn on the status LED, then reset the heartbeat counter to zero and measure the cell voltage and temperature, store those values in RAM, wait for the pulse to end, turn off the LED and repeat the loop, so go back to sleep.

If we have a 20ms heartbeat pulse, we increment the heartbeat counter. If the counter is equal to our cell number (which was stored in EEPROM during commissioning of the cell board), we turn the status LED on, then transmit the stored measurements to the ESP32 using U2, the other optocoupler. After that the LED is turned off and the loop repeats, so going back to power down sleep.

Observing the cell boards, you should see all their LEDs flash simultaneously during a sync pulse, the see them take turns during the heartbeat pulses.

As you can see the software is very simple, as it should be. If you can think like the above paragraphs to describe the functionality, you only have to give that to an AI which will write the software for you, which is a great time saver.