Fredrik Liljenvall

MCF 52259 FlexCAN problem, source code supplied

Discussion created by Fredrik Liljenvall on Feb 12, 2009
Latest reply on Dec 18, 2010 by TomE

Hello !

I have some trouble with the FlexCAN on ColdFire, hope someone can help me out

Sometimes the FlexCAN sends multiple frames on to the network even though we only send one frame by the CAN driver (we are using the drivers supplied with CodeWarrior). This seems to happened randomly it could work fine a long time then suddenly all frames sent are duplicated.


We have also seen bursts of messages (with the same message) causing 100% busload.


Have done a lot of debugging, for example a breakpoint at the start of the send service in the CAN driver and a breakpoint at the end i can see that 2 frames are sent at each call to the send routine.

However if i set another breakpoint just after writing 0xC to the CODE field then only one frame is sent.

Anyone have an idea of what could be wrong? I have not found any errata on this problem.

I supply the send service in the driver, we are only using one mailbox for TX.

int8 FlexCANSendDataPoll(uint8 *pData, uint8 u8Size, uint32 u32ID, uint8 u8MB)
    uint8 u8Counter;
    uint8 *pDataPointer;
    uint32 u32Rescue = 0;
    tFlexCANMB *BuffPtr;
    uint16 temp = 0;

    /*Set the buffer pointer*/
    BuffPtr = &MCF_FLEXCAN_BUFFERS.MB0 + u8MB;

    (*BuffPtr).u16CtrlStat = MB_CTRLSTAT_CODE(0x8);
    if (!(u32ID & FLEXCAN_EXTENDEDID(0)))
        /* Standard ID */
        (*BuffPtr).u32ID.u32ExtID = MB_STANDARD_ID(u32ID);
        (*BuffPtr).u32ID.u32ExtID = MB_EXTENDED_ID(u32ID - FLEXCAN_EXTENDEDID(0));
        temp |= (MB_CTRLSTAT_SRR | MB_CTRLSTAT_IDE);
    pDataPointer = &((*BuffPtr).u8Data0);
    for (u8Counter = 0; u8Counter < u8Size; u8Counter++)
        *(pDataPointer++) = *(pData++);

    temp |= MB_CTRLSTAT_LENGTH(u8Size);

    (*BuffPtr).u16CtrlStat = MB_CTRLSTAT_CODE(0xC) | temp;

    while(!(MCF_FlexCAN_IFLAG & (1<<u8MB)))
        if (u32Rescue++ == RESCUE_VALUE)
            return 0;

    /* Clear interrupt flag */
    MCF_FlexCAN_IFLAG = (1<<u8MB);

    return 1;