CAN Bus specification

Thread Starter

skyr6546

Joined Mar 22, 2019
73
hello everybody,

I have never used or came across CAN (Controller Area Network) I tried to collect some information about it. I found it to be more commonly used in the industry, automotive domain. I saw an example that show its use in cars to exchange information between different electronic components I want to know how it does communicate.

I found CAN specification http://esd.cs.ucr.edu/webres/can20.pdf I am reading this but I do not understand what is happening. I understand that there is a master and slaves in the communication process Master can send data to slave, or it can receive data from slave via CAN bus.

What we need to know to do firmware development ? Does CAN also have fixed signals ? Like there is one in uart, there are two in I2C and four for SPI
 

MaxHeadRoom

Joined Jul 18, 2013
28,619
What environment are you intending to use it in?
CANbus was developed for mainly automotive use, the Control Industry uses a very similar application called MODbus.
There is a development course out there explaining the MODbus details and function.
Max..
 

John P

Joined Oct 14, 2008
2,025
I'm not sure what you mean by "fixed signals", but if you mean the number of wires connecting the units, there are obviously 2 in a UART, a receive and a transmit. For CAN there are also 2 wires, but the information is encoded by "CANH > CANL" (zero) versus "CANH <= CANL" (one). Generally CAN doesn't have a "master" or "slaves", though you could designate a master if you wanted. What happens is that there are "producers" which place data on the bus, and "consumers" which need to read that information. Every producer makes a transmission at some programmed rate, provided that the bus isn't in use, so there's no need to instruct a node to make a transmission. If 2 units start transmitting simultaneously, there's a method ("arbitration") to prevent them from conflicting. Wikipedia has a pretty good article about it.
 

MrChips

Joined Oct 2, 2009
30,713
There are many communication buses in use under the common term of fieldbus. CANbus and MODbus are two examples.

https://en.wikipedia.org/wiki/Fieldbus

You need to understand the physical layer, and the protocol or data encoding layer.
To begin, understand basic UART communication and ASCII.
At the physical layer, a differential transmit/receive specification such as RS-485 is commonly used to provide reliable communication over long distances at relatively high speeds. At lower speeds, current loop is still very robust.

At the data encoding layer, data is transmitted in a packet or frame. This is where the different fieldbuses will differ. You can encode your data anyway you please as long as both the sender and receiver adhere to the same protocol. In essence, you transmit a sequence of bytes that defines the start and end of the frame, and any pertinent information such as sender ID, receiver ID, commands, data, check sums, etc.
 

Papabravo

Joined Feb 24, 2006
21,159
You said:
I am having problem to understanding all this in one context of CAN bus with specif example.

Let us start with the most fundamental concepts:
  1. Do you know how differential signaling works, and how a dominant bit is different than a recessive bit?
 

Thread Starter

skyr6546

Joined Mar 22, 2019
73
Let us start with the most fundamental concepts:
In essence, you transmit a sequence of bytes that defines the start and end of the frame, and any pertinent information such as sender ID, receiver ID, commands, data, check sums, etc.
I want to understand procedure to write a program for CAN bus The problem is that I don't have complete hardware to understand the CAN bus. I only have micro-controller But i'm still trying to understand it.

I have to understand the physical system Before writing the program. I assume an example we have micro-controller and one device. they both work on CAN protocol. Micro-controller can send data to device, or it can receive data from device via CAN bus.

My first question is, can you suggest me a any name of device that can be used as an example and is easy to understand?

My second question is that if I use any device that support CAN. I will need only two signals for transmission of data on CAN bus.?
 

MaxHeadRoom

Joined Jul 18, 2013
28,619
You make a master up using a micro-controller and also slave version, At least this is what I did for a MODbus exercise .
I used the MAX23 (RS23) just because the Pic has the serial module built in and I had the IC's on hand.
Practice writing program for each end using the specified protocol.
Make the slave show indication, i.e. LED on/off etc.
Max.
 

atferrari

Joined Jan 6, 2004
4,764
Incredibly close, you have this

I ended with three nodes communicating to each other, all programmed by me using 18F4585 micros, after reading the official document about the CAN bus and the datasheets. The transceiver were not from Microchip.
 

MrChips

Joined Oct 2, 2009
30,713
You can still play around with the data protocol without worrying about the physical layer.
Simply connect two MCUs together and use the bare metal UART TX/RX connections, 0-5V, also referred to as TTL.

If you wish, you can use a USB-to-UART bridge and communicate between an MCU and a PC with a USB cable.
 

Thread Starter

skyr6546

Joined Mar 22, 2019
73
Make the slave show indication, i.e. LED on/off etc.
I liked your idea but LED doesn't work on CAN protocol. I will need a device on the other end that works on CAN
You can still play around with the data protocol without worrying about the physical layer.
Simply connect two MCUs together and use the bare metal UART TX/RX connections, 0-5V, also referred to as TTL.
I am familiar with UART but reading say CAN is different then UART

What's the point of UART suggestion ?
 

Papabravo

Joined Feb 24, 2006
21,159
You're putting the cart way before the horse. Second question:

Do you understand the process of bus arbitration and error monitoring by all receivers?
 

Papabravo

Joined Feb 24, 2006
21,159
In order to understand how a CAN Controller works you need to understand how it uses the various fields in a message frame. In order to understand those fields it is necessary to understand the signaling and how the other nodes behave. For example a lonely node, the only node on a network, will transmit a frame continuously hoping to see an ACK in the ACK slot. If nobody is out there to do that the node will retry a transmission forever.

As a node is transmitting it's receiver continuously monitors the state of the bus. If a node transmits a dominant bit and the receiver hears a recessive bit it will throw an error frame. The converse is also true. If a node transmits a recessive bit and hears a dominant bit it will also throw an error frame. there are counters that look at the occurrence of errors and make a node go "Busoff" if there are too many errors.

The identifier field, either 11-bits long or 29-bits long is used for arbitration. Dominant bits override recessive bits, so if two nodes start transmitting at the same time the first identifier with a dominant bit will win. The other node will back off and allow the node with the lower numbered identifier to continue. This is referred to as collision avoidance.

No node will begin a transmission if it can hear another node already transmitting.

Third question: Do you understand how bit stuffing works, and how it applies to CAN frames?
 
Top