keil_examples/CANACT/can.c
/******************************************************************************
** Function name:		CAN_Init
**
** Descriptions:		Initialize CAN, install CAN interrupt handler
**
** parameters:			bitrate
** Returned value:		true or false, false if initialization failed.
** 
******************************************************************************/
Function name:         CAN_Init
Descriptions:          Initialize CAN, install CAN interrupt handler

bitrate
Returned value:                true or false, false if initialization failed.
Function name : CAN_Init Descriptions : Initialize CAN install CAN interrupt handler bitrate Returned value : true or false false if initialization failed .
uint32_t CAN_Init( uint32_t can_btr )
{
  CAN1RxDone = CAN2RxDone = FALSE;
  LPC_SC->PCONP |= ((1<<13)|(1<<14));  
  LPC_PINCON->PINSEL0 &= ~0x0000000F;  
  LPC_PINCON->PINSEL0 |= 0x00000005;	
  LPC_PINCON->PINSEL4 &= ~0x0003C000;  
  LPC_PINCON->PINSEL4 |= 0x00014000;
  LPC_CAN1->MOD = LPC_CAN2->MOD = 1;    
  LPC_CAN1->IER = LPC_CAN2->IER = 0;    
  LPC_CAN1->GSR = LPC_CAN2->GSR = 0;    
  LPC_CAN1->BTR = LPC_CAN2->BTR = can_btr;
  LPC_CAN1->MOD = LPC_CAN2->MOD = 0x0;  
  NVIC_EnableIRQ(CAN_IRQn);
  LPC_CAN1->IER = LPC_CAN2->IER = 0x01; 
  return( TRUE );
}
uint32_t CAN_Init ( uint32_t can_btr ) { CAN1RxDone = CAN2RxDone = FALSE ; LPC_SC -> PCONP |= ( ( 1 << 13 ) | ( 1 << 14 ) ) ; LPC_PINCON -> PINSEL0 &= ~ 0x0000000F ; LPC_PINCON -> PINSEL0 |= 0x00000005 ; LPC_PINCON -> PINSEL4 &= ~ 0x0003C000 ; LPC_PINCON -> PINSEL4 |= 0x00014000 ; LPC_CAN1 -> MOD = LPC_CAN2 -> MOD = 1 ; LPC_CAN1 -> IER = LPC_CAN2 -> IER = 0 ; LPC_CAN1 -> GSR = LPC_CAN2 -> GSR = 0 ; LPC_CAN1 -> BTR = LPC_CAN2 -> BTR = can_btr ; LPC_CAN1 -> MOD = LPC_CAN2 -> MOD = 0x0 ; NVIC_EnableIRQ ( CAN_IRQn ) ; LPC_CAN1 -> IER = LPC_CAN2 -> IER = 0x01 ; return ( TRUE ) ; }
Function name:         CAN_Init
Descriptions:          Initialize CAN, install CAN interrupt handler
Function name : CAN_Init Descriptions : Initialize CAN install CAN interrupt handler
/* Enable CAN1 and CAN2 clock */ /* CAN1 is p0.0 and p0.1	*/ /* CAN2 is p2.7 and p2.8 */ /* Reset CAN */ /* Disable Receive Interrupt */ /* Reset error counter when CANxMOD is in reset	*/ /* CAN in normal operation mode */ /* Enable receive interrupts */