CAN transmission using Non-blocking method?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAN transmission using Non-blocking method?

1,813 Views
gmk1
Contributor III

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? nxf46116‌ 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.

Labels (4)
0 Kudos
Reply
5 Replies

1,406 Views
Alexis_A
NXP TechSupport
NXP TechSupport

Hi Manikanta,

 

It's a pleasure to help you again. I have some questions about this.

 

  • Are you using a custom board or an LPCXpresso54xxx?
  • How are you testing the package reception? Are you using other board to receive the package or is in loopback mode?
  • If you are using other device, the device ID is the same of the other device?  The baud rate is the same in both devices?
  • Do you have any way to check if the other device set the acknowledge after sending the package?

 

Best Regards,

Alexis Andalon

0 Kudos
Reply

1,406 Views
gmk1
Contributor III

Hi Alexis...

Can you provide transmission irq handler just like receive handler below?

 

void CAN1_IRQ1_IRQHandler(void)
{
    MCAN_ClearStatusFlag(CAN1, (CAN_IR_RF1N_MASK));                             // >> CAN_IE_RF1NE_SHIFT));
    MCAN_ReadRxFifo(CAN1, 1, &rxFrame);
    rxComplete = true;
    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
      exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
    __DSB();
#endif
}
I don't want to use below function since it is not working properly for me even though everything looks perfect:
MCAN_TransferSendNonBlocking()
0 Kudos
Reply

1,406 Views
gmk1
Contributor III

Hi nxf46116‌, any progress on Case:00201633?

0 Kudos
Reply

1,406 Views
gmk1
Contributor III

Hi Alexis...

Can you provide transmission irq handler just like receive handler below?

void CAN1_IRQ1_IRQHandler(void)
{
    MCAN_ClearStatusFlag(CAN1, (CAN_IR_RF1N_MASK));                             // >> CAN_IE_RF1NE_SHIFT));
    MCAN_ReadRxFifo(CAN1, 1, &rxFrame);
    rxComplete = true;
    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
      exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
    __DSB();
#endif
}
I don't want to use below function since it is not working properly for me even though everything looks perfect:
MCAN_TransferSendNonBlocking()
0 Kudos
Reply

1,406 Views
gmk1
Contributor III
  1. It's a custom board
  2. I'm using USB to CAN analyzer tool called CANMate, so I can monitor packets on PC
  3. Baud is correct. Device ID doesn't matter as I have not set any filters on PC. I was supposed to receive every packet with valid ID 
  4. Again this does not matter

Additional info:

  1. I'm able to receive data correctly on PC using MCAN_TransferSendBlocking(...), using polling method
  2. I'm also receiving data correctly for the first time using MCAN_TransferSendNonBlocking(...). And in next iteration I get nothing
  3. I set breakpoint at Callback function but program never goes there
  4. As in the code above 'txComplete' flag should be set true by callback function but txComplete is always false

If you want any other information please let me know...

0 Kudos
Reply