用2块同样的 demo board(型号是9s08dz60) 分别作master,slave,用LIN2.0,使用freescale提供的LINKit作通信。做的事最简单的功能。master 发送 Msg_17给slave。 但是 发送/接受都不成功。请各位LIn的大虾帮着看下阿,最简单的Lin的通信了。这是master的程序: void main( void ) { int n,m; int i,nodeId; unsigned char statusDisplay; LINStatusType ret; unsigned char idList[16] = {0x10, 0x11, 0x12, 0x13, 0x18, 0x19, 0x1A, 0x1B, 0x20, 0x21, 0x22, 0x23, 0x28, 0x29, 0x2A, 0x2B}; char activeList[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char messageList = 16;
Time = 0; /* disable COP */ SOPT1 = 0x20; /* disable COP, enable stop mode */ /* Configure MCG to produce a 16MHz bus clock from a 8MHz external crystal via PLL */ /* Select High Range, High Gain, Bus divided by 1, Oscillator, ERCLK enabled */ MCGC2 = 0x36; while (!MCGSC_OSCINIT);
/* Select External Clock as bus clock source, Reference divided by 128, Reference = external */ MCGC1 = 0xB8;
/* wait for Reference Status bit to update */ while (!MCGSC_IREFST); /* Wait for clock status bits to update */ while (MCGSC_CLKST != 0b10);
/* NOW IN FBE MODE */ MCGC2 = 0x3E;
/* NOW IN BLPE MODE */ /* Change RDIV for PLL reference */ MCGC1 = 0x98;
/* Select the VCO divider and PLL */ MCGC3 = 0x48; /* Wait for PLL status to update */ while (!MCGSC_PLLST);
/* Clear LP bit */ MCGC2 = 0x36;
/* NOW IN PBE MODE */
/* Wait for LOCK bit to set */ while (!MCGSC_LOCK);
/* Enter PEE mode */ MCGC1 = 0x18;
/* Wait for Clock status to indicate PLL output */ while (MCGSC_CLKST != 0b11);
/* Initialize driver */ LIN_Init();
PTADD_PTADD7 = 1; //enable LIN transceiver TJA1020 PTAD_PTAD7 = 1;
PTCDD_PTCDD5 = 1; PTBDD_PTBDD3 = 1;
/* Initialise RTC */ InitDelay(); /* Enable interrupt */ asm cli; /* Check/Enable LIN interface */ LINActive(); // disable LINActive()
PeriphInit(); //initial led1,led2,sw1,sw2
while(1) {
/* Update message */
ret = LIN_PutMsg( 0x17,MsgSent) ;
ret = LIN_RequestMsg(0x17) ;
LED1=~LED1;
do {
ret = LIN_DriverStatus();
} while(ret!=LIN_STATUS_RUN);
ret = LIN_MsgStatus(0x17); if(ret==LIN_OK) {
for(n=0;n<5;n++) {
LED2=~LED2; Delay(500); } }
} }
|