status is set to kStatus_FLEXCAN_UnHandled in flexcan_callback

cancel
Showing results for 
Search instead for 
Did you mean: 

status is set to kStatus_FLEXCAN_UnHandled in flexcan_callback

744 Views
stdcerr
Contributor IV

Hi,

I'm working on a receive only CAN application that reads data from a sensor but am not able to receive anything so far.

The setup

I have a tilt sensor attached to my uC CAN module (PTB18 & PTB19) that continuously sends out frames at 250kbit/s. I have a CAN analyzer connected with which I can see the frames on the bus.

The plan is to use Kinetis to read these frames for further processing.

I planned to retrieve data with FLEXCAN_TransferReceiveNonBlocking but realized that statusis constantly set to kStatus_FLEXCAN_RxBusy even with the sensor disconnected.
A call to FLEXCAN_TransferHandleIRQ(EXAMPLE_CAN, &flexcanHandle); will invoke the callback with status set to kStatus_FLEXCAN_UnHandled.
mbState of the mailbox is set to 1 (kFLEXCAN_StateRxData).
The callback never is invoked with status = kStatus_FLEXCAN_RxIdle

Code:

globals:

#define EXAMPLE_CAN                CAN0
#define EXAMPLE_CAN_CLK_SOURCE     (kFLEXCAN_ClkSrc1)
#define EXAMPLE_CAN_CLK_FREQ       CLOCK_GetFreq(kCLOCK_BusClk)
#define RX_MESSAGE_BUFFER_NUM      (9)
#define DLC                        (8)
#define SET_CAN_QUANTUM            (0)
#define PSEG1                      (3)
#define PSEG2                      (2)
#define PROPSEG                    (1)
#define LOG_INFO                   (void)PRINTF

volatile bool rxComplete = false;
flexcan_frame_t rxFrame;
flexcan_mb_transfer_t rxXfer;
flexcan_handle_t flexcanHandle;

CAN setup:

    FLEXCAN_GetDefaultConfig(&flexcanConfig);

#if defined(EXAMPLE_CAN_CLK_SOURCE)
    flexcanConfig.clksrc=EXAMPLE_CAN_CLK_SOURCE;
#endif

    flexcanConfig.enableListenOnlyMode = true;
    flexcanConfig.baudRate = 250000U;
    //flexcanConfig.enableLoopBack = true;

    FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig, EXAMPLE_CAN_CLK_FREQ);
    /* Create FlexCAN handle structure and set call back function. */
    FLEXCAN_TransferCreateHandle(EXAMPLE_CAN, &flexcanHandle, flexcan_callback, NULL);

    /* Setup Rx Message Buffer. */
    mbConfig.format = kFLEXCAN_FrameFormatStandard;
    mbConfig.type   = kFLEXCAN_FrameTypeData;
    mbConfig.id     = FLEXCAN_ID_STD(0x10FF53C2);
    FLEXCAN_SetRxMbConfig(EXAMPLE_CAN, RX_MESSAGE_BUFFER_NUM, &mbConfig, true);

    /* Start receive data through Rx Message Buffer. */
    rxXfer.mbIdx = (uint8_t)RX_MESSAGE_BUFFER_NUM;
    rxXfer.frame = &rxFrame;

the callback:

static void flexcan_callback(CAN_Type *base, flexcan_handle_t *handle, status_t status, uint32_t result, void *userData)
{
    switch (status)
    {
        /* Process FlexCAN Rx event. */
        case kStatus_FLEXCAN_RxIdle:
            if (RX_MESSAGE_BUFFER_NUM == result) {
                rxComplete = true;
            }
            LOG_INFO("kStatus_FLEXCAN_RxIdle\r\n");
            break;
        case kStatus_FLEXCAN_UnHandled:
        	LOG_INFO("kStatus_FLEXCAN_UnHandled\r\n");
        	break;
        default:
        	LOG_INFO("in flexcan_cb, status 0x%x(%d)\r\n",status,status);
    }

}

receiving loop:

    while (!rxComplete) {
    	(void)FLEXCAN_TransferReceiveNonBlocking(EXAMPLE_CAN, &flexcanHandle, &rxXfer);
    	FLEXCAN_TransferHandleIRQ(EXAMPLE_CAN, &flexcanHandle);
    }

 

I also did attach flexcan_test.c that contains the above code.

Labels (1)
Tags (1)
0 Kudos
5 Replies

718 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

 

Thank you for provide me the part number.

I suggest you to refer to the example flexcan_loopback_transfer disabling the loopback. In the callback for the RX please disable the interruption flag. Also you can do test with a lower baudrate, 125000 was helpful.

 

Let me know if this is helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar

0 Kudos

702 Views
stdcerr
Contributor IV

Hi,

 

Thank you for the reply.

The flexcan loopback example is where I started from, I experimented with multiple baudrates and all seemed fine until I initialized my pins, removed the loopback and set the baudrate to match the sensor's 250000U. I would be notified through the callback, but status would never be set to kStatus_FLEXCAN_RxIdle but instead status is set to 0x14be and I could not figure out what this is telling me.

0 Kudos

701 Views
stdcerr
Contributor IV

Okay, I figured out, that 0x14BE stands for "kStatus_FLEXCAN_ErrorStatus" which gets set due to the value Err Status value that comes from FLEXCAN_GetStatusFlags() has the kFLEXCAN_ErrorIntFlag bit set. In the comment it just reads "Error Interrupt Flag" - I need to get this fixed.

0 Kudos

728 Views
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

 

Can you provide the part number you are working with?

I'm awaiting for your reply.

725 Views
stdcerr
Contributor IV

Definitely can, I'm working with a MK64FN1M0VLL12

0 Kudos