int main(void) { unsigned long i; CAN_MSG_Type RxMsg; // Can RxMsg. PINSEL_CFG_Type pinCfg; // Initialize pins pinCfg.Funcnum = 1; pinCfg.OpenDrain = pinCfg.Pinmode = pinCfg.Portnum = 0; pinCfg.Pinnum = 0; PINSEL_ConfigPin(&pinCfg); // P0.0 = CAN1RX pinCfg.Pinnum = 1; PINSEL_ConfigPin(&pinCfg); // P0.1 = CAN1TX CAN_Init(LPC_CAN1 , 500000 ); // Initialize CAN1 at 500kbps CAN_SetAFMode( LPC_CANAF , CAN_AccBP ); // Bypass Access Filter. All ID accepted. i=0; while(1) { if( CAN_ReceiveMsg( LPC_CAN1 , &RxMsg ) == SUCCESS ) // Receive a message i++; } return 0 ; } |
#define CANTESTMODE 1 int main(void) { CAN_MSG_Type TxMsg,RxMsg; // CAN Msgs PINSEL_CFG_Type pinCfg; unsigned int i; // Initialize pins pinCfg.Funcnum = 1; pinCfg.OpenDrain = pinCfg.Pinmode = pinCfg.Portnum = 0; pinCfg.Pinnum = 0; PINSEL_ConfigPin(&pinCfg); // P0.0 = CAN1RX pinCfg.Pinnum = 1; PINSEL_ConfigPin(&pinCfg); // P0.1 = CAN1TX CAN_Init(LPC_CAN1 , 500000 ); // Initialize CAN1 at 500kbps #if CANTESTMODE CAN_ModeConfig( LPC_CAN1 , CAN_SELFTEST_MODE , ENABLE ); #endif CAN_SetAFMode( LPC_CANAF , CAN_AccBP ); // Bypass Access Filter. All ID accepted. CAN_InitMessage( &TxMsg , &RxMsg ); i=0; while(1) { #if CANTESTMODE // Status CAN_SendMsg (LPC_CAN_TypeDef *CANx, CAN_MSG_Type *CAN_Msg, unsigned char self_test ); CAN_SendMsg(LPC_CAN1, &TxMsg,1); // #endif if( CAN_ReceiveMsg( LPC_CAN1 , &RxMsg ) == SUCCESS ) // Receive a message i++; } return 0; } |
Status CAN_SendMsg (... { ... /*Write transmission request Tx Buffer 1*/ if(self_recep) CANx->CMR = 0x30; else CANx->CMR = 0x21; ... /*Write transmission request Tx Buffer 2*/ if(self_recep) CANx->CMR = 0x50; else CANx->CMR = 0x41; ... /*Write transmission request Tx Buffer 3*/ if(self_recep) CANx->CMR = 0x90; else CANx->CMR = 0x81; |
#define CANTESTMODE 1 int main(void) { unsigned long i; CAN_MSG_Type TxMsg,RxMsg; // CAN Msgs PINSEL_CFG_Type pinCfg; // Initialize pins pinCfg.Funcnum = 1; pinCfg.OpenDrain = pinCfg.Pinmode = pinCfg.Portnum = 0; pinCfg.Pinnum = 0; PINSEL_ConfigPin(&pinCfg); // P0.0 = CAN1RX pinCfg.Pinnum = 1; PINSEL_ConfigPin(&pinCfg); // P0.1 = CAN1TX CAN_Init(LPC_CAN1 , 500000 ); // Initialize CAN1 at 500kbps #if CANTESTMODE CAN_ModeConfig( LPC_CAN1 , CAN_SELFTEST_MODE , ENABLE ); #endif CAN_SetAFMode( LPC_CANAF , CAN_AccBP ); // Bypass Access Filter. All ID accepted. CAN_InitMessage( &TxMsg , &RxMsg ); #if CANTESTMODE CAN_SendMsg(LPC_CAN1, &TxMsg); LPC_CAN1->CMR |=(1<<4); //Self Reception Request ( works) #endif i=0; while(1) { if( CAN_ReceiveMsg( LPC_CAN1 , &RxMsg ) == SUCCESS ){ // Receive a message i++; } #if CANTESTMODE LPC_CAN1->CMR |= (1<<4); //Self Reception Request ( doesn't work ) #endif } return 0; } |
[B]1. According to the CAN specification, dependening on the receive error counter, the CAN node can have the following states: 000-127: error-active state 128-255: error-passive state 256- : Bus-Off What the relation between this states and the state of the Minimon32 LEDs (BusOff-, Error- and Reset-LED) ?[/B] The error LED shows, whether the CAN controller is in warning level state. Error Counter: <= 96 : Error LED is green. Error Counter: > 96 : Error LED ist red. Error Counter: < 256 : Bus-Off LED ist green. Error Counter: = 256 : Bus-Off LED ist red. The Reset LED shows, whether the CAN controller is in initialisiation mode (RESET) or activ (RUN). |