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
2
votes
3 answers

Regarding CAN bus

I am using a 16-bit MCU PIC24HJ64GP504 to write a CAN based application. Basically it is communication between my board and one another node which continuously keeps on sending data to my board using CAN at 1 Mbit/s. I am configuring the ECAN module…
2
votes
2 answers

How do I access(open/read/etc) /dev devices from a kernel module?

I have received a driver (PCAN driver for PCI card, using rtdm), that creates /dev/pcan0 and /dev/pcan1 is compiled as a netdev driver. There are many facilities that come with this driver, but they are all targeted at a user-level program reading…
Shahbaz
  • 46,337
  • 19
  • 116
  • 182
2
votes
1 answer

How to parse CAN Frames from a DBC using QT and C++?

so I have this code here : #include "qcanbusframe.h" #include #include #include #include #include int main(int argc, char *argv[]) { …
Sc0Pe
  • 21
  • 3
2
votes
0 answers

Can read CANBUS socket, but not write to it

I'm converting a Windows program to Linux and I have some problem writing to the CAN bus. Trying write or send returns -1 with errno as "No such device or address" Some simplified C code: int s = socket(PF_CAN, SOCK_RAW, CAN_RAW); if (s < 0) {…
dargaud
  • 2,431
  • 2
  • 26
  • 39
2
votes
1 answer

Reverse engineer CRC/checksum algorithm in CAN messages

I have a device that is exchanging messages on a CAN bus. I am trying to reverse engineer the protocol being used. I can decode the protocol (or most of it), but I am struggling to reverse engineer the checksum/CRC being used (without it, the device…
2
votes
1 answer

How can the value of an argument in a function called from a signal handler be different from the value passed in?

Updated question - first version below I have set up a custom signal handler to buffer frames being removed from a CAN interface. In the handler, I block the signal first, and unblock it last, using pthread_sigmask(). In bufferMessageDirect(), the…
Walkingbeard
  • 590
  • 5
  • 15
2
votes
0 answers

python CAN implement a message counter

I am trying to use Python CAN, with Vector CAN interface to implement sending cyclic messages to an actual ECU. The message I am sending let's call it TorqueDemandMsg, it has 4 bit rolling counter MsgCounter as one of the signal, so that the ECU…
Summerle
  • 73
  • 1
  • 5
2
votes
0 answers

What is the python-can equivalent of sending socket CAN message?

I have code that communicates with a motor over CAN, originally written to work on a Linux machine. I want to run it on Windows, and I believe the socket-can libraries are not supported for Windows, and so I am trying to use python-can instead. The…
ITregear
  • 21
  • 3
2
votes
1 answer

Equivalent tool of Kvaser Database Editor on Linux

What's a Equivalent tool of Kvaser Database Editor on Linux? The only GUI tool I found is SavvyCAN and Wireshark CAN plugin. But both tools are for viewing logged data. enter image description here enter image description here I can't see the…
newnavi
  • 23
  • 4
2
votes
0 answers

Python, cantools - How to resolve overlapping signals issue

I work with quite large sym database with some (multiplexed) messages containing overlapped signals. I am using this database to decode a CAN communication log files in asc format. It works well unless the message has overlapped signals. This causes…
Karkar
  • 46
  • 4
2
votes
2 answers

How to search a .dbc file for a specified string

I'm developing a python program the reads information from a *.dbc file dbc_path_in = Path(path, dbc_directory) dbc_files = {"CAN": [(dbc, 0) for dbc in list(dbc_path_in.glob("*" + ".dbc"))]} print("dbc_files = " + str(dbc_files)) The dbc file I…
2
votes
1 answer

Fast CAN communication using sockets in C++

I'm trying to use C/C++ to communicate with a CAN bus. I'm using sockets to read and write on the bus. I've created a write thread and a read thread. The read thread is constantly trying to read and the socket, and when a write request arrives, the…
boubside
  • 61
  • 2
  • 5
2
votes
1 answer

Appending hex values to a list/converting string lists to hex

I have a dataframe where each row is a CAN message which has to be in hex. But when I put the rows into a list, individual values are stored as strings. For example: ['0x0', '0x0', '0x0', '0x0', '0x0', '0x0', '0x0', '0x1'] Is there a way to have…
siddheshk
  • 55
  • 5
2
votes
1 answer

can0 listen can-bus but no data appears

I'm trying to read a CAN-BUS on a vehicle with a raspberry (CAN is connected to DB9 connector on the raspberry). The vehicle provides energy to the raspberry also. Here's my stack: Protocol CAN "ISO 15765 CAN" by Bosch CAN-Bus Board PiCAN3 machine :…
wajisan
  • 94
  • 6
2
votes
1 answer

CAN-shield with MCP2515 on Raspberry Pi 4 B with Ubuntu

I would like to run a CAN shield with MCP2515 controller connected to a Raspberry Pi 4 Model B. It already worked under Raspbian but because I need ROS2 I want to run it under Ubuntu (20.04) now. Here it does not work anymore. What I did was editing…
Jonas
  • 33
  • 1
  • 5