Difference between revisions of "CAN Protocol"
Alexalspach (Talk | contribs) (→Case-study: Softing CAN) |
Alexalspach (Talk | contribs) (→Opening the CAN Communication Channel) |
||
Line 37: | Line 37: | ||
In this chapter, sample code demonstrating the implementation of the CAN communication interface is provide. This is the foundation for Softing PCI CAN. | In this chapter, sample code demonstrating the implementation of the CAN communication interface is provide. This is the foundation for Softing PCI CAN. | ||
===Opening the CAN Communication Channel=== | ===Opening the CAN Communication Channel=== | ||
+ | <syntaxhighlight lang="cpp"> | ||
+ | char ch_name[256]; | ||
+ | sprintf_s(ch_name, 256, "CAN-ACx-PCI_%d", ch); | ||
+ | INIL2_initialize_channel(&hCAN[ch-1], ch_name); | ||
+ | |||
+ | L2CONFIG L2Config; | ||
+ | L2Config.fBaudrate = 1000.0; | ||
+ | L2Config.bEnableAck = 0; | ||
+ | L2Config.bEnableErrorframe = 0; | ||
+ | L2Config.s32AccCodeStd = 0; | ||
+ | L2Config.s32AccMaskStd = 0; | ||
+ | L2Config.s32AccCodeXtd = 0; | ||
+ | L2Config.s32AccMaskXtd = 0; | ||
+ | L2Config.s32OutputCtrl = GET_FROM_SCIM; | ||
+ | L2Config.s32Prescaler = 1; | ||
+ | L2Config.s32Sam = 0; | ||
+ | L2Config.s32Sjw = 1; | ||
+ | L2Config.s32Tseg1 = 4; | ||
+ | L2Config.s32Tseg2 = 3; | ||
+ | L2Config.hEvent = (void*)-1; | ||
+ | |||
+ | CANL2_initialize_fifo_mode(hCAN[ch-1], &L2Config); | ||
+ | </syntaxhighlight> | ||
+ | |||
===CAN Initialization=== | ===CAN Initialization=== | ||
===Starting Periodic CAN Communication=== | ===Starting Periodic CAN Communication=== |
Revision as of 21:18, 5 October 2012
Contents |
CAN Communication
Baud-Rate
The CAN communication baud-rate is 1Mbps.
Non-Periodic Communication
Messages can be sent to initialize or stop CAN communication.
Periodic Communication
The Allegro Hand control software attempts to communicate with the real or simulated hand at a regular control interval. Every 3 milliseconds the joint torques are calculated and the joint angles are updated.
CAN Frames
Standard CAN Packet
The standard CAN packet used for communication contains 8 bytes.
typedef struct{ unsigned char STD_EXT; unsigned long msg_id; //message identifier unsigned char data_length; // char data[8]; // data array } can_msg;
ID (Message Identifier)
The 4 byte integer CAN message is split into the command ID (26 bits), destination ID (3bits) and source ID (3 bits).
TABLE GOES HERE
Command Identifiers
TABLE GOES HERE
Source and Destination Identifiers
TABLE GOES HERE
Case-study: Softing CAN
In this chapter, sample code demonstrating the implementation of the CAN communication interface is provide. This is the foundation for Softing PCI CAN.
Opening the CAN Communication Channel
char ch_name[256]; sprintf_s(ch_name, 256, "CAN-ACx-PCI_%d", ch); INIL2_initialize_channel(&hCAN[ch-1], ch_name); L2CONFIG L2Config; L2Config.fBaudrate = 1000.0; L2Config.bEnableAck = 0; L2Config.bEnableErrorframe = 0; L2Config.s32AccCodeStd = 0; L2Config.s32AccMaskStd = 0; L2Config.s32AccCodeXtd = 0; L2Config.s32AccMaskXtd = 0; L2Config.s32OutputCtrl = GET_FROM_SCIM; L2Config.s32Prescaler = 1; L2Config.s32Sam = 0; L2Config.s32Sjw = 1; L2Config.s32Tseg1 = 4; L2Config.s32Tseg2 = 3; L2Config.hEvent = (void*)-1; CANL2_initialize_fifo_mode(hCAN[ch-1], &L2Config);
CAN Initialization
Starting Periodic CAN Communication
Stopping Periodic CAN Communication
Transmitting Control Torques
Receiving Joint Angles
Whos here now: Members 0 Guests 0 Bots & Crawlers 1 |