Hi all
short question. Is there a workaround or a solution to use the Sparkfun Can Bus Shield with a Teensy 4.0 together with the mcp_can libary?
I am trying everything to get it up to live, but without any success.
Any help much appreciated
Thanks Fabian
You might try posting the same in the Teensy forums too 
Hi, good point. But maybe you can give some Info about the minimal pins I have to use. Hereby I mean if I just want to use the Sparkfun Can Bus Shield, but only isolated the Can functions. I have used D10-13 plus 2. But it is not working.
A few things for you to look into:
-
The Teensy 4.0 has three SPI ports available. The mcp_can library appears to, by default, use whatever port is wrapped in the instantiation of the SPIclass that is named âSPIâ. This is probably the one tied to pins 10-13 on the Teensy, but you could do a loopback test - connect MISO to MOSI - and make sure any data you send gets immediately returned. If it isnât, there is a second constructor for the MCP_CAN class that will let you specify the SPIclass instantiation to use.
-
You mention the SPI connections you have between the Teensy and the CAN BUS shield, but you didnât mention power. I assume the Teensy is getting powered from the USB connection, but are you also passing the 5 V and ground over to the CAN BUS shield? Or perhaps the shield has its own dedicated power? Iâm guessing youâve thought about the power, but since it wasnât mentioned and no schematic was provided, I just wanted to verify.
-
The Teensy I/O pins are not 5 V tolerant (per the documentation I found), but the CAN BUS shield requires 5 V to operate (the MCP2515 can run on 3.3 V, but the MCP2551 cannot). This means youâll need level shifting between the two. What do you have providing this functionality, and have you tested it to ensure it works?
Without having more information about your setup, the testing youâve done, and the results of those tests, the above is just some ideas that came to mind. I canât guarantee anything will pan out from them, but maybe it will give you something to check into.
Best of luck!
Mike
I just did some more googling about Teensyduino and it does seem like the âSPIâ object is defined to use pins 10-13, so the first item in my post above is probably moot. It may still, however, be worth doing a loopback test, or at least probing the pins, to ensure the Teensy is at least trying to talk over SPI.
Mike
Hi Mike thanks a lot for your reply.
To number 1) I will check this over the weekend.
2) The Can shield receives from a separate source the VCC and GND - so this should be fine but
3) I was believing that the Teensy Pins can take 5V, thats new - I will double check it and if needed implement a level-shifter inbetween.
Do you know if my pins are the right ones or do I miss some pins just for the Can functionality?
Thanks a lot, BR Fabian
Hi all
checked it yesterday. I have now used another Teensy 4.0 with level shifters and again tried it.
Not working.
When I connect the INT 2 Pin to Ground it is trying to initiate the module and falling in a kind of loop mode.
âCan´t initâ is then the only message
If the INT2 Pin is connected to +3.3V same message but it is going through the code.
The pins in general are working, when I load up a code for a display and connect the pins accordingly to it, works like a charm.
Is there some info missing about the CAN Module?
Are the D10, 11, 12, 13, GND, 5V (supply) and the Pin 2 the only ones or do I need more.
Next idea would be to really connect the module via jumper cables to the Redboard Plus and then remove one after the otherâŚ
Any other ideas?
Thanks a lot,
BR Fabian
Aside from power (5 V and GND), the only thing you need are the SPI connections (SCK, MISO, MOSI, and CS) so the Teensy can talk to the MCP2515 on the CAN BUS shield. Based on what information youâve provided, I would expect the connection to be:
SCK - Teensy pin 13 to shield pin 13
MISO - Teensy pin 12 to shield pin 12
MOSI - Teensy pin 11 to shield pin 11
CS - Teensy pin 10 to shield pin 10
As for the INT pin, you donât technically need this. There are two means to operate the MCP2515 - repeatedly poll the chip to see if a message has been received, or let it generate an interrupt when a message arrives. Iâm not sure what method the mcp_can library is designed to use, but I hope it gives the user the option to choose.
What intrigues me is you mention connecting the INT 2 pin to ground and to 3.3 V. You shouldnât be connecting this to either power rail, it goes to an input pin on the Teensy which is capable of generating an external interrupt. You can then create an ISR to process the incoming message. You might try leaving this disconnected to start and see if that at least gets you past the âCanât initâ stage.
Mike
1 Like