Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to get SOF, EOF, CRC etc of a CAN Frame.

Vindsan

New Member
I have a CAN device to which I am trying to communicate using a CAN Ethernet adapter. Adapter is the PCAN Ethernet Gateway DR. So I have set up the ID address and set everything up and then I communicated with the CAN device which is the IVTS from ISAscale using the PCAN software called PCAN View and it worked perfectly. But the problem is in the software I only need to enter the CAN ID and the Data and software calculates everything else like Start of Frame, CRC check, End of Frame etc. I am trying to write a program where I just send the entire CAN Frame via TCP/IP and receive its response., but I don't know how to calculate the entire CAN frame. I have the CAN ID and the Data to send from the datasheet of IVTS from ISAscale, but rest of the data for CAN frame I have no idea. Can you please educate forward me to any link or source on how to calculate the remaining stuff for a CAN frame. Thank you.
 
The CAN specification should be available from multiple sources. Here for example:

The SOF, or Start Of Frame is a single dominant bit. (see p. 43 of the CAN specification)

The EOF, or End Of Frame is a sequence of seven recessive bits (see p.14 of the CAN specification)

The CRC polynomial is:
1721918415075.png

(see p. 13 of the CAN specification)

Normally people don't worry about the details of a CAN frame that are handled in hardware when encapsulating a CAN frame inside another protocol. For example, I once developed a CAN to RS-232 to CAN bridge that worked flawlessly in both directions. This is all accomplished with the identifier, the data length, and the data. No other information needs to travel across the RS232 link.
 
When sending a CAN frame, you usually have to consider checking whether something else is already transmitting, and arbitration, which is where two devices start transmitting at the same time, and the one with the higher frame ID stops and tries later.

For those reasons, you don't know when the frame will be sent or whether it will need more than one attempt because of frames with a lower ID being transmitted. It is much easier to leave all of that to dedicated hardware, called a CAN engine, and only the ID and the data are sent to the CAN engine.
 
When bridging CAN to another network all of the Data Link Layer and hardware level stuff is mostly irrelevant.
 
The easiest way is to download code for a micro and understand it.

I use CAN on the PIC32 and the PIC18 both use the same library.. But as CAN is a hardware implementation trying to run a software driven is quite difficult... CAN run fast... very fast.. One of the reasons why it is used instead of RS485 as you can achieve close to real time data. Ergo! not something you can write.

There are stand alone CAN transceivers but then you have to talk to them via "A.N.other" protocol, which defeats the object.. I can talk to several CAN devices very fast. If you are using a computer, there are CAN modules that connect to USB and Ethernet to get the same results.. But try not to write a complete packet.
 
I wrote my own code for the PIC 18F585, IIRC, to implement a basic network. I cannot remember what transceivers I used.
Pure Assembly.

Against the advice of testing it in an already working nework (had none handy), implemented a 3-node one.

Worked at the first try.
 
A single lonely node on a terminated cable is very useful in making sure your transmitter is working properly. Why is that? It is because a single lonely node will never hear an ACK in the ACK slot and will retransmit the first frame it is given forever.
 
Actually I made a mistake. There is a developer documentation for this PCAN ethernet gateway adapter. I didnt read it when I posted it and found out later and read it. But still because of my inexperience with CAN i am not sure how to do it.
1722245320529.png

Length is something I can calculate at the end when I have all.
Message Type is 81
Tag is not needed.
Timestamp - I dont know. Should I leave it blank or just put 0 since it has no effect on transmission.
Channel is not needed.
DLC can be calculated from the CAN data.
CAN ID - I am not sure. So for the IVTS I connected to the ethernet adapted one of the CAN IDs I am using to communicate is 0209h. I am assuming that is the value that I need to enter here or is it some other value.
CAN Data is extactly the CAN Data which I need to give. For eg for my IVTS I will use 2402h. That is 4 byte and remaining 4 byte I will just put it to 0 and on top for DLC I will enter 4. I am assuming this is the correct way.
And finally CRC32. This is where the main problem is.
1722246788488.png

This page doesnt make any sense. It doesnt tell me how checksum is calculated. I tried entering these values in some online checksum calculator and was getting different values. This is what is confusing me.
I have also attached the whole document. Kindly do help me. Thank you.
 

Attachments

  • 1722246766253.png
    1722246766253.png
    1,022.2 KB · Views: 100
  • PCAN-Gateways_Developer-Documentation_eng.pdf
    1.5 MB · Views: 130
What you are looking at is a template for encapsulating a CAN frame inside an Ethernet frame. This encapsulation adds a few things that are not present in an actual CAN frame and eliminates things that are not relevant. You will notice in particular that the 15 bit CAN CRC is not present in this encapsulation. In order to compute the correct CRC you need to use the correct polynomial which is given by 0x04C11DB7.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top