/*CAN0初始化函数*/ void CAN0Initial(void) {
CAN0CTL0 = 0x01;
/* Enter Initialization Mode,请求进入初始化模式
* CAN0CTL0 CAN0控制寄存器0,用以请求进入初始化模式
*
0b00000001
*
||||||||__ INITRQ(Enter Initialization Mode)初始化请求位
*
|||||||___ SLPRQ(Sleep Mode Request bit)休眠模式请求位
*
||||||____ WUPE(Wake-Up disabled)唤醒允许位
*
|||||_____ TIME(Time stamping disabled)定时器允许位
*
||||______ SYNCH(Synchronized Status)同步状态位
*
|||_______ CSWAI(CAN not affected by Wait)等待模式下CAN停止控制位
*
||________ RXACT(Receiver Active Status bit)接收数据指示位
*
|_________ RXFRM(Received Frame Flag bit)接收帧标志位
*/
while (CAN0CTL1_INITAK==0){};/* Wait for Initialization Mode acknowledge
* INITRQ bit = 1时,表示已进入初始化模式
*/
CAN0CTL1 = 0x80;
/* Enable MSCAN module and LoopBack Mode,使能CAN,选择外部时钟,
* CAN0CTL1
CAN0控制寄存器0
*
0b10000000
*
||||||||__ INITAK(Initialization Mode Acknowledge)初始化确认位
*
|||||||___ SLPAK(Sleep Mode Acknowledge)休眠模式确认位
*
||||||____ WUPM(Wake-up low-pass filter disabled)
*
|||||_____ BORM(Bus-Off Recovery Mode)下线恢复模式控制位
*
||||______ LISTEN(Listen Only Mode disabled)
*
|||_______ LOOPB(Loop Back Mode enabled)监控自检模式控制位
*
||________ CLKSRC(Ext Osc/Xtal as Clock Source)时钟源选择位
*
|_________ CANE(MSCAN Module enabled)使能CAN总线控制位
*/
CAN0BTR0 = 0x03;
/* Synch Jump = 1 Tq clock Cycles,预分频为4
* MSCAN Bus Timing Register 0,总线定时寄存器0
*
0b00000011
*
||||||||__BRP0=1
*
|||||||___BRP1=1
*
||||||____BRP2=0
*
|||||_____RPP3=0
*
||||______BRP4=0
*
|||_______BRP5=0,即预分频为4
*
||________SJW0=0
*
|_________SJW1=0,即同步跳转宽度为1Tq
*/
CAN0BTR1 = 0x45;
/* Set Number of samples per bit, TSEG1 and TSEG2,设置1和2时间段
* MSCAN Bus Timing Register 1, 总线定时寄存器1
*
0b01000101
*
||||||||__TSEG10=1
*
|||||||___TSEG11=0
*
||||||____TSEG12=1
*
|||||_____TSEG13=0,即时间段1为6 Tq
*
||||______TSEG20=0
*
|||_______TSEG21=0
*
||________TSEG22=1,时间段2宽度为5 Tq
*
|_________SAMP=0, 即每位进行1次采样,1时每位进行3次采样
*/
CAN0IDAC = 0x10;
/* Set four 16-bit Filters,设置接收控制寄存器,
* MSCAN Identifier Acceptance Control Register
*
0b00010000
*
||||||||__IDHIT0
*
|||||||___IDHIT1
*
||||||____IDHIT2,滤波器应用指示位
*
|||||_____ Unimplemented
*
||||______IDAM0=1
*
|||_______IDAM1=0,即4个16位接收滤波器
*
||________
*
|_________>- Unimplemented
*/
|