AnsweredAssumed Answered

CAN transmission using Non-blocking method?

Question asked by Manikanta G on Feb 22, 2019
Latest reply on Mar 5, 2019 by Manikanta G

Hi community,

I am trying to transmit CAN message using non-blocking method using MCAN_TransferSendNonBlocking(...) function.

For that I have taken reference from example project "mcan_interrupt_transfer" provided in SDK. But it is not working as expected. I've created a transfer handle using MCAN_TransferCreateHandle(...) , a callback function & a transmit buffer configuration. Everything looks very fine but it still doesn't work. Have a look at the code below. What else can be wrong? Alexis Andalon can you help me again?

 

/* All variables are created but not shown here */

/* Create MCAN handle structure and set call back function. */

MCAN_TransferCreateHandle(CAN0, &mcanHandle, mcan_callback, NULL);

/* TX buffer config. */

txBuffer.address = TX_BUFFER_OFS;   // 0x20U

txBuffer.dedicatedSize = 1U;

txBuffer.fqSize = 0;

txBuffer.datafieldSize = kMCAN_8ByteDatafield;

MCAN_SetTxBufferConfig(CAN0, &txBuffer);

 

/* This part is in CAN transmit function */

{

TxHandle.frame = &TxFrame;

TxHandle.bufferIdx = 0;

MCAN_TransferSendNonBlocking(CAN0,&mcanHandle,&TxHandle);

free(tx_data);

while ( !txComplete )        //THIS IS WHERE PROGRAM GETTING STUCK although callback function is set properly

 { }                                     // txComplete variable is always zero and never becoming 'true' so while becomes infinite loop

txComplete = false;

}


// MCAN Call Back function
static void mcan_callback(CAN_Type *base, mcan_handle_t *handle, status_t status, uint32_t result, void *userData)
{
switch (status)
{
case kStatus_MCAN_RxFifo0Idle:
      rxComplete = true;
break;

case kStatus_MCAN_TxIdle:
      txComplete = true;
break;

default:
break;
}
}

 

Note: Most of the code is from SDK only while variables are changed.

Outcomes