CAN Bus Library for Teensy 3.1

chadder_all

Active member
Teensy as a CAN bus controller

Moderator Edit: I've merged the many CAN bus threads and made this topic stick to the top of the Suggestions forum.

Current CAN Bus Status (June 2014)
: Teachop's FlexCAN library works on Teensy 3.1. :)

Please use this thread to discuss CAN bus for Teensy 3.1.


-------------------------------


Is it possible to use a teensy 3.0 for a CAN bus controller? A few other classmates and myself are trying to develop a supervisory computer to monitor all onboard sensors. We are thinking of using CAN for a few reasons; error detection, message priority, increased immunity to noise, etc.
If teensy doesnt support CAN, are there any other suggestions? Perhaps I can convince some people to use I2C instead.
 
Moderator Edit: This old message was written before Teensy 3.1 was released, in January 2014.

------------------------------------------

Currently none of the Teensy boards supports CAN bus.

This CAN bus shield library will probably work on Teensy 3.0. It uses the SPI library to talk to the MCP2515 chip. I just checked the code and it compiles ok (on Linux, there's a lowercase filename that needs to be edited, but a trivial thing to fix, and it doesn't matter on Mac and Windows). Of course, you'll need that shield with those 2 chips.

I do have a quick question though. If I were to look into trying that shield, or just those 2 chips somehow, what CAN devices would I use for testing?
 
Last edited:
Thanks for the link! Just to clarify, the shield allows communication between an Arduino and the 2515 controller with SPI interface and the 2551 transceiver? Please bare with me as I am very new to CAN. For each CAN device (sensors, actuators, etc.) there is a host processor that will send out (or receive) messages to the CAN transceiver. The transceiver manipulates the message so that the CAN controller can understand it. Then does the controller put the received message on the CAN bus so it is available to be used by the host processor (i.e. the Arduino/Teensy)? The CAN controller also has the ability to decide which message/node has priority.

As for the test CAN devices, would two photoreceptors attached to analog pins work? So the message being sent would be based on the value being read at the pins? I dont think I understand this
 
Let me rephrase that question...

Suppose you magically had a Teensy with MCP2515 and tranceiver chip and 9 pin connector. What would you plug into that 9 pin connector? What other CAN stuff would you have communicate with Teensy?
 
Ok now I understand. There are going to be quite a few inputs and outputs but here are a few: throttle sensor, brake sensor, traction control system, BMS error, Emergency kill switch, ready indicator, battery temperature sensor. Those are the more important ones of a long list. Pretty much the supervisory computer has to indicate whether any of the systems fail and if they do the battery has to be disconnected immediately.
 
Paul,

Would my next step be to purchase the MCP 2515 and 2551 along with the shield? Then setup a basic network to see if the teensy supports CAN? I am really excited to work on this project
 
Hi Paul,

I just noticed the 3.1 is CAN enabled. Ive done my research and understand more or less how a CAN network operates. With the CAN controller integrated into teensy, all I would need is a transceiver like the MCP2551/2561 to take the differential signals from the CAN bus and transmit a 1 (recessive) or 0 (dominant) to the CAN controller to then be processed by the teensy. In my case, we have these nodes that are putting data on the CAN bus to be processed by the supervisory computer. I assume the data being put on the bus from the nodes contains message ID, message length, message, etc. otherwise we would have now way of telling which node is trying to "speak".

Anyways, what I am trying to get at is what does the CAN controller do? Does it just make it easier for the teensy to do its thing? I have read it has built in error handling functions.

Also, is the CAN controller hardware that needs to be programmed to handle these errors? Is that what a CAN library would do?

Many thanks!
 
say you want to put a message on the CAN bus, does the controller automatically frame the message or do you have to write functions/libraries to do so?
 
The driver chip just handles the electrical driving on the bus.
The controller handles sending a frame, which consists of lead bits, header, control-bits, data-length, data, checksum, and follow bits; and also does bit-stuffing and error detection and correction.
CAN was invented by Bosch for cars and trucks, and there is a lot of info on the net, e.g. http://en.wikipedia.org/wiki/CAN_bus and the original spec at http://www.bosch-semiconductors.de/media/pdf_1/canliteratur/can2spec.pdf
CAN controllers differ quite a lot. The MCP2515 is quite basic. The built in CAN controller in the Teensy 3.1 is more sophisticated, and has a number of 'mail-boxes', each of which can be used to receive particular messages, or to send messages. The messages can be filtered on the header field. and matched messages can cause automatic replies.
BTW, you have to have two CAN nodes on a bus to get it to work, otherwise the CAN controller will hang.
 
CAN support /library

Hi All -

If there is no CAN support for the FLEXCAN in Teensy 3.1, then I will take a stab at a very basic library.

I am thinking:
Can_setup( id, rate)
Where id is channel number, rate is an enum(125000,...),
And returns 0=fail, 1=success
Can_send( type, header, length, &data)
Where type is enum(standard, extended), header is 11 or 29-bit, length is number of data bytes,
And returns 0=fail, 1=success
Can_receive( type, header, length, &data)
Where type is enum(standard, extended), header is 11 or 29-bit, length is number of data bytes,
And returns 0=fail, 1=success

Filtering and other stuff on request.

David
 
CAN Bus Library?

It looks like Teensy 3.1 includes support for CAN bus though it doesn't look like there's any library or other documentation that supports it. Any idea on when there's be support for the CAN bus?

Thanks!

- Peter
 
It looks like Teensy 3.1 includes support for CAN bus though it doesn't look like there's any library or other documentation that supports it. Any idea on when there's be support for the CAN bus?

Thanks!

- Peter
Paul posted a few days ago that a CAN library for T3 is in the TODO list - a few weeks out.
 
Paul posted a few days ago that a CAN library for T3 is in the TODO list - a few weeks out.

Excellent, thanks for the info!

BTW, I had done a search for CAN bus but the forum engine returned nothing. Seems a bit strange to me.
 
there is Arduino (AVR) code for the CAN bus... in the model railroad world. I found some with Google's help.
 
I merged the many CAN bus threads.

Please use this threads to discuss CAN bus. If you see people start new threads on CAN bus, please direct them to post and subscribe on this thread.

Having it all in 1 thread will really help in a few weeks when I start actually working on the CAN library.
 
Hello Everyone,

I am newbie to CAN Bus, I have done some google on it, but i want some clarification.

1.If am having CAN controller inbuilt on my Microcontroller(say STM32), it is having CAN_H and CAN_L. Can i connect these CAN_H and CAN_L lines to other CAN device to form a CAN network. Is CAN tranceiver is needed? or can i connect One CAN device CAN_H to other CAN device CAN_H and same for CAN_L also.

2. If i want to send some message to CAN bus, how and where can i send, since there is two lines CAN_H and CAN_L. and through which pin will receive data from the BUS. is there any transmitter and receiver Pin as in UART

3. What is the difference between CAN and CANopen. Normally CAN data rate is max 1Mbps, is CANopen also has same datarate
 
I am newbie to CAN Bus, I have done some google on it, but i want some clarification
1. Yes you need a CAN transceiver, it won't work to just connect between parts CAN-TX and RX directly. Also include termination (resistors).
2. CAN is different from a UART. The UART has TX and RX that can operate at the same time, called full duplex. The CAN uses a single pair of wires in differential mode for noise immunity (some sort of ground reference is still needed too). The CAN bus can transfer information both ways but can only talk in one direction at a time, called half duplex.
3. CANopen is an additional protocol layer on top of the CAN bus. It can run at different rates, and 1Mbps is one of them.

Edit: Fixed TX/Rx oops thanks pawelsky for pointing it out!
 
Last edited:
Back
Top