CAN‐FD add‐on (MCP2518FD) - dalathegreat/Battery-Emulator GitHub Wiki

Why add CAN-FD

Some batteries use CAN-FD insteaf of just CAN. Batteries like Kia EV6 are moving towards the faster and more flexible CAN-FD. The LilyGo hardware does not support CAN-FD protocol, but this can be added with an extra MCP2518FD chip via the GPIO pins, similar to the CAN add-on setup.

[!TIP] The CAN-FD chip can also be used for normal CAN. Just enable the USE_CANFD_INTERFACE_AS_CLASSIC_CAN , and you can use the add-on chip with classic CAN batteries.

Hardware

The hardware used is an inexpensive chip, "MCP2518FD Pro", which can be purchased HERE

Connecting it

lilygo-and-canfd

SCK  -> Pin 12
MOSI -> Pin 5
MISO -> Pin 34
CS   -> Pin 18
INT  -> Pin 35
GND (next to 3V3) -> Any GND pin on LilyGo
3V3  -> VDD on LilyGo
GND (next to 5V) -> Any GND pin on LilyGo (+ to GND on external 5V source)
5V   -> 5V source, can be same as feeds LilyGo via the input pins

Alternative 5V source

The Lilygo also has a 3V3 to 5V boost switch-mode power supply (it is used for the RS485 chip on the Lilygo). It does not have an overly convenient location for connecting, but it can be soldered to one side of C62 (side closest to C64). The Lilygo can then be powered with 12V, which can be more convenient than powering the Lilygo with 5V. See the red wire in the image below. Of course the 5V supply on the Lilygo must be enabled for this to work.

image

Alternative hardware

Another board built around the same "MCP2518FD Pro" chip has been shown to work once the oscillator is configured to OSC_20MHz - see details below

The labelling on this board is slightly different:

SCK -> Pin 12
SDI -> Pin 5
SDO -> Pin 34
nCS -> Pin 18
INT -> Pin 35
GND (next to 3V3) -> Any GND pin on LilyGo
3V3 -> VDD on LilyGo
GND (next to 5V) -> Any GND pin on LilyGo (+ to GND on external 5V source)
5V -> 5V source, can be same as feeds LilyGo via the input pins

NB: Only one GND connector is technically required if the same ground is being used for the LilyGo

Software setup

Start by enabling the CANFD_ADDON flag in the USER_SETTINGS.h file. Then configure the battery to use this CAN interface in the USER_SETTINGS.cpp file. Select CAN_ADDON_FD_MCP2518 on the component that you intend to connect to the chip.

[!NOTE] Remember to configure crystal according to your PCB!

Depending on your add-on board, there may be different oscillator crystals. On the "MCP2518FD Pro" board, it is 40MHz, while on some others, it is 20MHz. If you don’t have a 40MHz oscillator, you need to update CANFD_ADDON_CRYSTAL_FREQUENCY_MHZ from OSC_40MHz to OSC_20MHz in the USER_SETTINGS.h file.

Example picture, board with 40.0Mhz crystal:

image

The default settings are 500kbit/s arbitration bit rate, and 2 Mbit/s data bit rate. Incase you have a battery that needs some other bit rate settings, this can be changed in the Software.ino file.

Logging CAN-FD messages

It is possible to log CAN messages via USB serial or Webserver, see the CAN logging page for more info