Questions tagged [can-bus]

Controller Area Network (CAN) bus is a networking technology typically used in cars and other vehicles. It supports deterministic priority arbitration with multiple transmitting nodes.

The CAN bus is a serial bus that allows multiple masters and uses a broadcast model. A message start with an ID, can contain up to eight data bytes (64 data bytes for CAN FD) and uses non-return-to-zero encoding. Each node can receive, but only one can send at each point in time. It uses CSMA/CA algorithm for bus access. The lower the (numerical) ID, the higher the priority. Short networks (below 40 m) can achieve bit rates up to 1 Mbit/s.

A distinguishing feature of CAN is that when two nodes with different message identifiers attempt to transmit at the same time, there are no collisions (CSMA/CA). The higher priority message will go through without any need for the sender to re-transmit it. This ensures that a CAN system can never get into a live lock state in which two nodes would continually re-send the same two messages, and continually collide with each other.

A newer version/generation called CAN FD was recently developed. It supports higher clocking of the data portion of the message, allowing up to 64 bytes of payload.

Tag usage:

  • Use this tag for all questions related to CAN or CAN FD software/firmware: drivers, controllers, communication, frames etc. Please note that hardware questions are off-topic and should be asked at https://electronics.stackexchange.com instead.
  • It is recommended to combine the tag with , to draw more attention to the question from the right kind of people.
  • If you are using a particular programming language (say, ), you should add that tag as well.
  • If the question is about higher layer protocols such as CANopen, J1939 or DeviceNet, the tag should be combined with the applicable higher layer protocol tag.

Links:

1162 questions
22
votes
2 answers

How to create virtual CAN port on linux? (C++)

I want to create program that would emulate CAN port for testing purposes for another big application. Program should send previously recorded data through this virtual CAN. Anyone has any experience with such thing? I'm thinking to establish…
Michał Zubrzycki
  • 845
  • 3
  • 11
  • 20
21
votes
7 answers

How to program a simple CANopen layer

We have a robot project where the motor controllers use CANopen for communication. I need to communicate with these motor controllers using a master microcontroller. The problem is that I need to develop a CANopen layer in this microcontroller, but…
user150908
15
votes
1 answer

CAN communication between LPC 2292 and LPC1758 boards "Start of Frame " error

I am trying to setup CAN communication between a couple of LPC device nodes. My setup includes a couple of CAN nodes writing on to the CAN bus. For example LPC 2292 CAN controller can write on to the CAN bus and the LPC1758 can receive the data.…
rockstar
  • 3,512
  • 6
  • 40
  • 63
13
votes
1 answer

Java and CANopen

Background I am required to create a Java program on a laptop to receive/send CANopen messages. RJ45 is chosen to be the network's physical medium. I am new to CANopen and Java communications programming. Pardon me if I appear to be uninitiated. The…
frustratedone
13
votes
2 answers

boost::asio over SocketCAN

I was thinking of making use of Boost Asio to read data from a Socket CAN. There's nothing fancy going on in linux/can.h , and the device should behave like the loopback interface, and be used with a raw socket. Looking at the basic_raw_socket…
farnsworth
  • 349
  • 3
  • 13
12
votes
1 answer

write: no buffer space available socket-can/linux-can

I'm running a program with two CAN channels (using TowerTech CAN Cape TT3201). The two channels are can0 (500k) and can1 (125k). The can0 channels works perfectly but can1 runs a write:No buffer space available error. I'm using…
avelampudi
  • 316
  • 2
  • 6
  • 16
11
votes
2 answers

Heavily confused by candump (SocketCAN) ID filtering feature

In a nutshell, I want candump to show me ONLY frames with IDs 0x00200200 or 0x255. So I do this: candump can0,00200200:0,255:0 But this gives ALL frames, and each frame is shown twice. i.e. the output of: cansend can0 256#112233 would be…
Erik Nyquist
  • 1,267
  • 2
  • 12
  • 26
8
votes
3 answers

Sharing virtual network with docker container

I am working on a project that requires me to create a virtual CAN network on my host machine $ sudo modprobe vcan $ sudo ip link add dev vcan0 type vcan $ sudo ip link set up vcan0 My ifconfig : My question is how can I share this interface with…
Ansh David
  • 654
  • 1
  • 10
  • 26
8
votes
2 answers

How are transmitted CAN messages acknowledged on CAN bus by other nodes?

I know a dominant acknowledge bit is sent by the receiver of the message which is transmitted by another node. The thing I am not able to grasp is whether a single dominant bit is sent by the receiver after the entire message is received or the…
Sachin Kedar
  • 93
  • 2
  • 7
8
votes
8 answers

Casting struct to int in c++

I have a structure to represent the 29 bit CAN identifier with bit fields as following. struct canId { u8 priority :3; u8 reserved :1; u8 dataPage :1; u8 pduFormat :8; u8 pduSpecific …
Paindoo
  • 173
  • 3
  • 8
8
votes
1 answer

Socket-CAN virtual bus

How can I create several virtual sockets and link them together to create a virtual bus? I want to simulate an application in which many nodes communicate to each other via CAN.
Shabbir Hussain
  • 2,600
  • 2
  • 17
  • 25
8
votes
3 answers

Canplayer won't replay candump files

I'm trying to use canplayer to replay some candump files, with no success. When I try to run the canplayer it just executes and returns, giving me no clue of what is happening. What I've tried up to now: Setup 1 Set up a vcan interface Sent…
Arthur Nunes
  • 6,718
  • 7
  • 33
  • 46
7
votes
2 answers

How to make CAN bus operate from within a docker container?

I successfully dockerized my nodejs app running on a Beaglebone black. But now I'd like to access to the CAN from within the docker container but it doesn't work. Note that I successfully configured the CAN ports in the host and candump shows it…
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
6
votes
11 answers

What happens if a bus-off error occurs in a CAN controller while a car is in motion?

I know that in a CAN controller if the error count reaches some threshold (say 255), bus off will occur which means that a particular CAN node will get switched off from the CAN network. So there won't be any communication at all. But what if the…
Jeganraj
  • 383
  • 2
  • 4
  • 9
6
votes
2 answers

SocketCAN: Filtering of frames with certain CAN IDs not working

I'm trying to filter CAN frames with certain IDs as described here: https://landlock.io/linux-doc/landlock-v8/networking/can.html#raw-protocol-sockets-with-can-filters-sock-raw Part of my code: struct can_filter rfilter[4]; if ((s = socket(PF_CAN,…
ci7i2en4
  • 834
  • 1
  • 13
  • 27
1
2 3
77 78