// CANB
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 0;
GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (CANRXDB)
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 2; // CANRXB
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 0;
GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (CANTXDB)
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 2; // CANTXB
void Arch_ECanIRQ_Drive1_Config(void)
{
EALLOW;
/* 邮箱中断屏蔽寄存器 */
ECanbRegs.CANMIM.all = 0xFFFFFFFF;
/* 邮箱中端级别设置寄存器,1代表使用中断线1,0代表使用中断线0 */
/* 与邮箱相关的中断,例如消息的发送或者接收所响应的中断 */
ECanbRegs.CANMIL.all = 0x0;
ECanbRegs.CANGIM.bit.MTOM = 0x1; // mailbox time-out
ECanbRegs.CANGIM.bit.TCOM = 0x1; // time counter overflown
ECanbRegs.CANGIM.bit.AAIM = 0x1; // acknowledge failure
ECanbRegs.CANGIM.bit.WDIM = 0x1; // write refusal
ECanbRegs.CANGIM.bit.WUIM = 0x1; // wake-up
ECanbRegs.CANGIM.bit.RMLIM = 0x1; // messages lost
ECanbRegs.CANGIM.bit.BOIM = 0x1; // bus closed
ECanbRegs.CANGIM.bit.EPIM = 0x1; // Error-passive
ECanbRegs.CANGIM.bit.WLIM = 0x1; // warning
/* then, map all interrupts to ECAN0INTB */
ECanbRegs.CANGIM.bit.GIL = 0x0;
/* Enable interrupt line0 */
ECanbRegs.CANGIM.bit.I0EN = 0x1;
/* Diable interrupt line1 */
ECanbRegs.CANGIM.bit.I1EN = 0x0;
EDIS;
}
void Arch_ECanPort_Drive1_Config(void)
{
struct ECAN_REGS ECanbShadow;
EALLOW;
/* CANTX引脚用于CAN的发送操作 */
ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;
ECanbShadow.CANTIOC.bit.TXFUNC = 1;
ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;
/* CANRX引脚用于CAN的接收操作 */
ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
ECanbShadow.CANRIOC.bit.RXFUNC = 1;
ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;
/* 主控制器配置 */
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.STM = 0; /* 自测模式使能位 1自测 0普通 */
ECanbShadow.CANMC.bit.SCB = 1; /* CAN模式选择,1增强型ECAN,0标准型CAN */
ECanbShadow.CANMC.bit.DBO = 0; /* 数据字节顺序, 1:先发低字节,0先发高字节 */
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
ECanbMboxes.MBOX0.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX1.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX2.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX3.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX4.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX5.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX6.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX7.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX8.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX9.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX10.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX11.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX12.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX13.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX14.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX15.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX16.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX17.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX18.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX19.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX20.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX21.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX22.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX23.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX24.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX25.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX26.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX27.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX28.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX29.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX30.MSGCTRL.all = 0x0000000;
ECanbMboxes.MBOX31.MSGCTRL.all = 0x0000000;
/* 清空发送响应寄存器的所有位 */
ECanbRegs.CANTA.all = 0xFFFFFFFF;
/* 清空接收消息挂起寄存器的所有位 */
ECanbRegs.CANRMP.all = 0xFFFFFFFF;
/* 清空所有的中断标志位 */
ECanbRegs.CANGIF0.all = 0xFFFFFFFF;
ECanbRegs.CANGIF1.all = 0xFFFFFFFF;
/* irq level config */
Arch_ECanIRQ_Drive1_Config();
/* 改变配置请求位,在对CANBTC进行操作之前,
CPU必须等待,直到CANES的CCE置1 */
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 1;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do{
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
} while(ECanbShadow.CANES.bit.CCE != 1);
ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;
ECanbShadow.CANBTC.all = 0;
ECanbShadow.CANBTC.bit.BRPREG = 4; /* 波特率预定标器 BRPREG(BRPREG+1) = 5
feeds a 15Mhz CAN clock(CAN的时钟为15Mhz) */
ECanbShadow.CANBTC.bit.TSEG1REG = 10; /* 时间段1,合并了传播段和相位缓冲段1,以Tq为
单位的位的长度 */
ECanbShadow.CANBTC.bit.TSEG2REG = 2; /* 时间段2,相位缓冲段2,以Tq为单位的位的长度 */
ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;
/* 改变配置请求位,在对CANBTC进行操作之前,
CPU必须等待,知道CANES的CCE置0 */
ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
ECanbShadow.CANMC.bit.CCR = 0;
ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
do{
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
}while(ECanbShadow.CANES.bit.CCE != 0);
/* 禁止邮箱使能,从而对邮箱进行写操作 */
ECanbRegs.CANME.all = 0;
EDIS;
}
如下代码无法使用:
do{
ECanbShadow.CANES.all = ECanbRegs.CANES.all;
} while(ECanbShadow.CANES.bit.CCE != 1);
CCE位没有被置位,程序暂时看不出来什么问题,这与硬件有关吗?CAN0已调试完毕,可以使用,现在CAN1出问题,硬件出错可能性真的太低了。 |