One ESP32-C3 controller for Huawei R4850G2 and Emerson R48-2000e rectifiers over CAN
Second-hand telecom rectifiers make good battery chargers, but each brand speaks its own CAN dialect. I built a controller for the Huawei R4850G2 first and one for the Emerson R48-2000e after that, each with its own sketch. Both used the same hardware, so I merged them into one firmware that supports both models. At boot you pick the supply with the encoder, and from then on it behaves the same way for both.
What it does
- Sets the output voltage and current limit with a rotary encoder
- Model selection at boot: turn the encoder to choose Emerson or Huawei and press to confirm. After 5 seconds without input it starts the model used last time. The first time ever, the default is Emerson
- Short press switches between voltage and current editing
- Long press saves the values to the ESP32 flash and, only if the supply answers on CAN, to the supply itself (its offline values)
- Double click switches the output on and off; the off state is not saved, so the output is always on at boot
- Blinking NC on the display when no CAN frame has been received for 3 seconds
- Huawei: the idle screen shows the measured output voltage and current. Emerson: the idle screen shows the set values, because I have not identified its status frames yet
The supply’s non-volatile values are written only on a long press, never automatically, so its memory does not wear out. With no CAN communication, the long press only saves to the ESP32 and the display shows NO PSU instead of SAVED.
Parts
| Part | Notes |
|---|---|
| Huawei R4850G2 or Emerson R48-2000eR | 48 V rectifier |
| ESP32-C3 SuperMini | controller |
| MCP2515 CAN module | 8 MHz crystal |
| 0.91" OLED, 128x32 | I2C |
| Rotary encoder with button |
Wiring
| Function | ESP32-C3 SuperMini pin |
|---|---|
| MCP2515 SCK | GPIO4 |
| MCP2515 MISO | GPIO5 |
| MCP2515 MOSI | GPIO6 |
| MCP2515 CS | GPIO7 |
| OLED SDA | GPIO8 |
| OLED SCL | GPIO9 |
| Encoder CLK | GPIO2 |
| Encoder DT | GPIO3 |
| Encoder SW | GPIO0 |
The MCP2515 INT pin is not connected; the code polls for incoming frames.
Two supplies, two dialects
Both supplies use a 125 kbit/s CAN bus with 29-bit IDs, so the CAN setup is the same. The differences are in the frames and the behaviour:
| Huawei R4850G2 | Emerson R48-2000eR | |
|---|---|---|
| Command ID | 0x108180FE | 0x0607FF83 |
| Voltage value | volts x 1024, integer | IEEE 754 float |
| Current value | amps x 20, integer | float, as a fraction of the 47 A rating |
| Voltage limits in my firmware | 42 to 58.4 V | 40 to 58.4 V |
| Commands resent every | 1 second | 10 seconds |
| Measurements | read back over CAN | not decoded yet |
| CAN off command | output stops, fan stops | output stops, fan keeps running |
For the full Huawei protocol, see the R4850G2 controller article.
Emerson frames
The first stage of the Emerson project, with a fixed voltage and current set in the code, is described in the R48-2000eR charger article, including the connector pinout.
Every command is one frame with ID 0x0607FF83 (extended) and 8 data bytes: 03 F0 00 CMD followed by a 32-bit big-endian value.
| CMD | Meaning | Value |
|---|---|---|
0x21 | Voltage, online (volatile) | float, volts |
0x24 | Voltage, offline (stored) | float, volts |
0x22 | Current limit, online | float, fraction of 47 A |
0x19 | Current limit, offline | float, fraction of 47 A |
0x30 | Output ON / OFF | 00 00 00 00 / 00 01 00 00 |
The current limit is sent as a fraction of the supply’s rated current, so 20 A is 20 / 47 = 0.4255 as a float. In the code, the frames are sent with a 30 ms pause between them. The output on/off frame comes from community documentation.
Fan behaviour. On the Emerson the fan runs at full speed at power-up, slows down clearly once the controller sets the output voltage, and does not change when the CAN off command is sent. On the Huawei, the off command stops the fan as well.
How the firmware is organised
One sketch holds both models. A model flag selects the frames, the limits, the resend interval and the flash keys, so the user interface code is shared.
- Model selection: the chosen model is written to flash only when it changes
- Flash storage: each model keeps its own saved voltage and current under its own key, so switching models does not mix the values
- Encoder: read by polling on the falling edge of CLK with a 35 ms debounce, not in an interrupt, because DT has to be read after the contact has settled
- Boot: the saved voltage and current are sent, the output is switched on, and on the Huawei the measurement request follows
- Idle screen: the largest font that fits V, A and the NC marker on one line is chosen automatically
Code
Written in the Arduino IDE for the ESP32-C3 with autowp/arduino-mcp2515, U8g2 and the ESP32 Preferences library.
Repo: github.com/blazeB45/psu_can_controller
Problems and fixes
- No response from the first supply I tried: I started with an SN65HVD230 module; it turned out to be defective, and switching to an MCP2515 module fixed it. The test sketch and a checklist are in the SN65HVD230 article, and the Huawei side is in the R4850G2 article.
- Emerson fan: the CAN off command cuts the output but not the fan, so the fan keeps running until the supply is powered down.
- Emerson measurements: the status frames are not identified, so the Emerson idle screen shows set values instead of measured ones.
Safety
These supplies deliver real power at 48 V. When charging a battery, put an ideal diode or a MOSFET on the supply output so the supply never sees the battery voltage, set the voltage and current limit to the battery’s specification, and use a BMS. 58.4 V is 3.65 V per cell on a 16S LiFePO4 pack; adjust the limits in the code for your battery. At boot the controller applies the last saved voltage and switches the output on, so check the saved values before connecting a battery. I tested the Emerson off command and fan behaviour on a 52 ohm resistor, without a battery.