在线时间0 小时
UID2079485
注册时间2014-3-16
NXP金币0
该用户从未签到
新手上路

- 积分
- 4
- 最后登录
- 1970-1-1
|
关于CAN,官方例程如下:
/* main.c: FlexCAN program */
/* Description: Transmit one message from FlexCAN 0 buf. 0 to FlexCAN C buf. 1 */
/* Rev 0.1 Jan 16, 2006 S.Mihalik, Copyright Freescale, 2006. All Rights Reserved */
/* Rev 0.2 Jun 6 2006 SM - changed Flexcan A to C & enabled 64 msg buffers */
/* Rev 0.3 Jun 15 2006 SM - 1. Made globals uninitialized */
/* 2. RecieveMsg function: read CANx_TIMER, removed setting buffer's CODE*/
/* 3. added idle loop code for smoother Nexus trace */
/* 4. modified for newer Freescale header files (r 16) */
/* Rev 0.4 Aug 11 2006 SM - Removed redundant CAN_A.MCR init */
/* Rev 0.5 Jan 31 2007 SM - Removed other redundant CAN_C.MCR init */
/* Rev 0.6 Mar 08 2007 SM - Corrected init of MBs- cleared 64 MBs, instead of 63 */
/* Rev 0.7 Jul 20 2007 SM - Changes for MPC5510 */
/* Rev 0.8 May 15 2008 SM - Changes for new header file symbols */
/* Rev 0.9 May 22 2009 SM - Changes for MPC56xxB/P/S */
/* Rev 1.0 Jul 10 2009 SM - Simplified, cleared CAN Msg Buf flag by writing to reg */
/* not bit, increased Tx pads slew rate, changed RxCODE, RxLENGTH, dummy data types*/
/* & init receiving CAN first to allow CAN bus sync time before receiving 1st msg*/
/* Rev 1.1 Mar 14 2010 SM - modified initModesAndClock, updated header file */
/* NOTE!! structure canbuf_t in header file modified to allow byte addressing*/
#include "MPC5604B_0M27V_0102.h" /* Use proper include file */
uint32_t RxCODE; /* Received message buffer code */
uint32_t RxID; /* Received message ID */
uint32_t RxLENGTH; /* Recieved message number of data bytes */
uint8_t RxDATA[8]; /* Received message data string*/
uint32_t RxTIMESTAMP; /* Received message time */
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[16].R = 0x01; /* MPC56xxB/P/S FlexCAN0: select ME.RUNPC[1] */
ME.PCTL[17].R = 0x01; /* MPC56xxB/S FlexCAN1: select ME.RUNPC[1] */
ME.PCTL[68].R = 0x01; /* MPC56xxB/S SIUL: select ME.RUNPC[1] */
/* 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[1].R = 0x80; /* MPC56xxB/S: Enable peri set 2 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 initCAN_1 (void) {
uint8_t i;
CAN_1.MCR.R = 0x5000003F; /* Put in Freeze Mode & enable all 64 msg bufs */
CAN_1.CR.R = 0x04DB0006; /* Configure for 8MHz OSC, 100KHz bit time */
for (i=0; i
|
|