This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CAN message lost

Other Parts Discussed in Thread: TMS320F28033

Hello,

I'm working on the TMS320F28033 and configured my CAN module as an eCan and running at 250kbps. During a bootload sequence (data received all 2ms - TP_DT_RX in the code below), I sometime have to send a diagnostic message (DM1 in the code below), and it could happens that the message following the diag message is lost, but not always. The received procedure is based on polling the message and not on an interrupt.

After 1 week of analysis, I can already say that it is depending of the configuration of the Data RX mailbox. The problem occurs only when the received mailbox is set between 16 and 31. If it is between 0 and 15, the problem doesn't occur. I as well checked the configuration of the CAN module but didn't see something...

Here is code for the init of the CAN:

void CanInit(void)
{
   volatile struct  ECAN_REGS  ECanaShadow;

   EALLOW;

   /* 1.0) Reset the CAN module (SRES = 1) and interrupt all pending CAN requests. */
   ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
   ECanaShadow.CANMC.bit.SRES = 1;
   ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;

   /* 1.1) Enable clock to the CAN module */
   SysCtrlRegs.PCLKCR0.bit.ECANAENCLK = 1;

   /* 1.2) Set the CANTX and the CANRX pins to CAN functions */
   GpioCtrlRegs.GPAPUD.bit.GPIO30     = 1;                        /* Disable pull-up for GPIO30 (CANRXA) */
   GpioCtrlRegs.GPAPUD.bit.GPIO31     = 0;                        /* Enable pull-up for GPIO31 (CANTXA) */
   GpioCtrlRegs.GPAQSEL2.bit.GPIO30   = 3;                        /* Asynch qual for GPIO30 (CANRXA) */
   GpioCtrlRegs.GPAMUX2.bit.GPIO30    = 1;                        /* Configure GPIO30 for CANRXA operation */
   GpioCtrlRegs.GPAMUX2.bit.GPIO31    = 1;                        /* Configure GPIO31 for CANTXA operation */
   ECanaRegs.CANTIOC.bit.TXFUNC       = 1;                        /* Config CANTX for CAN use */
   ECanaRegs.CANRIOC.bit.RXFUNC       = 1;                        /* Config CANRX for CAN use */

   /* 1.3) After a reset, bit CCR (CANMC.12) and bit CCE (CANES.4) are set to 1. Check just in case */
   ECanaShadow.CANMC.all              = ECanaRegs.CANMC.all;      /* Set CCR to enter config mode */
   ECanaShadow.CANMC.bit.CCR      = 1;
   ECanaRegs.CANMC.all                = ECanaShadow.CANMC.all;

   ECanaShadow.CANES.all              = ECanaRegs.CANES.all;      /* Wait for CCE bit to be set... */
   while( ECanaShadow.CANES.bit.CCE != 1 )
   {
      ECanaShadow.CANES.all = ECanaRegs.CANES.all;
   }

   /* 1.4) Program the CANBTC register with timing values (Calculate with can_timing.m in project folder) */
   ECanaShadow.CANBTC.all       = CanBtc;
   ECanaRegs.CANBTC.all           = ECanaShadow.CANBTC.all;

   /* 1.5) For the SCC, program the acceptance masks now */
   /* Not necessary in eCAN mode!!! */

   /* 1.6a) Program the master control register (CANMC) */
   ECanaRegs.CANMC.all            = 0x0001A280;                   /* Master Control Register: SUSP = 1, MBCC = 1, SCB = 1, WUBA = 1, ABO = 1 */

   /* 1.6b) Initialize CAN interrupt */
   ECanaRegs.CANGIM.all           = 0x00000000;                   /* Global Interrupt Mask Register: Disable all interrupts */
   ECanaRegs.CANMIM.all           = 0x00000000;                   /* Mailbox Interrupt Mask Register: Disable all interrupts */
   ECanaRegs.CANMIL.all           = 0x00000000;                   /* All interrupts on Line 0 */
   ECanaRegs.CANRMP.all           = 0xFFFFFFFF;                   /* Reset all */

   /* 1.7) Initialize all bits of MSGCTRLn registers 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;

   /* 1.8) Verify that the CCE bit is cleared */
   ECanaShadow.CANES.all          = ECanaRegs.CANES.all;
   while(ECanaShadow.CANES.bit.CCE != 0)
   {
      ECanaShadow.CANES.all = ECanaRegs.CANES.all;
   }

   /* 2.0) Clear the appropriate bit in the CANTRS register to 0 by setting CANTRR */
   ECanaRegs.CANTRR.all          = 0xFFFFFFFF;                       /* Clear all! */
   ECanaShadow.CANTRS.all        = ECanaRegs.CANTRS.all;
   while(ECanaShadow.CANTRS.all != 0)
   {
      ECanaShadow.CANTRS.all     = ECanaRegs.CANTRS.all;
   }
   
   /* 2.1) Disable the mailbox by clearing the corresponding bit in the mailbox enable (CANME) register */
   ECanaRegs.CANME.all                 = 0x00000000;                 /* Clear all! */

   /* 3.11) Configure Mailbox 11 as Tx */
   DM1_TX.MSGID.all                    = DM1_TX_BASE_ID + CanSourceAddress;                       
                                                                     /* Message ID, write this first! */
   DM1_TX.MSGID.bit.IDE                = 1;                          /* Extended ID */
   DM1_TX.MSGCTRL.bit.DLC              = 8;                          /* Data length */
   DM1_TX.MSGCTRL.bit.RTR              = 0;                          /* Remote Transmission Request disabled */
   DM1_TX.MSGCTRL.bit.TPL              = 28;                         /* Pritority level, highest number highest priority */

   /* 3.13) Configure Mailbox 13 as Rx */
   DM14_RX.MSGID.all                   = DM14_RX_BASE_ID + ((uint16)CanSourceAddress<<8);                          
                                                                     /* Message ID, write this first! */
   DM14_RX.MSGID.bit.IDE               = 1;                          /* Extended ID */
   DM14_RX.MSGID.bit.AME               = 1;                          /* Acceptance mask enable '1' */
   DM14_RX.MSGCTRL.bit.DLC             = 8;                          /* Data length */
   DM14_RX.MSGCTRL.bit.RTR             = 0;                          /* Remote Transmission Request disabled */
   DM14_RX.MSGCTRL.bit.TPL             = 0;                          /* Pritority level, highest number highest priority */
   DM14_RX_MASK_REG                    = DM14_RX_MASK;               /* Acceptance mask (1=don't care) */

   /* 3.14) Configure Mailbox 14 as Tx */
   DM15_TX.MSGID.all                   = DM15_TX_BASE_ID + CanSourceAddress;                       
                                                                     /* Message ID, write this first! */
   DM15_TX.MSGID.bit.IDE               = 1;                          /* Extended ID */
   DM15_TX.MSGCTRL.bit.DLC             = 8;                          /* Data length */
   DM15_TX.MSGCTRL.bit.RTR             = 0;                          /* Remote Transmission Request disabled */
   DM15_TX.MSGCTRL.bit.TPL             = 0;                          /* Pritority level, highest number highest priority */

   /* 3.15) Configure Mailbox 15 as Tx */
   TP_CM_TX.MSGID.all                  = TP_CM_TX_BASE_ID + CanSourceAddress;                       
                                                                     /* Message ID, write this first! */
   TP_CM_TX.MSGID.bit.IDE              = 1;                          /* Extended ID */
   TP_CM_TX.MSGCTRL.bit.DLC            = 8;                          /* Data length */
   TP_CM_TX.MSGCTRL.bit.RTR            = 0;                          /* Remote Transmission Request disabled */
   TP_CM_TX.MSGCTRL.bit.TPL            = 15;                         /* Pritority level, highest number highest priority */

   /* 3.19) Configure Mailbox 19 as Rx */
   TP_CM_RX.MSGID.all                  = TP_CM_RX_BASE_ID + ((uint16)CanSourceAddress<<8);                          
                                                                     /* Message ID, write this first! */
   TP_CM_RX.MSGID.bit.IDE              = 1;                          /* Extended ID */
   TP_CM_RX.MSGID.bit.AME              = 1;                          /* Acceptance mask enable '1' */
   TP_CM_RX.MSGCTRL.bit.DLC            = 8;                          /* Data length */
   TP_CM_RX.MSGCTRL.bit.RTR            = 0;                          /* Remote Transmission Request disabled */
   TP_CM_RX.MSGCTRL.bit.TPL            = 0;                          /* Pritority level, highest number highest priority */
   TP_CM_RX_MASK_REG                   = TP_CM_RX_MASK;              /* Acceptance mask (1=don't care) */

   /* 3.20) Configure Mailbox 20 as Rx */
   TP_DT_RX.MSGID.all                  = TP_DT_RX_BASE_ID + ((uint16)CanSourceAddress<<8);                          
                                                                     /* Message ID, write this first! */
   TP_DT_RX.MSGID.bit.IDE              = 1;                          /* Extended ID */
   TP_DT_RX.MSGID.bit.AME              = 1;                          /* Acceptance mask enable '1' */
   TP_DT_RX.MSGCTRL.bit.DLC            = 8;                          /* Data length */
   TP_DT_RX.MSGCTRL.bit.RTR            = 0;                          /* Remote Transmission Request disabled */
   TP_DT_RX.MSGCTRL.bit.TPL            = 0;                          /* Pritority level, highest number highest priority */
   TP_DT_RX_MASK_REG                   = TP_DT_RX_MASK;              /* Acceptance mask (1=don't care) */

   /* 3.21) Configure Mailbox 21 as Rx */
   DM16_RX.MSGID.all                   = DM16_RX_BASE_ID + ((uint16)CanSourceAddress<<8);                          
                                                                     /* Message ID, write this first! */
   DM16_RX.MSGID.bit.IDE               = 1;                          /* Extended ID */
   DM16_RX.MSGID.bit.AME               = 1;                          /* Acceptance mask enable '1' */
   DM16_RX.MSGCTRL.bit.DLC             = 8;                          /* Data length */
   DM16_RX.MSGCTRL.bit.RTR             = 0;                          /* Remote Transmission Request disabled */
   DM16_RX.MSGCTRL.bit.TPL             = 0;                          /* Pritority level, highest number highest priority */
   DM16_RX_MASK_REG                    = TP_DT_RX_MASK;              /* Acceptance mask (1=don't care) */

   /* Set direction and enable (OBS only 32 bit acces!) */
   ECanaRegs.CANOPC.all               = 0x00000000;                  /* Overwrite protection disable */
   ECanaRegs.CANMD.all                = 0xFFFFFFFF - ALL_MBOX_TX;    /* Transmit direction 0=Tx, 1=Rx */
   ECanaRegs.CANME.all                = ALL_MBOX;                    /* Enable mailbox */

   /* Disable TIME-OUT interrupt */
   ECanaShadow.CANTOC.all = ECanaRegs.CANTOC.all;                    /* Disable Time-Out for all mailbox's */
   ECanaShadow.CANTOC.all = 0;
   ECanaRegs.CANTOC.all = ECanaShadow.CANTOC.all;

   EDIS;
}

Any idea why I sometime lost my data?

Many thanks in advance for your help

Steve