FlexCAN Bus off when trying to send a message          M5282 CW7.1.1

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

FlexCAN Bus off when trying to send a message          M5282 CW7.1.1

1,803 Views
francois_boucha
Contributor III

Hi all,

 

I got a simple setup of 2 M5282 eval board connected together with a CAN bus.  The passive side is waiting for an incomming CAN message.  The other side is supposed to send 5 CAN messages but when attempting to send a message the bus becomes off. 

 

Just after the initialization sequence the registers have these value:

MCF_FlexCAN_CANMCR==0
MCF_FlexCAN_ESTAT==80    // bus is idle
MCF_FlexCAN_IFLAG==0

 

 

 //  Init sequence
        // F sys = 64 MHz
        // CAN baud rate = 1 Mbps /* Set PASPA2,3 bits to one to assign port to CAN bus function */ MCF_PAD_PASPAR |= (MCF_PAD_PASPAR_PASPA2_CANTX |        MCF_PAD_PASPAR_PASPA3_CANRX); MCF_FlexCAN_CANCTRL2 = 0; MCF_FlexCAN_PRESDIV = (uint8) MCF_FlexCAN_PRESDIV_PRES_DIV(
                                ((SYSTEM_CLOCK_MHZ / 8) - 1) );  // Init message buffers //------------------------------------------------ /* Initialize 16 Message Buffers */ /* Descr.  used for     ID    Mask*/ //------------------------------------------------ // BUF0  Rx      slot_id   111111xxxxx     // BUF1   Rx      slot_id   111111xxxxx     // BUF2  Rx      slot_id   111111xxxxx     // BUF3   Rx      slot_id   111111xxxxx   // BUF4  Rx      slot_id   111111xxxxx    // BUF5   Rx      slot_id   111111xxxxx  // BUF6  Rx      slot_id   111111xxxxx    // BUF7   Rx      slot_id   111111xxxxx  // BUF8  Rx      slot_id   111111xxxxx  // BUF9  Rx      slot_id   111111xxxxx   // BUF10 Rx      slot_id   111111xxxxx   //------------------------------------------------ // BUF11  Rx      0    111111xxxxx   // BUF12  Rx      0    111111xxxxx   //------------------------------------------------ // BUF13 Tx    xxxxxxx     - // BUF14 Tx       xxxxxxx     - //------------------------------------------------ // BUF15  not used     -      - //------------------------------------------------   // check ID: 6 bits if(CAN_ID > 63) {  return FALSE;  }  // Rx mailboxes    for(i = 0;  BSP_RX_mailbox[i] != -1; ++i)    {     // Make buffer inactive      MCF_FlexCAN_MBUF_CTRL( BSP_RX_mailbox[i]) = MB_NOT_ACTIVE;           // for RX_BROADCAST_MAILBOX1 AND RX_BROADCAST_MAILBOX2, CAN_ID == 0     MCF_FlexCAN_MBUF_IDH( BSP_RX_mailbox[i])  = 0; // default          // All Rx mailboxes except RX_BROADCAST_MAILBOX1 AND RX_BROADCAST_MAILBOX2     if(BSP_RX_mailbox[i] != RX_BROADCAST_MAILBOX1 && BSP_RX_mailbox[i]!= RX_BROADCAST_MAILBOX2)      MCF_FlexCAN_MBUF_IDH( BSP_RX_mailbox[i])  = (uint16)(CAN_ID << 10);   // Initialise control/status word     MCF_FlexCAN_MBUF_CTRL( BSP_RX_mailbox[i]) = MB_RX_EMPTY;     }    // Tx mailboxes    for(i = 0;  BSP_TX_mailbox[i] != -1; ++i)    {     MCF_FlexCAN_MBUF_CTRL( BSP_TX_mailbox[i]) = MB_TX_NOT_READY; /* Initialise control/status word */         }       /* Message buffer(s) 15 not in use */    MCF_FlexCAN_MBUF_CTRL(15) = MB_NOT_ACTIVE; /* Make buffer inactive */            MCF_FlexCAN_RXGMASK = (uint32)(0x7e0 << 21) | (0x3ffff << 1); // Init Interrupts init_CAN_interrupts(); MCF_FlexCAN_CANMCR = 0;

 Init sequence

 

 

 

 

but when attempting to transmit, the IFLAG is never set, and no message is transmitted.

       /* Hold Message Buffer ie. not ready for transmit */
    MCF_FlexCAN_MBUF_CTRL(mailbox) = MB_TX_NOT_READY;

    // Fill mailbox
    MCF_FlexCAN_MBUF_WORD(mailbox, 0) = (uint32)(word0 | (word1 << 16));
    MCF_FlexCAN_MBUF_WORD(mailbox, 1) = (uint32)(word2 | (word3 << 16));
   
           
    /* Activate transmission of Message Buffer */
    MCF_FlexCAN_MBUF_CTRL(mailbox) = MB_TX_ONCE;

    // wait
    count=0;
    while(!(MCF_FlexCAN_IFLAG & MCF_FlexCAN_IFLAG_BUF(mailbox)))
    {
        count++;
       
       
        //if(count > MAXcount)    MAXcount=count;
        // stop if too long
        if(count >= 32000)
            break;
       
    }

 

Any hints?  Bus is terminated on both sides.

FB

Labels (1)
0 Kudos
3 Replies

791 Views
JulienP
Contributor II

Hello sir,

 

Have you fixed your problem? Because I got something similar, but in my case data are transmitted continuously, instead of one time. So BUS OFF is set. Do you have any idea?  (Loopback mode is working great).

0 Kudos

791 Views
dragi_pandeliev
Contributor I

Have you configured correctly your bit timings? Tseg1 and Tseg2? 

I had the same problem and I needed to reconfigure everything with the correct settings and then it worked.

0 Kudos

791 Views
David_UCT
Contributor III

if your bit timing is wrong the nodes will continuously transmit until they go Bus_OFF.  In that case I would recommend you have a look at freescales application note for Bit timing, AN1798 I think just keyword search for it.

 

If you disconnect the nodes from each other and transmit messages you should be able to see a continuous repeat of messages on a scope to verify that the individual nodes are working.

 

0 Kudos