完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
基于28235;初始化时在while(ECanaShadow.CANES.bit.CCE != 0)处陷入死循环;时钟已打开;系统时钟
25MHz;哪位大侠帮分析一下原因,感激不尽!代码如下: void InitECana(void) { struct ECAN_REGS ECanaShadow; EALLOW; // EALLOW enables access to protected bits /* Configure eCAN RX and TX pins for CAN operation using eCAN regs*/ ECanaShadow.CANTIOC.all = ECanaRegs.CANTIOC.all; ECanaShadow.CANTIOC.bit.TXFUNC = 1; ECanaRegs.CANTIOC.all = ECanaShadow.CANTIOC.all; ECanaShadow.CANRIOC.all = ECanaRegs.CANRIOC.all; ECanaShadow.CANRIOC.bit.RXFUNC = 1; ECanaRegs.CANRIOC.all = ECanaShadow.CANRIOC.all; /* Configure eCAN for HECC mode - (reqd to access mailboxes 16 thru 31) */ // HECC mode also enables time-stamping feature ECanaRegs.CANME.all = 0; ECanaShadow.CANMC.all = ECanaRegs.CANMC.all; ECanaShadow.CANMC.bit.SCB = 1; ECanaRegs.CANMC.all = ECanaShadow.CANMC.all; /* Initialize all bits of 'Master Control Field' to zero */ // Some bits of MSGCTRL register come up in an unknown state. For proper operation, // all bits (including reserved bits) of MSGCTRL must be initialized to zero ECanaMboxes.MBOX0.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX1.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX2.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX3.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX4.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX5.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX6.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX7.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX8.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX9.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX10.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX11.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX12.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX13.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX14.MSGCTRL.all = 0x00000000; ECanaMboxes.MBOX15.MSGCTRL.all = 0x00000000; // TAn, RMPn, GIFn bits are all zero upon reset and are cleared again // as a matter of precaution. ECanaRegs.CANTA.all = 0xFFFFFFFF; /* Clear all TAn bits */ ECanaRegs.CANRMP.all = 0xFFFFFFFF; /* Clear all RMPn bits */ ECanaRegs.CANGIF0.all = 0xFFFFFFFF; /* Clear all interrupt flag bits */ ECanaRegs.CANGIF1.all = 0xFFFFFFFF; //ECanaRegs.CANMIM.all = 0xFFFFFFFF; /* Configure bit timing parameters for eCANA*/ ECanaShadow.CANMC.all = ECanaRegs.CANMC.all; ECanaShadow.CANMC.bit.CCR = 1; // Set CCR = 1 ECanaRegs.CANMC.all = ECanaShadow.CANMC.all; EDIS; ECanaShadow.CANES.all = ECanaRegs.CANES.all; { ECanaShadow.CANES.all = ECanaRegs.CANES.all; } while(ECanaShadow.CANES.bit.CCE != 1); // Wait for CCE bit to be set.. EALLOW; ECanaShadow.CANBTC.all = 0; ECanaShadow.CANBTC.bit.BRPREG = 4; ECanaShadow.CANBTC.bit.TSEG2REG = 1; ECanaShadow.CANBTC.bit.TSEG1REG = 6; #endif //ECanaShadow.CANBTC.bit.SJWREG = 2; //ECanaShadow.CANBTC.bit.SAM = 1; ECanaShadow.CANBTC.bit.SAM = 1; ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all; ECanaShadow.CANMC.all = ECanaRegs.CANMC.all; //把CANMC读入影子寄存器 ECanaShadow.CANMC.bit.CCR = 0; //改变配置请求位 ECanaRegs.CANMC.all = ECanaShadow.CANMC.all; //把配置好的寄存器值回写 ECanaShadow.CANES.all = ECanaRegs.CANES.all; EDIS; do { ECanaShadow.CANES.all = ECanaRegs.CANES.all; } while(ECanaShadow.CANES.bit.CCE != 0); /* Disable all Mailboxes */ ECanaRegs.CANME.all = 0; } |
|
相关推荐
19个回答
|
|
|
|
|
|
|
|
|
|
回帖奖励 +1 分积分
你是在仿真的时候出现,还是实际运行(不连仿真器)的情况下出现?
|
|
|
|
不连仿真器;我是用串口下载.hex文件,下载完之后程序不运行,注释掉以下语句程序可正常运行,但CAN未被成功初始化 do { ECanaShadow.CANES.all = ECanaRegs.CANES.all; } while(ECanaShadow.CANES.bit.CCE != 0); |
|
|
|
你看看ECanaRegs.CANES.all的值是多少,对应的ECanaShadow.CANES.bit.CCE位是否为0?
|
|
|
|
CCE未被置0,就是卡在这 |
|
|
|
|
|
|
|
你看看于ECanaShadow.CANES相关的寄存器,看看是否有写保护控制寄存器?
|
|
|
|
我也遇到过这个问题,重新掉电就好了
|
|
|
|
|
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
波特率要设置正确,我的问题找到原因了 switch(4/*DPI_CANOpenBaud*/) { /*Bit rate=(SYSCLKOUT/2)/((TSEG2REG+TSEG1REG+3)*(BRPREG+1))*/ case 0://50k ECanbShadow.CANBTC.bit.BRPREG = 99; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 1://125k ECanbShadow.CANBTC.bit.BRPREG = 39; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 2://250k ECanbShadow.CANBTC.bit.BRPREG = 19; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 3://500k ECanbShadow.CANBTC.bit.BRPREG = 9; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; case 4://1M ECanbShadow.CANBTC.bit.BRPREG = 4; ECanbShadow.CANBTC.bit.TSEG2REG =2; ECanbShadow.CANBTC.bit.TSEG1REG = 10; break; default: break; } ECanbShadow.CANBTC.bit.SAM = 1; ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all; ECanbShadow.CANGIF0.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF0.all = 0xFFFFFFFF; ECanbRegs.CANGIF0.all = ECanbShadow.CANMIM.all; ECanbShadow.CANGIF1.all = ECanbRegs.CANMIM.all; ECanbShadow.CANGIF1.all = 0xFFFFFFFF; ECanbRegs.CANGIF1.all = ECanbShadow.CANMIM.all; ECanbShadow.CANMC.all = ECanbRegs.CANMC.all; ECanbShadow.CANMC.bit.CCR = 0 ; // Set CCR = 0,再次激活CAN ECanbRegs.CANMC.all = ECanbShadow.CANMC.all; do { ECanbShadow.CANES.all = ECanbRegs.CANES.all; } while(ECanbShadow.CANES.bit.CCE != 0 ); 之前是因为波特率没设置,导致无法初始化成功,然后CCE就一直为0 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1176 浏览 1 评论
584 浏览 1 评论
1414 浏览 0 评论
基于DSP C6000教学实验箱_数字图像处理教程:5-9 图像反色实验案例分享
1709 浏览 0 评论
1393 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-21 03:19 , Processed in 0.689198 second(s), Total 76, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191