AnsweredAssumed Answered

FlexCan Transmit MB issue

Question asked by David XY Zhou on Mar 16, 2016
Latest reply on Mar 17, 2016 by David XY Zhou

Hi,

I have two MBs setup for transmit CAN IDs. MB[8] and MB[10].

I copied TX task here:

while (1) {

//1. Check MB is Active or not, if so abort process

if (iBuffer==0) {//Use MB[8] for ID=0x0C20FF00

   iBuffer=1;   

   if ((g_pCanReg1->MB[8].CS & CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE))== CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE)) { // check if mailbox is set for transmit           

      //2. write ID and Data

      g_pCanReg1->MB[8].CS; // |= CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE); // Locking mailbox

      g_pCanReg1->MB[8].CS = CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE);   

      g_pCanReg1->MB[8].CS |= (DEFAULT_DLC_8 << CAN_CS_DLC_SHIFT); 

      g_pCanReg1->MB[8].CS &= ~CAN_CS_SRR_MASK;            

      g_pCanReg1->MB[8].CS |= CAN_CS_IDE_MASK;        

      g_pCanReg1->MB[8].ID &= ~(0x1FFFFFFF);

      g_pCanReg1->MB[8].ID |= (0x0C20FF00L & 0x1FFFFFFF);

      g_pCanReg1->MB[8].WORD0++;

      g_pCanReg1->MB[8].WORD1++;

      g_pCanReg1->MB[8].CS |= (CAN_CS_CODE(CAN_MESSAGE_TRANSMIT_ONCE) | TX_DLC); //transmit data

   }

   else {  //NOT ready

      iTxError0++;

   }

}

else {  //Use MB[8] for ID=0x0C21FF00

   iBuffer=0;

   if ((g_pCanReg1->MB[10].CS & CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE))==  

             CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE)) { // check if mailbox is set for transmit           

      g_pCanReg1->MB[10].CS;  // |= CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE); // Locking mailbox

      g_pCanReg1->MB[10].CS = CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE);        //Initialize CODE Status

      g_pCanReg1->MB[10].CS |= (DEFAULT_DLC_8 << CAN_CS_DLC_SHIFT); 

      g_pCanReg1->MB[10].CS &= ~CAN_CS_SRR_MASK;                    

      g_pCanReg1->MB[10].CS |= CAN_CS_IDE_MASK;                    

      g_pCanReg1->MB[10].ID &= ~(0x1FFFFFFF);

      g_pCanReg1->MB[10].ID |= (0x0C21FF00L & 0x1FFFFFFF);

      g_pCanReg1->MB[10].WORD0 ++;

      g_pCanReg1->MB[10].WORD1 ++;

      g_pCanReg1->MB[10].CS |= (CAN_CS_CODE(CAN_MESSAGE_TRANSMIT_ONCE) | TX_DLC); // transmit data

   }

   else {//NOT ready

      iTxError1++;

   }

}

if ((iTxError0!=0 || iTxError1 !=0)) {

}

} //end while

_time_delay(1);

// end of the task

The code runs ok without error.  But if the last line _time_delay(1) is commented out, it causes a problem.

The transmit doesn't use interrupt. interrupt mask is not enable and interrupt ISR is not installed.

The logic is simple:

    check the MB for TX is not active, then setup data, status, and transmit once.

     if is active, skip it. ErrorCount++;

    two MBs alternatively to transmit each ID.

Run results:

    no error counter is logged.

    Both IDs are transmitted.

    But from CAN capture problem, it also transmitted another Standard ID=0x308 periodically. I don't know where this ID come from. If I transmit just one MB, either of the both, it will receive the above 0x308 ID.

  it seems that transmit has error. I though the transmit arbitration process shall take care of the MBs transmit. What's the best way to resolve it?

 

It runs on K60 tower.

 

Thank you,

David

Outcomes