AnsweredAssumed Answered

Can't get working FlexCAN

Question asked by Mikhail Burakov on Nov 15, 2013
Latest reply on Oct 31, 2014 by Anders Hørtvedt

Hello everyone!

 

For the few last days I tried to get working FlexCAN via MQX IO api. Now it looks like i am totally failed. I use custom board with MK20DX256VLK7 CPU and MQX 4.0.1. The problem is, that no data ever leaves mailboxes, it spams errors infinitely instead: CAN0_ECR is changing, code in CAN0_CS0 is stuck on 0xc, no timestamp in CAN0_CS0. The code is simple:

 

#define CAN_DEVICE   ( 0 )
#define FREQUENCY    ( 1000 )
#define MAILBOX_TX ( 0 )

 

void canbus_task(uint_32 initial_data)
{
    _bsp_flexcan_io_init(CAN_DEVICE);
    FLEXCAN_Initialize(CAN_DEVICE, 0, 0, FREQUENCY, FLEXCAN_IPBUS_CLK);
    FLEXCAN_Initialize_mailbox(CAN_DEVICE, MAILBOX_TX, 0x111, 8, FLEXCAN_TX, FLEXCAN_STANDARD, FLEXCAN_DISABLE);
    FLEXCAN_Activate_mailbox(CAN_DEVICE, MAILBOX_TX, FLEXCAN_TX_MSG_BUFFER_NOT_ACTIVE);

    FLEXCAN_Select_mode(CAN_DEVICE, FLEXCAN_NORMAL_MODE);

  
    unsigned char data[] = { 0x23, 0x10, 0x19, 0x67, 0x11, 0x22, 0x33, 0x44 };
    FLEXCAN_Tx_mailbox(CAN_DEVICE, MAILBOX_TX, data);

 

    _task_block();
}

 

Can some one verify that this is the correct code? The hardware is functional, on the other end i have PCAN-USB. It works for sure, because i was able to receive messages from this board without the use of MQX (another project). The situation is really weird because i even tried to manually configure CAN0 module in exact the same way as in barebone project. I verified that all the registers are totally equal (except CAN0_TIMER of course). But sending data fails anyway. I feel that i miss some obvious tiny detail, but this is my first experience with canbus, and i am out of ideas.

 

Please help me, dear community :)

Outcomes