#include #include "..\lib\UPAC5000.h" #include "..\lib\XWCAN.h" /*If the UserCANInt() function is not used, please don't remove it.*/ void UserCANInt(int CANPort,char CANInt){ if(CANPort ==0x0) { if (CANInt==0x01) /*avoid complier warning*/ { } } } void main(void) { int ret,i; unsigned char MsgMode,MsgRTR,MsgDataLen,MsgData[8]; unsigned long MsgID,MsgUpperTimeStamp,MsgLowerTimeStamp,MsgCnt=0; InitLib(); /********************************************************/ /* Initial all LEDs */ /********************************************************/ CL1Off(); CL2Off(); CL3Off(); /*******************************************************/ /* initialize and configure the CAN controller */ /*******************************************************/ ret=XWCANInit(0,1,125000UL,0,0,0x91a2b3a8UL,0x00000018UL); /* XCANInit function Parameter descriptions 0 : for CAN Port select 1 : for Receive Interrupt Enable 125000UL : for CAN baud 0 : for BT0 of user defined baud 0 : for BT1 of user defined baud 0x91a2b3a8UL : for AccCode of CAN message filter 0x00000018UL : for AccMask of CAN message filter After setting the AccCode and AccMask,only the message, whose ID is from 0x12345674 to 0x12345677 and RTR bit is 0, will be received. */ switch (ret){ /*Check if configuration is OK*/ case CAN_ResetError: Print("Reset Error!\n\r"); return; case CAN_SetACRError: Print("\n\rSet ACR Error!"); return; case CAN_SetAMRError: Print("\n\rSet AMR Error!"); return; case CAN_SetBaudRateError: Print("\n\rSet Baud Rate Error!"); return; case CAN_BaudNotSupport: Print("\n\rBaud Rate Not Support!"); return; case CAN_ConfigError: Print("\n\rConfiguration Failure!"); return; default: if (ret >0){ Print("Default=%d\n\r",ret); return; } } /********************************************************/ /* Enable Irq */ /********************************************************/ ret=CAN_CreateBuffer(0,0,1000); //Create RX Buffer /* 0 :for CAN Port select 0 :for Create Rx buffer 1000 :Create buffer count */ CAN_InstallIrq(0); /* CAN_Restore function Parameter descriptions 0 :for CAN Port select */ Print("Press any key to exit the program.\n\r"); while(1){ /********************************************************/ /* Receive CAN messages from CAN bus */ /********************************************************/ ret=GetCANMsg(0,&MsgMode,&MsgID,&MsgRTR,&MsgDataLen,MsgData,&MsgUpperTimeStamp,&MsgLowerTimeStamp); if (!ret){ MsgCnt++; Print("%lu(%lus-%luus):Mode=%d,ID=%lx,RTR=%d,Len=%d",MsgCnt,MsgUpperTimeStamp ,MsgLowerTimeStamp,MsgMode,MsgID,MsgRTR,MsgDataLen); if (MsgDataLen && !MsgRTR){ Print(",Data="); for (i=0;i