RPI - CANOpen: Difference between revisions

From SoftwareGuy
Jump to navigation Jump to search
Mark (talk | contribs)
Mark (talk | contribs)
Line 36: Line 36:


=== frame ===
=== frame ===
The CANopen frame contains the arbitration field (12 bits) and data fields (8 bytes)[[File:Fig1.1.png|thumb|alt=CAN frame|right|CANopen frame sequence]]
The CANopen frame contains the arbitration field (12 bits) and data fields (8 bytes)[[File:Fig1.1.png|thumb|none|upright=0.35|CANopen frame sequence]]


=== arbitration ===
=== arbitration ===
The arbitration field contains an 11 bit identifier (COB-ID) which describes the message types.  The cob-id defines the message priority, 0 is the highest, 0x7ff is the lowest.  It also contains a 1 bit RTR (remote transmit request).  This requests a response from the target device.  [[File:Fig1.2.png|thumb|right|alt=Arbitration Field|Arbitration Fields]]
The arbitration field contains an 11 bit identifier (COB-ID) which describes the message types.  The cob-id defines the message priority, 0 is the highest, 0x7ff is the lowest.  It also contains a 1 bit RTR (remote transmit request).  This requests a response from the target device.  [[File:Fig1.2.png|thumb|none|upright=0.35|Arbitration Fields]]


=== NMT ===
=== NMT ===
NMT messages have cob-id of 0 (zero).  These messages request the communication state of the node-id (data byte 2) be set to the designated state in data byte 1.[[File:Fig1.3.png|thumb|left|middle|NMT message structure]]
NMT messages have cob-id of 0 (zero).  These messages request the communication state of the node-id (data byte 2) be set to the designated state in data byte 1.[[File:Fig1.3.png|thumb|left|middle|NMT message structure]]

Revision as of 15:30, 30 November 2023

Links

https://www.autopi.io/blog/canopen-simple-introduction-explained/

https://copperhilltech.com/cangineberry-canopen-module-for-raspberry-pi/

https://www.seeedstudio.com/CAN-BUS-FD-HAT-for-Raspberry-Pi-p-4742.html?gad=1&gclid=Cj0KCQjwk96lBhDHARIsAEKO4xYAmLdGQNoTgtlQiTcZrmM7NoMeBFUGK7oMgsC-L3k_4WfpV43_WLYaAnTaEALw_wcB

https://www.autopi.io/blog/raspberry-pi-can-bus-explained/#:~:text=The%20Raspberry%20Pi%20hardware%20does,the%20CAN%20Bus%20(Raspbian).

https://copperhilltech.com/search.php?search_query=pican3&Search=

Config

Running a Seeed mcp2518fd based board with 2 can bus.

after boot, should see the following:

$ dmesg | grep can

[   11.115212] mcp251xfd spi0.1 can0: MCP2518FD rev0.0 (-RX_INT -PLL -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD o:40.00MHz c:40.00MHz m:20.00MHz rs:17.00MHz es:16.66MHz rf:17.00MHz ef:16.66MHz) successfully initialized.

[   11.217854] mcp251xfd spi0.0 can1: MCP2518FD rev0.0 (-RX_INT -PLL -MAB_NO_WARN +CRC_REG +CRC_RX +CRC_TX +ECC -HD o:40.00MHz c:40.00MHz m:20.00MHz rs:17.00MHz es:16.66MHz rf:17.00MHz ef:16.66MHz) successfully initialized.

Now set the interface "up":

$ sudo ip link set can0 up type can bitrate 100000

$ sudo ip link set can1 up type can bitrate 100000

Now testing the link with can0 connected to can1.

$ candump can0

$ cansend can1 111#ff

CANopen message structure

frame

The CANopen frame contains the arbitration field (12 bits) and data fields (8 bytes)

CANopen frame sequence

arbitration

The arbitration field contains an 11 bit identifier (COB-ID) which describes the message types. The cob-id defines the message priority, 0 is the highest, 0x7ff is the lowest. It also contains a 1 bit RTR (remote transmit request). This requests a response from the target device.

Arbitration Fields

NMT

NMT messages have cob-id of 0 (zero). These messages request the communication state of the node-id (data byte 2) be set to the designated state in data byte 1.

NMT message structure