Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

XMC7000 MCU: Get the index of the last transmitted CANFD Tx buffer – KBA231463

XMC7000 MCU: Get the index of the last transmitted CANFD Tx buffer – KBA231463

LinglingG_46
Moderator
Moderator
Moderator
10 questions asked 5 questions asked 250 sign-ins

XMC7000 MCU: Get the index of the last transmitted CANFD Tx buffer – KBA231463

 

In the XMC7000 MCU family, after the CAN FD message in the Tx buffer is transmitted, the corresponding bit of the CANFDx_CHx_TXBTO register is set, but it will be reset only when a new transmission is requested. Therefore, the last transmitted Tx buffer index may not be identified directly by the value in the CANFD_CH_TXBTO register.

See the following description of the CANFD_CH_TXBTO register in XMC7000 MCU family register TRM.

LinglingG_46_0-1673945086547.png

 

LinglingG_46_1-1673945099140.png

An alternative software method to get the Tx buffer index is shown in the following example:

1.Enable Tx buffer transmission interrupt by setting the corresponding bit in the CANFDx_CHx_TXBTIE register when the Tx transmission is requested.

//Enable one Tx buffer interrupt 

CANFD0_CH1 ->M_TTCAN.TXBTIE = 1ul << vTxBufferIndex;

//Transmit Tx message in the Tx buffer

Cy_CANFD_UpdateAndTransmitMsgBuffer((CANFD_HW,CAN_HW_CHANNEL,  &CANFD_txBuffer_0,CAN_BUFFER_INDEX, &canfd_context););

2.When the Transmission Completed interrupt is set (CANFDx_CHx_IR.TC = 1), the last transmitted Tx buffer index can be identified by checking the CANFDx_CHx_TXBTIE and CANFDx_CHx_TXBTO registers. When this bit of both registers is set, the corresponding bit is the index of the last transmitted Tx Buffer.

3.Clear CANFDx_CHx_TXBTIE register.

//Get TXBTIE register value

vTxBufIntStatus = CANFD0_CH1_M_TTCAN->TXBTIE;

//Check bits of register TXBTIE and TXBTO

for(vIndex=0;vIndex < 32;vIndex++)

{

        vTxbufSatus=Cy_CANFD_GetTxBufferStatus(CANFD_HW,CAN_HW_CHANNEL,1);

        //TXBTIE.bit == 1 and TXBTO.TOx =1, TX buffer transmit occured/successful and TXBCF.CFx =0 no cancel

        if (((1ul << vIndex)& vTxBufIntStatus) && (vTxbufStatus == CY_CANFD_TX_BUFFER_TRANSMIT_OCCURRED))

        { 

            //disable Tx buffer interrupt 

            CANFD0_CH1_M_TTCAN.TXBTIE = 0x00000000;

            //vIndex is the last transmitted Tx buffer index

            gTxBufferIndex = vIndex;

        }

 

 

Attachments
0 Likes
37 Views
Contributors