MPC5606S FlexCan sample code

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

MPC5606S FlexCan sample code

Jump to solution
1,665 Views
eddiewu
Contributor I

Hi all,

I'm searching MPC5606S FlexCan sample code for reference. Can you help to supply one?

Following are my code that can not work:

void flexcan0_init(void)
{
    /* Enable the FlexCAN module */
    CAN_0.MCR.B.MDIS = 0b0;                 /* 0 Enable the FlexCAN module */
   
    /* Enabled to enter Freeze mode */
    CAN_0.MCR.B.FRZ = 0b1;                  /* 1 Enabled to enter Freeze mode */
    /* Enters Freeze mode */
    CAN_0.MCR.B.HALT = 0b1;                 /* 1 Enters Freeze mode if the FRZ bit is asserted. */
   
    /* Wait till Freeze mode is reached */
    while(CAN_0.MCR.B.FRZACK != 1) {;}      /* 1 FlexCAN in Freeze mode, prescaler stopped */
   
    /* Set Maximum Number of Message Buffers
     * MAXMB field, which should only be changed while the module is in Freeze mode
     */
    CAN_0.MCR.B.MAXMB = 63;                 /* 64 buffer */
   
    /* Init Message Buffers */
    {
        uint8_t i = 0;
        for (i=0; i<64; i++)
        {
            CAN_0.BUF[i].CS.B.CODE = MBCRX_INACTIVE;    /* MB does not participate in the matching process. */
        }
    }
   
    CAN_0.RXGMASK.R = 0x1FFFFFFF;
   
    /* Set Control Register
     * Baudrate = CLK/(PRESDIV+1)/(SYNC_SEG(1)+(PROPSEG+PSEG1+2)+(PSEG2+1))
     * 8000000/5/(1+6+3+2+3+1)=100000 = 100 K
     */
    CAN_0.CR.B.CLKSRC = 0b0;                /* 0 The CAN engine clock source is the oscillator clock */
    CAN_0.CR.B.PRESDIV = 0x4;
    CAN_0.CR.B.PSEG1 = 0x3;
    CAN_0.CR.B.PSEG2 = 0x3;
    CAN_0.CR.B.PROPSEG = 0x6;
   
    // Set RX Pin
    SIU.PCR[IO_CANRX_0].B.PA = 0x1;         /* CANRX_0 */
    SIU.PCR[IO_CANRX_0].B.IBE = 0x1;        /* 1 Input Buffer of the pad is enabled. */
    SIU.PSMI[0].B.PADSEL = 0x0;             /* PCR[19] */
   
    // Set Tx Pin
    SIU.PCR[IO_CANTX_0].B.PA = 0x1;         /* CANTX_0 */
    SIU.PCR[IO_CANTX_0].B.OBE = 0x1;        /* Output Buffer Enable */
    SIU.PCR[IO_CANTX_0].B.ODE = 0x1;
    SIU.PCR[IO_CANTX_0].B.SRC = 0x1;
   
    /* Set STB HIGH */
    SIU.PCR[IO_STB0].B.PA = 0x0;
    SIU.PCR[IO_STB0].B.OBE = 0x1;
    SIU.GPDO[IO_STB0].B.PDO = 0;
   
    /* Exit Freeze mode */
    CAN_0.MCR.B.HALT = 0b0;             /* 0 No Freeze mode request. */
   
    CAN_0.MCR.B.FRZ = 0b0;
}

0 Kudos
Reply
1 Solution
1,350 Views
martin_kovar
NXP Employee
NXP Employee

Hello,

please look at the AN2865, there is FlexCAN example you can use.

http://cache.nxp.com/assets/documents/data/en/application-notes/AN2865.pdf?fsrch=1&sr=1&pageNum=1 

Here is link for application note software.

MPC5500 and MPC5600 Simple Cookbook Code 

Regards,

Martin

View solution in original post

0 Kudos
Reply
2 Replies
1,351 Views
martin_kovar
NXP Employee
NXP Employee

Hello,

please look at the AN2865, there is FlexCAN example you can use.

http://cache.nxp.com/assets/documents/data/en/application-notes/AN2865.pdf?fsrch=1&sr=1&pageNum=1 

Here is link for application note software.

MPC5500 and MPC5600 Simple Cookbook Code 

Regards,

Martin

0 Kudos
Reply
1,350 Views
eddiewu
Contributor I

Hi Martin,

Thanks for you great help. I use this example to debug the hardware, found that FlexCAN module can not receive or send data.

I use the Oscilloscope to detect RX pin on the MCU, The data from PC already reached to the RX pin, but FlexCAN module can not receive. So I suspect some of the registers are not set properly.

Do you have another example code for reference ?

0 Kudos
Reply