打印
[DSP]

关于DSP28335CAN通讯远程帧调试求助!

[复制链接]
1226|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
smile2196|  楼主 | 2020-8-30 10:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在调试28335的ACN通讯中,在自响应模式下调试远程帧,想实现MBOX16向MBOX0发送远程帧并接收MBOX0发出的数据。在给接收邮箱的TRS16置位后,TA 端始终无法得到接收响应,程序卡死了。设置的是MBOX0和MBOX16分别为远程帧的传输和接收邮箱,MSGID分别设置为MBOX0:0xB5550093,MBOX16:0xD5550093。给MBOX0和MBOX16的RTR位也都进行了置位。想请教一下各位大佬,问题出在哪里了。相关的代码节选如下,请各位大佬帮忙指点一下!感谢!
void main(void)
{
    Uint16  j;
   struct ECAN_REGS ECanaShadow;
   InitSysCtrl();
   InitECanGpio();
   DINT;
   InitPieCtrl();
   IER = 0x0000;
   IFR = 0x0000;

   InitPieVectTable();
   
    MessageReceivedCount = 0;
    ErrorCount = 0;
    PassCount = 0;
   
    // Configure the eCAN RX and TX pins for eCAN transmissions
    EALLOW;
    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;
    EDIS;
     
    // Disable all Mailboxes
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    ECanaRegs.CANME.all = 0;

    // Mailboxs can be written to 16-bits or 32-bits at a time
    // Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 15
    ECanaMboxes.MBOX0.MSGID.all = 0xB5550093;
    ECanaMboxes.MBOX1.MSGID.all = 0x95550094;
    ECanaMboxes.MBOX2.MSGID.all = 0x95550122;
    //中间代码略
    ECanaMboxes.MBOX15.MSGID.all = 0x9555AAAF;
   
    // Write to the MSGID field of RECEIVE mailboxes MBOX16 - 31
    ECanaMboxes.MBOX16.MSGID.all = 0xD5550093;
    ECanaMboxes.MBOX17.MSGID.all = 0x95550094;
    ECanaMboxes.MBOX18.MSGID.all = 0x95550122;
    ECanaMboxes.MBOX19.MSGID.all = 0xD5550125;
    //中间代码略
    ECanaMboxes.MBOX31.MSGID.all = 0x9555AAAF;

    // Configure Mailboxes 0-15 as Tx, 16-31 as Rx
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    ECanaRegs.CANMD.all = 0xFFFF0000;
   
    // Enable all Mailboxes */
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    ECanaRegs.CANME.all = 0xFFFFFFFF;

    // Specify that 8 bits will be sent/received
    ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
    ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
    //中间代码略
    ECanaMboxes.MBOX15.MSGCTRL.bit.DLC = 8;
   
    // No remote frame is requested
    // Since RTR bit is undefined upon reset,
    // it must be initialized to the proper value
    ECanaMboxes.MBOX0.MSGCTRL.bit.RTR = 1;
    ECanaMboxes.MBOX1.MSGCTRL.bit.RTR = 0;  
    //中间代码略
    ECanaMboxes.MBOX15.MSGCTRL.bit.RTR = 0;
    ECanaMboxes.MBOX16.MSGCTRL.bit.RTR = 1;//发起远程帧

    // Write to the mailbox RAM field of MBOX0 - 15
    ECanaMboxes.MBOX0.MDL.all = 0x00;
    ECanaMboxes.MBOX0.MDH.all = 0x00;

    ECanaMboxes.MBOX1.MDL.all = 0x1111;
    ECanaMboxes.MBOX1.MDH.all = 0x1111;
    //中间代码略
    ECanaMboxes.MBOX15.MDL.all = 0x9555AAAF;
    ECanaMboxes.MBOX15.MDH.all = 0x89ABCDEF;

    EALLOW;
    ECanaRegs.CANMIM.all = 0xFFFFFFFF;

    // Request permission to change the configuration registers
    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.CCR = 1;            
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    EDIS;
   
    do
    {
      ECanaShadow.CANES.all = ECanaRegs.CANES.all;
    } while(ECanaShadow.CANES.bit.CCE != 1 );  
   
    // Configure the eCAN timing
    EALLOW;
    ECanaShadow.CANBTC.all = ECanaRegs.CANBTC.all;
    ECanaShadow.CANBTC.bit.BRPREG = 9;    // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock
    ECanaShadow.CANBTC.bit.TSEG2REG = 5 ; // to the CAN module. (150 / 10 = 15)
    ECanaShadow.CANBTC.bit.TSEG1REG = 7;  // Bit time = 15
    ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;
   
    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.CCR = 0;            
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    EDIS;

    // Wait until the CPU no longer has permission to change the
    // configuration registers
    do
    {
      ECanaShadow.CANES.all = ECanaRegs.CANES.all;
    } while(ECanaShadow.CANES.bit.CCE != 0 );

    // Configure the eCAN for self test mode
    // Enable the enhanced features of the eCAN.
    EALLOW;
    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
    ECanaShadow.CANMC.bit.STM = 1;    // Configure CAN for ACK mode
    ECanaShadow.CANMC.bit.SCB = 1;    // eCAN mode (reqd to access 32 mailboxes)
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
    EDIS;
   
    // Begin transmitting
    for(;;)                                
    {  
       ECanaRegs.CANTRS.all = 0x0000FFFF;  // Set TRS for all transmit mailboxes
       //ECanaRegs.CANTRS.bit.TRS3=0;
       while(ECanaRegs.CANTA.all != 0x0000FFFF ) {}  // Wait for all TAn bits to be set..
       ECanaRegs.CANTA.all = 0x0000FFFF;   // Clear all TAn
       MessageReceivedCount++;

       ECanaRegs.CANTRS.all = 0x0000FFFF;  // Set TRS for all transmit mailboxes
       ECanaRegs.CANTRS.bit.TRS16=1;
       while(ECanaRegs.CANTA.bit.TA16 != 1 ) {}  // 卡在了这一步过不去
       ECanaRegs.CANTA.bit.TA16 = 1;   // Clear all TAn
       ErrorCount++;
    }
}



使用特权

评论回复

相关帖子

沙发
smile2196|  楼主 | 2020-8-30 18:38 | 只看该作者
有做过CAN通讯这一块的伙伴们能探讨一下远程帧的工程应用吗?第一次做CAN开发,不是很理解远程帧要怎么用

使用特权

评论回复
板凳
airwill| | 2020-8-31 19:30 | 只看该作者
远程帧只是带远程帧特征位的无数据帧的报文, 如何处理是看你的上层协议怎么定义了

使用特权

评论回复
地板
smile2196|  楼主 | 2020-8-31 19:49 | 只看该作者
airwill 发表于 2020-8-31 19:30
远程帧只是带远程帧特征位的无数据帧的报文, 如何处理是看你的上层协议怎么定义了 ...

能帮忙看一下另一个帖子里面的问题吗?我现在没有用自响应来调了,改用PC机和CAN分析仪直接调,但是出现了新的问题https://bbs.21ic.com/icview-3018974-1-1.html

使用特权

评论回复
5
smile2196|  楼主 | 2020-8-31 19:50 | 只看该作者
airwill 发表于 2020-8-31 19:30
远程帧只是带远程帧特征位的无数据帧的报文, 如何处理是看你的上层协议怎么定义了 ...

我现在主要是还不知道实现信息的远程请求要如何实现

使用特权

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

本版积分规则

9

主题

19

帖子

0

粉丝