AnsweredAssumed Answered

Using Multiple Tx MBs for transmiting CAN Messages

Question asked by David XY Zhou on Sep 2, 2016
Latest reply on Sep 20, 2016 by David XY Zhou

Hi,

I Have K60 Tower board: _K60P144M150SF3RM. using Code Warrior 10.6.4 and MQX 4.2

I have the following code for transmitting CAN Messages. It works if one TX MB is used for transmitting, or if any TX MB is busy, just return the function and do another try. But if one of the MB is busy, i.e. Not NOT_ACTIVE, then it cannot use another MB for TX. Although multiple TX MBs are scanned for highest priority message to be TX-ed first. It shall allow using multiple TX MBs. Something is not right. What needs to be done for using multiple TX MBs for transmitting?

 

uint8_t TransmitCanMsg(uint8_t bCANId_Index, uint8_t bTail) {
volatile CanMemMapPtr pCanReg = _bsp_get_flexcan_base_address(0);
int i=0;
volatile uint8_t bMbID = 0;
volatile uint8_t bBusy = TRUE;

 

for (i=8; i<(8+NUM_OF_MB_USED_TX); i++) {  
_disable_int();
if ((pCanReg->MB[i].CS & CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE))== CAN_CS_CODE(CAN_TX_MSG_BUFFER_NOT_ACTIVE)) {
    bBusy = FALSE;
}
_enable_int();


if ( bBusy == TRUE) {
    continue;
}
pCanReg->MB[i].ID  &= ~(0x1FFFFFFF);  //clear
pCanReg->MB[i].ID = MyID & 0x1FFFFFFF ;
pCanReg->MB[i].WORD0 = MyWORD0;  
pCanReg->MB[i].WORD1 = MyWORD1;  
     // Set IDE  //Set SRR bit -Not Set
pCanReg->MB[bMbID].CS &= ~(CAN_CS_CODE_MASK);    // Reset the code
//pCanReg->MB[i].CS &= ~CAN_CS_DLC_MASK;    //Clear the DLC
pCanReg->MB[bMbID].CS |= (CAN_CS_IDE_MASK | (CAN_CS_CODE(CAN_MESSAGE_TRANSMIT_ONCE) | TX_DLC));  
return 1;     //transmitted
}
return 0;                                                 
}

 

 

Thank you,

David Zhou

Outcomes