DS-MPE-CAN2L User Manual Rev A.
www.diamondsystems.com
Page 16
// Set 500k Baud rate for CAN#0
ret_val = set_baudrate(
can0_fd
, CAN_SPEED_500K ) ;
if ( ret_val < 0 )
{
printf("Error while setting the baud rate \n") ;
exit(0) ;
}
// Set 500k Baud rate for CAN#1
ret_val = set_baudrate(
can1_fd
, CAN_SPEED_500K ) ;
if ( ret_val < 0 )
{
printf("Error while setting the baud rate \n") ;
exit(0) ;
}
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 Transmit & Receive:
can_tx() & can_rx() :
These function will be used to Transmit and Receive the CAN messages respectively.
CAN Transmit Prototype.
int can_tx( int can_fd, unsigned char msgType, unsigned int can_id, int len,unsigned char *data) ;
Assign the appropriate values, before calling the can_tx function.
can0_fd : CAN descriptor, return value from init_can0() function
msgType = MSG_STANDARD ; // or MSG_EXTENDED .
can_id = 0x12 ; // CAN ID, if the msgType is MSG_STANDARD then it should be 11-Bit CAN Message ID
// if the msgType is MSG_EXTENDED then it should be 29-Bit CAN Message ID
len = 4 ; // CAN Transmit Data Length
data : CAN message data.
data[0] = 0x1A ;
data[1] = 0xAB ;