打印

ecan 初始化问题

[复制链接]
958|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
hwhbuaahwhbuaa|  楼主 | 2017-9-21 22:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

基于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;               
}

相关帖子

沙发
hwhbuaahwhbuaa|  楼主 | 2017-9-21 22:58 | 只看该作者
本帖最后由 hwhbuaahwhbuaa 于 2017-9-21 23:46 编辑

是基于28335

使用特权

评论回复
板凳
hwhbuaahwhbuaa|  楼主 | 2017-9-22 09:23 | 只看该作者
本帖最后由 hwhbuaahwhbuaa 于 2017-9-26 16:18 编辑

能帮解决的版友,楼主将提供现金红包奖励100rmb!

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

3

帖子

0

粉丝