Fortec Star Diamond Systems DS-MPE-CAN2L Manual page 33

Pcie minicardi/o expansion module with dual canbus ports
Table of Contents

Advertisement

can_init (1); // Will initialize CAN#1 channel
Baud rate configuration.
set_baudrate(int can_ch, int baud rate): This API accepts the CAN interface number and the baudrate as
arguments for configuring the baud rate of the specified CAN port.
// Set 500k Baud rate for CAN#0, Corresponding CAN channel values should be passed.
ret_val = set_baudrate(0, CAN_SPEED_500K) ;
Use below macros for setting the different baud rates. These macros can also be found in can.h file.
CAN_SPEED_1M
CAN_SPEED_800K
CAN_SPEED_500K
CAN_SPEED_250K
CAN_SPEED_125K
CAN_SPEED_100K
CAN_SPEED_50K
CAN_SPEED_20K
CAN_SPEED_10K
CAN Transmit & Receive :
FrameCANTxMsg() & check_rx_msg() : These function will be used to Transmit and Receive the CAN
messages respectively.
CAN Transmit Prototype.
void FrameCANTxMsg(int can_ch, unsigned char msgType, unsigned int can_id, int len, unsigned char *data):
Assign the appropriate values, before calling the FrameCANTxMsg function.
can_ch: CAN port number, 0 for CAN#0 and 1 for CAN#1.
msgType = MSG_STANDARD ; // or MSG_EXTENDED .
can_id = 0x12; //if the msgType is MSG_STANDARD then the value should be in the range of 0x0 to 0x7FF (11
bit value)
//Else if the msgType is MSG_EXTENDED then the value should be in range 0x0 to 0x1FFFFFFF (29 bit value)
len = 4 //This field can be of 0 to 8 bytes length ; // CAN Transmit Data Length
data: This field depends on the len field.
If len is 4 then the CAN message data will be of 4 bytes long and each byte can range from 0x0 to 0xFF (
8-Bit data)
data[0] = 0x1A ;
data[1] = 0xAB ;
data[2] = 0x22 ;
data[3] = 0x4D ;
FrameCANTxMsg(0, msgType, can_id, dlc, data) ;
DS-MPE-CAN2L User Manual Rev A.1
www.diamondsystems.com
Page 31

Advertisement

Table of Contents
loading

Table of Contents