打印

eCAN信息发送后TA位不置位是为啥?

[复制链接]
7325|15
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
不锈钢铁|  楼主 | 2012-9-22 15:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
小鸟用的是2808,最近用到了eCAN,接收没有问题,但是发送遇到了问题,程序总是卡在while(ECanbRegs.CANTA.bit.TA1 != 1 ) {}  ,但是接上USBCAN后,我发现信息已经发送出去了,每次都是发送出去后,卡在while(ECanbRegs.CANTA.bit.TA1 != 1 ) {}  。
不是说CAN信息成功发送后TAx位会置位的嘛,哪位遇到过相同的问题?

相关帖子

沙发
不锈钢铁|  楼主 | 2012-9-22 15:38 | 只看该作者
void InitECan(void)
{
   InitECana();
   ECanaMboxes.MBOX0.MSGID.bit.IDE = 0; // Standard Identifier
   ECanaMboxes.MBOX1.MSGID.bit.IDE = 0;
   ECanaMboxes.MBOX0.MSGID.bit.AME = 0;
   ECanaMboxes.MBOX1.MSGID.bit.AME = 0;
   ECanaMboxes.MBOX0.MSGID.bit.STDMSGID = 0xB0; // Standard Identifier
   ECanaMboxes.MBOX1.MSGID.bit.STDMSGID = 0xB1;
   ECanaMboxes.MBOX0.MSGID.bit.AAM = 0;
   ECanaMboxes.MBOX1.MSGID.bit.AAM = 0;
   ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 4;
   ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 4;

   ECanaShadow.CANMD.all = ECanaRegs.CANMD.all;
   ECanaShadow.CANMD.bit.MD0 = 0; // Transmit
   ECanaShadow.CANMD.bit.MD1 = 0; // Transmit
   ECanaRegs.CANMD.all = ECanaShadow.CANMD.all;

   ECanaShadow.CANME.all = ECanaRegs.CANME.all;
   ECanaShadow.CANME.bit.ME0 = 1;
   ECanaShadow.CANME.bit.ME1 = 1;
   ECanaRegs.CANME.all = ECanaShadow.CANME.all;
}
  void InitECana(void)                // Initialize eCAN-A module
{

/* Create a shadow register structure for the CAN control registers. This is
needed, since only 32-bit access is allowed to these registers. 16-bit access
to these registers could potentially corrupt the register contents or return
false data. This is especially true while writing to/reading from a bit
(or group of bits) among bits 16 - 31 */

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

        ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
        ECanaShadow.CANMC.bit.SCB = 1;
        ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

/* Initialize all bits of 'Message Control Register' 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;
    ECanaMboxes.MBOX16.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX17.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX18.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX19.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX20.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX21.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX22.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX23.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX24.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX25.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX26.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX27.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX28.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX29.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX30.MSGCTRL.all = 0x00000000;
    ECanaMboxes.MBOX31.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;


/* 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;

    // Wait until the CPU has been granted permission to change the configuration registers
    do
    {
      ECanaShadow.CANES.all = ECanaRegs.CANES.all;
    } while(ECanaShadow.CANES.bit.CCE != 1 );                  // Wait for CCE bit to be set..

           ECanaShadow.CANBTC.all = 0;

           #if (CPU_FRQ_100MHZ)     // CPU_FRQ_100MHz is defined in DSP280x_Examples.h

       /* The following block for all 100 MHz SYSCLKOUT - default. Bit rate = 1 Mbps */

               ECanaShadow.CANBTC.bit.BRPREG = 9;
            ECanaShadow.CANBTC.bit.TSEG2REG = 1;
            ECanaShadow.CANBTC.bit.TSEG1REG = 6;
    #endif

    #if (CPU_FRQ_60MHZ) // CPU_FRQ_60MHz is defined in DSP280x_Examples.h

       /* The following block is only for 60 MHz SYSCLKOUT. Bit rate = 1 Mbps */

               ECanaShadow.CANBTC.bit.BRPREG = 3;
            ECanaShadow.CANBTC.bit.TSEG2REG = 2;
            ECanaShadow.CANBTC.bit.TSEG1REG = 10;
    #endif

    ECanaShadow.CANBTC.bit.SAM = 1;
    ECanaRegs.CANBTC.all = ECanaShadow.CANBTC.all;

    ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
        ECanaShadow.CANMC.bit.CCR = 0 ;            // Set CCR = 0
    ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

    // 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 );                 // Wait for CCE bit to be  cleared..

/* Disable all Mailboxes  */
        ECanaRegs.CANME.all = 0;                // Required before writing the MSGIDs

    EDIS;
}

使用特权

评论回复
板凳
不锈钢铁|  楼主 | 2012-9-22 15:39 | 只看该作者
发送的语句
                        ECanaRegs.CANMC.bit.CDR = 1;    // Set the change data request bit
                        ECanaMboxes.MBOX0.MDL.all = aver_ADCB0_vol;
                        ECanaShadow.CANTRS.all =0;
                           ECanaShadow.CANTRS.bit.TRS1 = 1;  // Set TRS for all transmit mailboxes
                           ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all;
                        while(ECanbRegs.CANTA.bit.TA1 == 0 ) {}  // Wait for all TAn bits to be set..
                           ECanaShadow.CANTA.all = 0x00000000;
                           ECanaShadow.CANTA.bit.TA1 = 1;   // Clear all TAn
                           ECanaRegs.CANTA.all = ECanaShadow.CANTA.all;

使用特权

评论回复
地板
不锈钢铁|  楼主 | 2012-9-24 16:41 | 只看该作者
找到原因了。。。蛋疼

使用特权

评论回复
5
wjzx111056| | 2012-9-24 19:51 | 只看该作者
LZ,是什么原因呢?和大家分享一下啊!让大家也学习学习。

使用特权

评论回复
6
happybird21| | 2012-9-24 23:06 | 只看该作者
程序真长,看的都眼花了

使用特权

评论回复
7
ZLSWRH| | 2012-9-27 17:19 | 只看该作者
LZ,是什么原因呢?和大家分享一下啊!让大家也学习学习。

使用特权

评论回复
8
不锈钢铁|  楼主 | 2012-10-9 08:00 | 只看该作者
7# ZLSWRH
用影子寄存器读标志位,然后判断

使用特权

评论回复
9
ZLSWRH| | 2012-10-10 20:29 | 只看该作者
do   {
               ECanaShadow.CANTA.bit.TA1= ECanaRegs.CANTA.bit.TA1;
        }while(ECanaShadow.CANTA.bit.TA1!=1);
这样也不行,请问如何改!

使用特权

评论回复
10
ZLSWRH| | 2012-10-10 21:06 | 只看该作者
有人说:发送的id应该和对面接收的id 一样,是不是要找块ecan的板子来试吗?市面上卖的USBCAN不能用吗(即使波特率一致也不行,销售人员说:只要波特率一致,有发就有收)?USBCAN在和STM32通讯就有数据!这些问题请高手帮忙解释一下!

使用特权

评论回复
11
心店言己| | 2013-12-10 20:11 | 只看该作者
我特别想问一个下,CANTA在消息发送成功的时候会被置位,它复位后是0,那置位后应为1,为什么条件是.TA1 != 1 ?
求指导。

使用特权

评论回复
12
心店言己| | 2013-12-10 20:26 | 只看该作者
好吧~这是等待它置位的程序,我用的是DSP,不知道怎么用影子寄存器,还有其他的方式可以解决这个问题吗?

使用特权

评论回复
13
心店言己| | 2013-12-10 21:27 | 只看该作者
我用的是DSP28335,eCAN模式用CCS5.2看寄存器,它的TA位没有被置位。我看了好几遍程序了,找不到问题所在,能帮忙看下吗?

使用特权

评论回复
14
心店言己| | 2013-12-10 21:29 | 只看该作者
#define          LED1        GpioDataRegs.GPADAT.bit.GPIO0

void main(void)
{

   Uint16  j;
   Uint32  k;

   struct ECAN_REGS ECanbShadow;
   
   InitSysCtrl(); //³õʼ»¯ÏµÍ³

   InitECanGpio();//ÅäÖÃGPIOÒý½Å

   DINT;
   InitPieCtrl();//³õʼ»¯PIEÖжÏ

   IER = 0x0000;//¹ØÖжÏ
   IFR = 0x0000;

   InitPieVectTable();//³õʼ»¯PIEÖжÏʸÁ¿±í

    MessageReceivedCount = 0;
    ErrorCount = 0;
    PassCount = 0;
   
    EALLOW;//ÅäÖÃeCANµÄRXºÍTX·Ö±ðΪeCANµÄ½ÓÊպͷ¢ËÍÒý½Å
    ECanbShadow.CANTIOC.all = ECanbRegs.CANTIOC.all;
    ECanbShadow.CANTIOC.bit.TXFUNC = 1;
    ECanbRegs.CANTIOC.all = ECanbShadow.CANTIOC.all;

    ECanbShadow.CANRIOC.all = ECanbRegs.CANRIOC.all;
    ECanbShadow.CANRIOC.bit.RXFUNC = 1;
    ECanbRegs.CANRIOC.all = ECanbShadow.CANRIOC.all;
    EDIS;

    // Configure the eCAN for self test mode
      // Enable the enhanced features of the eCAN.
    EALLOW;
    ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
    ECanbShadow.CANMC.bit.STM = 0;    // Configure CAN for self-test mode
    ECanbShadow.CANMC.bit.SCB = 1;    // eCAN mode (reqd to access 32 mailboxes)
    ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
    EDIS;

                         EALLOW;
                     GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0; // GPIO0 = GPIO0
                     GpioCtrlRegs.GPADIR.bit.GPIO0 = 1;
                     EDIS;

                     ECanaRegs.CANTRR.all= 0xFFFFFFFF;
                     ECanaRegs.CANTA.all= 0xFFFFFFFF;

    // Disable all Mailboxes
    ECanbRegs.CANME.all = 0;

                          EALLOW;
                          ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
                          ECanbShadow.CANMC.bit.CDR=1;
                          ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
                          EDIS;

   //ÉèÖ÷¢ËÍÓÊÏäID  À©Õ¹Ö¡
    ECanbMboxes.MBOX0.MSGID.all = 0x00000000;
   
    // Write to the MSGID field of RECEIVE mailboxes MBOX16
    ECanbMboxes.MBOX16.MSGID.all = 0x9555AAA0;
  
/*    // 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.
    ECanbRegs.CANMD.all = 0xFFFF0000;
*/
   //ÓÊÏä0ΪTX
        ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
        ECanbShadow.CANMD.bit.MD0 =0;
        ECanbShadow.CANMD.bit.MD16 =1;
        ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;

/*  // Enable all Mailboxes
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    ECanbRegs.CANME.all = 0xFFFFFFFF;
*/

    // Specify that 8 bits will be sent/received
    ECanbMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
   
    // No remote frame is requested   Ã»ÓÐÔ¶·½Ó¦´ðÖ¡
    // Since RTR bit is undefined upon reset,
    // it must be initialized to the proper value
    ECanbMboxes.MBOX0.MSGCTRL.bit.RTR = 0;      
   
    // Write to the mailbox RAM field of MBOX0
    ECanbMboxes.MBOX0.MDL.all = 0x01010101;
    ECanbMboxes.MBOX0.MDH.all = 0x01010101;


                                        EALLOW;
                                        ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
                                        ECanbShadow.CANMC.bit.CDR = 0;
                                        ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
                                        EDIS;

                                  //ÓÊÏäʹÄÜMailbox0 16
                                           ECanbShadow.CANME.all = ECanbRegs.CANME.all;
                                           ECanbShadow.CANME.bit.ME0 =1;
                                           ECanbShadow.CANME.bit.ME16 =1;
                                           ECanbRegs.CANME.all = ECanbShadow.CANME.all;


    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    EALLOW;
    ECanbRegs.CANMIM.all = 0xFFFFFFFF;//ʹÄÜÓÊÏäÖжÏ

    // Request permission to change the configuration registers
    ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
    ECanbShadow.CANMC.bit.CCR = 1;            
    ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
    EDIS;
   
    // Wait until the CPU has been granted permission to change the
    // configuration registers
    // Wait for CCE bit to be set..
    do
    {
      ECanbShadow.CANES.all = ECanbRegs.CANES.all;
    } while(ECanbShadow.CANES.bit.CCE != 1 );  
   
    // Configure the eCAN timing
    EALLOW;
    ECanbShadow.CANBTC.all = ECanbRegs.CANBTC.all;

    ECanbShadow.CANBTC.bit.BRPREG = 9;    // (BRPREG + 1) = 10 feeds a 15 MHz CAN clock
    ECanbShadow.CANBTC.bit.TSEG2REG = 5 ; // to the CAN module. (150 / 10 = 15)  5   7
    ECanbShadow.CANBTC.bit.TSEG1REG = 7;  // Bit time = 15                      7    15
    ECanbRegs.CANBTC.all = ECanbShadow.CANBTC.all;//1Mbps  600
   
    ECanbShadow.CANMC.all = ECanbRegs.CANMC.all;
    ECanbShadow.CANMC.bit.CCR = 0;            
    ECanbRegs.CANMC.all = ECanbShadow.CANMC.all;
    EDIS;

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



   
    // Begin transmitting
    for(;;)                                
    {
     
                LED1 = 1;
                for(j=0;j<1000;j++)
                   for(k=0;k<1000;k++);
                LED1 = 0;
                for(j=0;j<1000;j++)
                   for(k=0;k<1000;k++);
//                DELAY_US(500);

       ECanbRegs.CANTRS.all = 0x00000001;  // Set TRS for all transmit mailboxes
//       while(ECanbRegs.CANTA.all == 0x0000FFFF ) {}  // Wait for all TAn bits to be set..
       while(ECanbRegs.CANTA.all == 0){}
       ECanbRegs.CANTA.all = 0x00000001;   // Clear Mailbox0 TAn   

       MessageSendCount++;
//       MessageReceivedCount++;

       ECanbMboxes.MBOX0.MDL.all = 0x01010101;
       ECanbMboxes.MBOX0.MDH.all = 0x01010101;

使用特权

评论回复
15
mountainest| | 2014-12-6 15:00 | 只看该作者
不锈钢铁 发表于 2012-10-9 08:00
7# ZLSWRH  
用影子寄存器读标志位,然后判断

我用了影子寄存器,为什么还是一直不置位?

使用特权

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

本版积分规则

个人签名:小鸟快跑

31

主题

730

帖子

5

粉丝