配置代码:void CAN1Init(void)
{
CAN_BIT_CONFIGcanBitConfig;
UINT baudPrescalar;
CANEnableModule(CAN1,TRUE);
CANSetOperatingMode(CAN1,CAN_CONFIGURATION);
while(CANGetOperatingMode(CAN1)!= CAN_CONFIGURATION);
CANSetTimeStampPrescalar(CAN1, 80 );
CANSetCap(CAN1, TRUE );
canBitConfig.phaseSeg2Tq = CAN_BIT_2TQ;
canBitConfig.phaseSeg1Tq = CAN_BIT_3TQ;
canBitConfig.propagationSegTq = CAN_BIT_4TQ;
canBitConfig.phaseSeg2TimeSelect = TRUE;
canBitConfig.sample3Time = TRUE;
canBitConfig.syncJumpWidth = CAN_BIT_2TQ;
CANSetSpeed( CAN1, &canBitConfig,SYSTEM_FREQ, CAN_SPD_1MHZ );
CANAssignMemoryBuffer(CAN1,CAN1MessageFifoArea,(24* 16) );
CANConfigureChannelForRx(CAN1,CAN_CHANNEL1, 24, CAN_RX_FULL_RECEIVE);
CANConfigureFilterMask (CAN1, CAN_FILTER_MASK0, 0, CAN_SID,CAN_FILTER_MASK_IDE_TYPE);
CANConfigureFilter (CAN1, CAN_FILTER1, 0x00, CAN_SID);
CANLinkFilterToChannel (CAN1, CAN_FILTER1, CAN_FILTER_MASK0,CAN_CHANNEL1);
CANEnableFilter (CAN1, CAN_FILTER1, TRUE);
CANEnableChannelEvent(CAN1, CAN_CHANNEL1,CAN_RX_CHANNEL_NOT_EMPTY, TRUE);
CANEnableModuleEvent (CAN1, CAN_RX_EVENT,TRUE);
/* These functions are from interruptperipheral
* library. */
/*Step 7: Switch the CAN mode
* to normal mode. */
CANSetOperatingMode(CAN1,CAN_LISTEN_ONLY);
while(CANGetOperatingMode(CAN1)!= CAN_LISTEN_ONLY);
}
|