AnsweredAssumed Answered

How to clear CAN TX flag CANTFLG.TXE to indicate the message buffer is full after a FIFO write done?

Question asked by dongpeng hou on Apr 1, 2014
Latest reply on Apr 2, 2014 by dongpeng hou

Hello, the CAN Transmit Buffer Empty flag CANTFLG.TXE is set to 1 to clear it, after a write FIFO done to start the transmission, is that? Because from the example code below, after the TX FIFO is filled, CANTFLG = TxbufSel, at this time, TxbufSel is read from CANTBSEL, the bit of selected FIFO should be set.

 

byte CanTxFrame(CanMsg_t msg)

{  

    byte TxbufSel;        

    byte idx;           // Index to data within the transmission buffer

   

    if (!CANTFLG)       // Retrun if Transmit Buffer is full

        return ERR_BUFFER_FULL;

 

 

    CANTBSEL = CANTFLG; // Select lowest empty buffer

    TxbufSel = CANTBSEL; // Backup selected buffer

   

    *((word *) ((word)(&CANTXIDR0)))= msg.ID<<5;   // 11bit ID, RTR=0: data frame; IDE=0

       

// Load data to Data Segment Registers

    for (idx=0; idx<(msg.DtLen); idx++) {

        *(&CANTXDSR0 + idx) = (msg.data)[idx]; 

    }

 

 

    CANTXDLR  = msg.DtLen;   // set Data Length Code

    CANTXTBPR = 0;           // set highest priority

 

 

    CANTFLG = TxbufSel;      // Start transmission

               

    while ( (CANTFLG&TxbufSel) != TxbufSel);  // Wait for Transmission completion

           

    return NO_ERR;

}

Outcomes