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;
}
Solved! Go to Solution.
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
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
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 ?