ESP32-C3 and SN65HVD230 CAN module: why the Huawei R4850G2 did not answer, and how to test your module

Published 3 December 2026

Esp32CanTwaiSn65hvd230TroubleshootingHuawei

The ESP32-C3 has a CAN controller built in (called TWAI in Espressif’s documentation), so the obvious way to build a CAN controller around it is to add only a transceiver. The SN65HVD230 is the usual 3.3 V choice, and the modules are cheap. This is the first thing I tried for controlling a Huawei R4850G2 rectifier. The supply did not react at all and stayed at its default 43.5 V.

In my case the modules turned out to be defective. This article shows the test sketch I used, what I would check before blaming the code, and why a bad module is easy to overlook.

The setup

FunctionESP32-C3 SuperMini pin
CAN TX (to the module’s TXD / CTX)GPIO3
CAN RX (to the module’s RXD / CRX)GPIO4
OLED SDAGPIO5
OLED SCLGPIO6
Encoder A / BGPIO7 / GPIO10
Encoder buttonGPIO1

The firmware is the same controller idea as in the R4850G2 article: an encoder sets the voltage and the current limit, a long press saves, a small blinking NC shows that no frame has been received. The CAN frames are the same too: ID 0x108180FE at 125 kbit/s with the voltage as volts x 1024 and the current as amps x 20.

Differences from the later MCP2515 version:

  • The CAN controller is the ESP32’s own, used through driver/twai.h. No SPI, no extra library.
  • Defaults are 53.5 V and 10 A, with limits of 42 to 58.5 V and 0 to 50 A.
  • The encoder is decoded with a state table, four transitions per detent.
  • The loop handles bus-off: if the controller goes bus-off it starts recovery, and if it is stopped it restarts.
  • The frames are sent without blocking (twai_transmit with a zero timeout), and the commands are resent every second. The PSU falls back to its offline values when it stops receiving commands.

The test mode

In normal mode, a CAN controller expects another node to acknowledge each frame. With nothing else on the bus, transmissions fail. To test the hardware alone, the sketch starts the driver in TWAI_MODE_NO_ACK, which lets the ESP32 transmit without needing an acknowledgement:

twai_general_config_t g =
    TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)CAN_TX, (gpio_num_t)CAN_RX, TWAI_MODE_NO_ACK);
twai_timing_config_t t = TWAI_TIMING_CONFIG_125KBITS();
twai_filter_config_t f = TWAI_FILTER_CONFIG_ACCEPT_ALL();
twai_driver_install(&g, &t, &f);
twai_start();

With a real power supply on the bus, use TWAI_MODE_NORMAL.

There is a catch. In this mode a missing acknowledgement is not an error, so the sketch cannot tell you whether anything actually reached the bus. The code can look and behave correctly while the module does nothing.

What to check before blaming the code

  1. Power and wiring. The module needs 3.3 V, and TX and RX go to the module’s TXD and RXD, not crossed. Some modules label them CTX and CRX.
  2. The ESP32 side. A logic analyser or an oscilloscope on GPIO3 should show frames while the sketch is running. If the TX pin shows frames, the controller and the code are working.
  3. The bus side. Look at CANH and CANL with an oscilloscope while the ESP32 transmits. If TX shows frames but CANH and CANL stay flat, the transceiver is not driving the bus. A module that does this is faulty or in standby.
  4. The Rs pin. On the SN65HVD230, the Rs pin sets the mode. Tied to ground it is high-speed mode, through a resistor it sets the slew rate, and held high it puts the transceiver in standby. Most modules tie it to ground, so confirm that on yours.
  5. Termination. A CAN bus needs 120 ohm at each end. With the bus connected and powered down, you should measure about 60 ohm between CANH and CANL.
  6. Bitrate. The Huawei R4850G2 uses 125 kbit/s.
  7. Try another module. If the first four checks point at the module, swapping it is the quickest confirmation.

To make the sketch more useful for debugging, print twai_get_status_info() in the loop: the controller state and the TX error counter show whether the controller sees a working bus.

Result

The PSU never reacted, and every SN65HVD230 module I had turned out to be defective. Replacing the module with an MCP2515 CAN module, with the same encoder, display and frames, worked. That version is described in the R4850G2 article and in the two-supply controller article.

Code

Written in the Arduino IDE for the ESP32-C3 with the U8g2 library and the ESP32 Preferences and driver/twai.h libraries.

Repo: github.com/blazeB45/esp32c3_sn65hvd230_test

If you want to reuse the sketch with a working module, use it as a starting point and switch the mode to TWAI_MODE_NORMAL.