Using CAN module with Leonardo and the V2.04 SimpleFOCShield?

Hi folks,
I’m new here, but definitely learning fast! Loving the SimpleFOC shiels, so accessible and easy to work with. Hopefully moving on to a pair of B-G431B-ESC1 and their inbuilt can interface after de-bugging with the shields.

I’d like to use a CAN module to communicate with my Leonardo and 2 stacked SompleFOCShield’s. Is there anywhere that identifies which pins are used by the shield and which aren’t? The CAN module uses the following connections to the Leonardo:

|MPC2515 - VCC|+5V|
|MPC2515 - GND|GND|
|MPC2515 - CS|D10 (SPI_SS)|
|MPC2515 - SO|D12 (SPI_MISO)|
|MPC2515 - S I|D11 (SPI_MOSI)|
|MPC2515­ - SCK|D13 (SPI_SCK)|
|MPC2515 - INT|D2|

See: MPC2515 Module Example

I think I’ve seen some where that SPI encoders will work, so does that man I can use that IO for the CAN module?

Any constructive thoughts would be much appreciated.

Many Thanks
Barry M



Welcome to the forum.

Probably yes.

Long answer. You need to be very familiar with SPI and also know that the shield itself does not communicate with SPI. On Leonardo the SPI pins are kind of on the tail of the board, so they have nothing to do with the SimpleFOC boards you will stack up. The shields will not touch the Leonardo SPI pins. In other words, these are physically separate from the SimpleFOC shield and stacking them up w.r.t. SPI doesn’t matter at all.

Secondly, just to clarify, you need MCP2515 to communicate to Leonardo as a CAN gateway?

I’m not sure Leonardo has enough memory and computing power to run two motors and SPI-CAN library on top. You better check. It’s a 16 MHz ATmega32U4 chip with only 32K flash memory. I mean, you will definitely make it work but your use case may be too much for that small chip. As a comparison the B-G431B-ESC1 stm32g431cb is 170 MHz and has 128 KB Flash.

Perhaps @runger could provide more constructive input.


Hey, I haven’t checked the pins, but basically you’d have to check all these pins aren’t used by the 2 simpleFOC shields…

In terms of trying to control 2 motors and do CAN on the ATMega, I think it will be super-hard, if it’s possible at all… you’ll be really short of both MCU power and memory. Personally, I would not even attempt it, and instead go straight to a STM32 F4 or G4, or ESP32 MCU… these will have the kind of power needed for this job…

Thanks @runger & @Valentine, I’ve taken your advice and got a mega, there definitely wasn’t enough space on the Leonardo or UNO. I’ve got my motors working now, on to the CAN based comms implementation!

Many Thansk
Barry M

1 Like