MPC5604B How to implement the LIN bus communication function???

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

MPC5604B How to implement the LIN bus communication function???

1,946 Views
鑫洋金
Contributor II

/********************************************************
【平 台】龙丘MPC多功能开发板
【编 写】龙丘
【Designed】by Chiu Sir
【E-mail 】chiusir@yahoo.cn
【软件版本】V1.0
【最后更新】2011年11月08日
【相关信息参考下列地址】
【网 站】http://www.lqist.cn
【淘宝店铺】http://shop36265907.taobao.com
------------------------------------------------
【dev.env.】Code Warrior 2.9
【Target 】MPC5604B/P
【内部晶振】 khz
【外部晶振】8MHz
【总线频率】64MHz
*/
/* main.c: LINFlex program for MPC56xxB */
/* Description: Transmit one message from FlexCAN 0 buf. 0 to FlexCAN C buf. 1 */
/* Oct 30 2009 S Mihalik - initial version */
/* Mar 14 2010 SM - modified initModesAndClock, updated header file */

#include "MPC5604B_0M27V_0102.h" /* Use proper header file */

void initModesAndClks(void) {
ME.MER.R = 0x0000001D; /* Enable DRUN, RUN0, SAFE, RESET modes */
/* Initialize PLL before turning it on: */
/* Use 1 of the next 2 lines depending on crystal frequency: */
CGM.FMPLL_CR.R = 0x02400100; /* 8 MHz xtal: Set PLL0 to 64 MHz */
/*CGM.FMPLL_CR.R = 0x12400100;*/ /* 40 MHz xtal: Set PLL0 to 64 MHz */
ME.RUN[0].R = 0x001F0074; /* RUN0 cfg: 16MHzIRCON,OSC0ON,PLL0ON,syclk=PLL */
ME.RUNPC[1].R = 0x00000010; /* Peri. Cfg. 1 settings: only run in RUN0 mode */
ME.PCTL[48].R = 0x01; /* MPC56xxB/P/S LINFlex 0: select ME.RUNPC[1] */
ME.PCTL[68].R = 0x01; /* MPC56xxB/S SIUL: select ME.RUNPC[0] */
/* Mode Transition to enter RUN0 mode: */
ME.MCTL.R = 0x40005AF0; /* Enter RUN0 Mode & Key */
ME.MCTL.R = 0x4000A50F; /* Enter RUN0 Mode & Inverted Key */
while (ME.GS.B.S_MTRANS) {} /* Wait for mode transition to complete */
/* Note: could wait here using timer and/or I_TC IRQ */
while(ME.GS.B.S_CURRENTMODE != 4) {} /* Verify RUN0 is the current mode */
}

void initPeriClkGen(void) {
CGM.SC_DC[0].R = 0x80; /* MPC56xxB/S: Enable peri set 1 sysclk divided by 1 */
}

void disableWatchdog(void) {
SWT.SR.R = 0x0000c520; /* Write keys to clear soft lock bit */
SWT.SR.R = 0x0000d928;
SWT.CR.R = 0x8000010A; /* Clear watchdog enable (WEN) */
}

void initLINFLEX_1 (void) {

LINFLEX_1.LINIBRR.B.DIV_M= 416; /* Mantissa baud rate divider component */
LINFLEX_1.LINFBRR.B.DIV_F = 16; /* Fraction baud rate divider comonent */
LINFLEX_1.LINCR1.R= 0x00000310; /* Configure module as LIN master & header */
SIU.PCR[38].R = 0x0400; /* MPC56xxB: Configure port c6 as LIN1TX */
SIU.PCR[39].R = 0x0103; /* MPC56xxB: Configure port c7 as LIN1RX */
}

void transmitLINframe (void) {

LINFLEX_1.BIDR.R = 'a'; /* Init header: ID=0x35, 8 B, Tx, enh. cksum*/

}
void delayms(int ms)
{
int ii,jj;
if (ms<1) ms=1;
for(ii=0;ii<ms;ii++)
for(jj=0;jj<3338;jj++); //
}
void main(void) {
volatile uint32_t IdleCtr = 0;

initModesAndClks(); /* Initialize mode entries */
initPeriClkGen(); /* Initialize peripheral clock generation for LINFlex */
disableWatchdog(); /* Disable watchdog */
initLINFLEX_1(); /* Initialize FLEXCAN 0 as master */
transmitLINframe(); /* Transmit one frame from master */
while (1)
{
IdleCtr++;
transmitLINframe();
delayms(500);
} /* Idle loop: increment counter */
}      

0 Kudos
Reply
4 Replies

1,420 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

you can refer to this example https://community.nxp.com/docs/DOC-102526 

BR, Petr

1,420 Views
鑫洋金
Contributor II

Do you have  MPC5604B Flex CAN  communication demo 

0 Kudos
Reply

1,420 Views
鑫洋金
Contributor II

Can I add your Whatsapp account ? 

0 Kudos
Reply

1,420 Views
鑫洋金
Contributor II

My email address is      918793695@qq.com

0 Kudos
Reply