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

Why add another CAN channel?

Some Inverters do not like to see automotive CAN frames on the CAN channel meant for stationary storage. When they see these messages, they enter a fault state. To get around this, we can add an additional MCP2515 chip to the LilyGo, to get an isolated secondary CAN bus.

How to add an MCP2515 chip?

The solution is to add a separate CAN channel, via an additional MCP2515. The additional MCP2515 can be connected to the Lilygo in multiple ways.

Option 1: MCP2515 powered via 5V (easiest no-solder method)

If you want to avoid soldering and just use the MCP2515 module, supply the VCC pin on the MCP2515 module with 5V.

image

Option 2: MCP2515 powered via Lilygo VDD pin converted to 5V

As a 5V pin is not directly available on the Lilygo, it would be ideal if the VDD pin can be used to power the MCP2515 board. This can be achieved in the following manner.

The MCP2515 modules widely available have a 5V only CAN transceiver (TJA1050). The Lilygo has a 3.3V CAN transceiver (SN65HVD231). The Lilygo also has a level shifter circuit already provisioned on board to use 5V transceivers. Therefore, it is viable to change the voltage from 3.3V to 5V and solder the 5V CAN transceiver from an MCP2515 module onto the Lilygo board. This requires basic SMD reworking skills.

This solution reduced the need:

  • for an intermediary level shifter board to 5V
  • to pick up 5V from a component pad on the Lilygo
  • for an external supply of 5V.

After the chip swap is done, another MCP2515 module can be powered from the VDD pin of the Lilygo.

Steps for making the Lilygo use a TJA1050 CAN transceiver and supply 5V.

  1. With a hot air soldering gun remove the CAN transceiver (SN65HVD231) from the Lilygo and swap the CAN transceiver from the MCP2515 (TJA1050) onto the Lilygo. An alternative to desoldering the TJA1050 from an MCP2515, is to buy a TJA1050 chip, and solder it to the Lilygo.
  2. Move resistor from RF to RD. Since it is a zero Ohm resistor you can remove the RF resistor and put a blob of solder or wire in RD. This will power the transceiver on the Lilygo with 5V. ⚠️ Do not power up the board before swapping the 3.3V transceiver for the 5V transceiver.

lilygo-schematic lilygo

Wiring diagram

These pins need to be connected between the LilyGo header and the MCP2515 board:

Pin on MCP2515 board MCP2515 board comment Pin on Lilygo Lilygo comment
MCP2515_SCK SCK input of MCP2515 Pin 12
MCP2515_MOSI SDI input of MCP2515 Pin 5
MCP2515_MISO SDO output of MCP2515 Pin 34 Pin 34 is input only, without pullup/down resistors
MCP2515_CS CS input of MCP2515 Pin 18
MCP2515_INT INT output of MCP2515 Pin 35 Pin 35 is input only, without pullup/down resistors
GND Any GND pin on LilyGo
VCC Any VDD pin on LilyGo if you performed chip swap. If no chip swapped, this pin needs 5V

bild

ℹ️ Note on crystal

The extra board has either an 8Mhz or 12Mhz crystal. Be sure to set the correct value in USER_SETTINGS.h if needed. This line: #define CRYSTAL_FREQUENCY_MHZ 8 //CAN_ADDON option, what is your MCP2515 add-on boards crystal frequency? can be changed to 12 if there is an 12Mhz crystal on the board

bild

Software configuration

When using the MCP2515, make sure that the can_config inside USER_SETTINGS.cpp is defined correctly. Be sure to add the CAN_ADDON_MCP2515 to the component that is connected to the add-on-CAN

image

Also make sure the option #define CAN_ADDON is enabled in the USER_SETTINGS.h

image

Troubleshooting steps

If you are having problems with the MCP2515 add-on chip not detecting/sending any CAN messages, check the following:

  • Check that you have #define CAN_ADDON enabled, and the interface configured
  • Check that you have the correct crystal setting!
  • Check that board is fed with 5V
  • CAN termination OK?
    • With everything off, do you have 60 Ohm between CAN-H and CAN-L? If not, add 120 Ohm termination resistors to the ends of the CAN network
    • The MCP2515 board has a jumper (J1) which you can enable to get a 120Ohm termination resistor
  • Verify cabling is correct
    • Take a multimeter, and flip the both boards upside down. Then with everything OFF, measure continuity for each pin pad on the bottom between MCP-LilyGo. All pins should have good continuity. If you have high resistance, you might have a corroded pin somewhere.

End result

End result, extra CAN channel added:

bild