Transmitting / relaying CAN messages over I2C

Hi, I have a set up where I have Solar inverters talking to a battery pack but don't have enough CAN ports.

At the moment 1 CAN port is used for 1 inverter, 1 port for another inverter and one port for the battery. I'm using a TEENSY 4.1 as an Arduino was too slow. What I would like is for the Teesny to be able to relay the battery's CAN messages (possibly with modification) to another Teensy or Arduino over the I2C network so I can send messages to 3 more inverters.

Has anyone done similar or could point me in the right direction.

not quite sure about your set up but CAN is not a P2P connection but rather a network of controllers communicating on a shared connection(bus).

A Brief Introduction to Controller Area Network

1 Like

Thanks, I'm aware of what CAN is but I'm changing the CAN messages to each inverter.

I get that battery message is 'modified' and re-ransmitted to inverter on the 2nd CAN bus but if I'm guessing this right, you want to send different values to each inverter for each received battery message for whatever reason. hence why they cannot all be on the same CAN bus, right?

my approach would be to enable/disable comms to each inverter as required if that is possible, but probably the 'easiest' solution in your case would be to get some MCP2515 boards to add extra CAN buses and connect the to your Teeny over SPI.

Multiplexing the 2nd CAN bus between the inverters might also be an option.

hope that helps...

Yes, for example the battery will send a message that the maximum current that it requires is 100Amps. If that message goes to 3 inverters then the battery would receive 300A. If I just split the battery message to another Teesny then that only gives me 2 additional CAN ports and doesn't allow me modify the messages between the Teensys. For example if one inverter is already supplying 20A then the other inverters need to know that the max battery current is now 100A-20A = 80A

I don't want to disable comms to individual inverters, that just seriously complicates matters and leads to potential problems. I don't think its possible to add any more MCP2515 boards, I'm at the max.

U've used even the SPI pins...?

If it was me I would try to find a way to rationalise my pin usage to allow me to add the CAN boards as it would be then be much easier to manage within code IMHO. SPI would be common between them + x1 CS pin per added board.

how you want to interface your stuff is up to you really....

Interesting, Would the library's work using the SPI pins as well as the CAN pins?

At the moment I'm using this board which is really neat and have another the same that I was going to use if I can communicate between them.

not really worked with Teeny's tbh but look at the pinout information I share in reply #6, if make use of MOSI,MISO, SCK and not MOSI1,MISO1, SCK1 as your SPI port they should not interfere with CAN pins ie (CRX1/CTX1, CRX2/CTX2, CRX3/CTX3).

As for the MCP2515 library, it should be plug and play.

bear in mind that the MCP2515 board are usually 5V. so unless the Teensy pins are 5V tolerant you may also need a level shifter.

on a side note, if you have a second board already available, then probably worth exploring connecting those 2 together as you have already considered.

I see that board had a ethernet port built-in so why not sent a server-client connection between the 2 to transfer the CAN data.

The Teensy connected to the Battery pack would be the webserver and the one connected to the other inverters would be the client.

There is already some example codes available so would not be a big jump to modify then :wink:

or more simply just try using one of the serial ports to connect the 2! :slight_smile:

hope that helps....

Thank you for your help, gives me a few things to consider.

I had thought about the LAN connections and I do use MQQT to send data from the Teensy so also considered that. I'm trying to make it as fail safe as possible as we run it off grid, so if it fails the power goes off. The inverters need to see the CAN battery data, as if not, they shut down. If I can put everything in one small box next to the batteries and inverters, with it's power directly from the batteries it avoids network switches etc.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.