Hi,
I'm using LPC55S06 board. I'm working with CAN. Before I was using interrupt based CAN, now I'm trying to use callback function. When I try to run the code I'm getting assert error.
Can you give some solution to this problem.
Hi,
I suppose that the SDK package includes the CAN example, the callback code is the example code without any modification, pls test the example.
Regarding the callback function, you have to install the callback function with the line in main() function.
MCAN_Init(EXAMPLE_MCAN, &mcanConfig, MCAN_CLK_FREQ);
/* Create MCAN handle structure and set call back function. */
MCAN_TransferCreateHandle(EXAMPLE_MCAN, &mcanHandle, mcan_callback, NULL);
Pls check if you have called the above two lines, they are required.
The callback function is only called in ISR:
void MCAN_TransferHandleIRQ(CAN_Type *base, mcan_handle_t *handle)
{
/* Assertion. */
assert(NULL != handle);
status_t status = kStatus_MCAN_UnHandled;
uint32_t valueIR;
uint32_t result;
/* Store Current MCAN Module Error and Status. */
valueIR = base->IR;
do
{
if (0U != (valueIR & ((uint32_t)kMCAN_ErrorWarningIntFlag | (uint32_t)kMCAN_ErrorPassiveIntFlag |
(uint32_t)kMCAN_BusOffIntFlag)))
{
/* Solve error. */
result = (uint32_t)kMCAN_ErrorWarningIntFlag | (uint32_t)kMCAN_ErrorPassiveIntFlag |
(uint32_t)kMCAN_BusOffIntFlag;
status = kStatus_MCAN_ErrorStatus;
}
else if (0U != (valueIR & (uint32_t)kMCAN_TxTransmitCompleteFlag))
{
/* Solve Tx interrupt. */
result = (uint32_t)kMCAN_TxTransmitCompleteFlag;
status = kStatus_MCAN_TxIdle;
MCAN_TransferAbortSend(base, handle, handle->txbufferIdx);
}
else if (0U != (valueIR & (uint32_t)kMCAN_RxFifo0NewFlag))
{
(void)MCAN_ReadRxFifo(base, 0U, handle->rxFifoFrameBuf);
result = (uint32_t)kMCAN_RxFifo0NewFlag;
status = kStatus_MCAN_RxFifo0Idle;
MCAN_TransferAbortReceiveFifo(base, 0U, handle);
}
else if (0U != (valueIR & (uint32_t)kMCAN_RxFifo0LostFlag))
{
result = (uint32_t)kMCAN_RxFifo0LostFlag;
status = kStatus_MCAN_RxFifo0Lost;
}
else if (0U != (valueIR & (uint32_t)kMCAN_RxFifo1NewFlag))
{
(void)MCAN_ReadRxFifo(base, 1U, handle->rxFifoFrameBuf);
result = (uint32_t)kMCAN_RxFifo1NewFlag;
status = kStatus_MCAN_RxFifo1Idle;
MCAN_TransferAbortReceiveFifo(base, 1U, handle);
}
else if (0U != (valueIR & (uint32_t)kMCAN_RxFifo1LostFlag))
{
result = (uint32_t)kMCAN_RxFifo1LostFlag;
status = kStatus_MCAN_RxFifo0Lost;
}
else
{
/* Handle the interrupt flag unsupported in current version of MCAN driver.
* User can get these unsupported interrupt flags by callback function,
* we can clear directly in the handler to prevent endless loop.
*/
result = valueIR;
result &= ~((uint32_t)kMCAN_ErrorWarningIntFlag | (uint32_t)kMCAN_ErrorPassiveIntFlag |
(uint32_t)kMCAN_BusOffIntFlag | (uint32_t)kMCAN_TxTransmitCompleteFlag |
(uint32_t)kMCAN_RxFifo0NewFlag | (uint32_t)kMCAN_RxFifo0LostFlag |
(uint32_t)kMCAN_RxFifo1NewFlag | (uint32_t)kMCAN_RxFifo1LostFlag);
}
/* Clear Error interrupt, resolved Rx FIFO, Tx Buffer IRQ and other unsupported interrupt flags. */
MCAN_ClearStatusFlag(base, result);
/* Calling Callback Function if has one. */
if (handle->callback != NULL)
{
handle->callback(base, handle, status, result, handle->userData);
}
/* Reset return status */
status = kStatus_MCAN_UnHandled;
/* Store Current MCAN Module Error and Status. */
valueIR = base->IR;
} while (0U != valueIR);
}
Hope it is helpful
BR
XiangJun Rong
../fatfs/drivers/fsl_mcan.c:1735:47: error: 'mcan_handle_t' {aka 'struct _mcan_handle'} has no member named 'txbufferIdx'
1735 | MCAN_TransferAbortSend(base, handle, handle->txbufferIdx);
When we use the code you've given us we're getting the above error
Hi,
i suppose that this is an issue for different SDK package version. On my SDK ver2.8.2, the
_mcan_handle has the txbufferIdx member.
But my SDK version is a bit old.
BR
XiangJun Rong