//****************************************************************************
// @Module MultiCAN Module (CAN)
// @Filename CAN.C
// @Project 2267.dav
//----------------------------------------------------------------------------
// @Controller Infineon XC2267-96F66
//
// @Compiler Keil
//
// @Codegenerator 2.2
//
// @Description This file contains functions that use the CAN module.
//
//----------------------------------------------------------------------------
// @Date 2017/6/5 14:50:13
//
//****************************************************************************
// USER CODE BEGIN (CAN_General,1)
// USER CODE END
//****************************************************************************
// @Project Includes
//****************************************************************************
#include "MAIN.H"
// USER CODE BEGIN (CAN_General,2)
// USER CODE END
//****************************************************************************
// @Macros
//****************************************************************************
// USER CODE BEGIN (CAN_General,3)
// USER CODE END
//****************************************************************************
// @Defines
//****************************************************************************
// USER CODE BEGIN (CAN_General,4)
// USER CODE END
//****************************************************************************
// @Typedefs
//****************************************************************************
// USER CODE BEGIN (CAN_General,5)
// USER CODE END
//****************************************************************************
// @Imported Global Variables
//****************************************************************************
// USER CODE BEGIN (CAN_General,6)
// USER CODE END
//****************************************************************************
// @Global Variables
//****************************************************************************
static ubyte ubFIFOWritePtr[5];
static ubyte ubFIFOReadPtr[5];
// USER CODE BEGIN (CAN_General,7)
// USER CODE END
//****************************************************************************
// @External Prototypes
//****************************************************************************
// USER CODE BEGIN (CAN_General,8)
// USER CODE END
//****************************************************************************
// @Prototypes Of Local Functions
//****************************************************************************
// USER CODE BEGIN (CAN_General,9)
// USER CODE END
//****************************************************************************
// @Function void CAN_vInit(void)
//
//----------------------------------------------------------------------------
// @Description This is the initialization function of the CAN function
// library. It is assumed that the SFRs used by this library
// are in reset state.
//
//----------------------------------------------------------------------------
// @Returnvalue None
//
//----------------------------------------------------------------------------
// @Parameters None
//
//----------------------------------------------------------------------------
// @Date 2017/6/5
//
//****************************************************************************
// USER CODE BEGIN (Init,1)
// USER CODE END
void CAN_vInit(void)
{
ubyte i;
// USER CODE BEGIN (Init,2)
// USER CODE END
/// -----------------------------------------------------------------------
/// Configuration of Kernel State Configuration Register:
/// -----------------------------------------------------------------------
/// - Enable the CAN module(MODEN)
/// - Enable Bit Protection for MODEN
MCAN_KSCCFG = 0x0003; // load Kernel State Configuration Register
_nop_(); // one cycle delay
_nop_(); // one cycle delay
/// -----------------------------------------------------------------------
/// Configuration of the Module Clock:
/// -----------------------------------------------------------------------
/// - the CAN module clock = 20.00 MHz
/// - Normal divider mode selected
CAN_FDRL = 0x43FE; // load Fractional Divider Register
/// -----------------------------------------------------------------------
/// Panel Control
/// -----------------------------------------------------------------------
/// - wait until Panel has finished the initialisation
while(CAN_PANCTRL & CAN_PANCTR_BUSY){ // wait until Panel has finished
// the initialisation
}
/// -----------------------------------------------------------------------
/// Configuration of CAN Node 0:
/// -----------------------------------------------------------------------
/// General Configuration of the Node 0:
/// - set INIT and CCE
CAN_NCR0 = 0x0041; // load NODE 0 control register[15-0]
/// -----------------------------------------------------------------------
/// Configuration of CAN Node 1:
/// -----------------------------------------------------------------------
/// General Configuration of the Node 1:
/// - set INIT and CCE
CAN_NCR1 = 0x0041; // load NODE 1 control register[15-0]
/// -----------------------------------------------------------------------
/// Configuration of CAN Node 2:
/// -----------------------------------------------------------------------
/// General Configuration of the Node 2:
/// - set INIT and CCE
CAN_NCR2 = 0x0041; // load NODE 2 control register[15-0]
/// -----------------------------------------------------------------------
/// Configuration of CAN Node 3:
/// -----------------------------------------------------------------------
/// General Configuration of the Node 3:
/// - set INIT and CCE
/// - enable interrupt generation when a message transfer is completed
/// - transfer OK interrupt node pointer: MultiCAN SRN 0
CAN_NCR3 = 0x0043; // load NODE 3 control register[15-0]
/// - load NODE 3 interrupt pointer register
CAN_NIPR3 = 0x0000; // load NIPR3_LECINP, ALINP, CFCINP and TRINP
/// Configuration of the used CAN Port Pins:
/// - Loop-back mode is disabled
/// - P10.14 is used for CAN3 Transmit input(RXDC3C)
/// - P10.13 is used for CAN3 Transmit Output(TXDC3C)
P10_IOCR13 = 0x00A0; //set direction register
CAN_NPCR3 = 0x0002; // load node3 port control register
/// Configuration of the Node 3 Baud Rate:
/// - required baud rate = 250.000 kbaud
/// - real baud rate = 250.000 kbaud
/// - sample point = 60.00 %
/// - there are 5 time quanta before sample point
/// - there are 4 time quanta after sample point
/// - the (re)synchronization jump width is 2 time quanta
CAN_NBTR3L = 0x3447; // load NBTR3_DIV8, TSEG2, TSEG1, SJW and BRP
/// Configuration of the Node 3 Error Counter:
/// - the error warning threshold value (warning level) is 96
CAN_NECNT3H = 0x0060; // load NECNT3_EWRNLVL register
CAN_NECNT3L = 0x0000;
/// Configuration of the Frame Counter:
/// - Frame Counter Mode: the counter is incremented upon the reception
/// and transmission of frames
/// - frame counter: 0x0000
CAN_NFCR3H = 0x0000; // load NFCR3_CFCOV, CFCIE, CFMOD, CFSEL
CAN_NFCR3L = 0x0000; // load NFCR3_CFC
/// -----------------------------------------------------------------------
/// Configuration of CAN
评论0