About receiving MPC5748g lin messages

cancel
Showing results for 
Search instead for 
Did you mean: 

About receiving MPC5748g lin messages

Jump to solution
356 Views
ZD-Zhengkun
Contributor II

Hi,

I have a question about receiving the LIN msg on the MPC5748g. The example given in the S32DS is operating in the master mode. The other example I found was implemented in UART MODE(MPC5748G-LINFlex-LIN-Master-Slave-test-GHS614).

When I want to receive LIN frame in slave mode, I encountered some problems.

ZD-Zhengkun_0-1622029809963.png

According to the reference manual, I set the mpc5748 as slave node, init the pin, baud rate, direction, CCS, etc, and then wait for the message from the master node. After I send the message from PLIN(as a master node) to MPC5748G, I can clearly see the waveform from the oscilloscope, but the HRF doesn't change a bit, and RMB doesn't change either. Did I miss anything?

Really needs your help! Thanks 

Here is my code:

void receiveLIN1frame (void) { /* Request data from ID 0x15 */

uint8_t __attribute__ ((unused)) RxBuffer[8] = {0};
uint8_t i;


MPC_LINFlexD_3.LINCR1.B.SLEEP = 0; /* Put LINFlex hardware in init mode */
MPC_LINFlexD_3.LINCR1.B.INIT = 1; /* Put LINFlex hardware in init mode */
MPC_LINFlexD_3.LINCR1.B.MME = 0; /* LIN master */
MPC_LINFlexD_3.LINCR1.B.MBL = 0b0001; /* master break length */
MPC_LINFlexD_3.LINIBRR.B.IBR= 260; /* Mantissa baud rate divider component */

MPC_LINFlexD_3.LINFBRR.B.FBR = 0; /* Fraction baud rate divider component */
MPC_LINFlexD_3.LINCR1.B.INIT = 0; /* Put LINFlex hardware in init mode */MPC_LINFlexD_3.BIDR.B.DIR = 0; /*REIEVES DATA*/
MPC_LINFlexD_3.BIDR.B.CCS = 0;/*ENHANCED CCS*/
MPC_LINFlexD_3.BIDR.B.DFL = 0b111; /*length = 8 */

while(!MPC_LINFlexD_3.LINSR.B.HRF); /* Wait 4 header recieve flag*/

while(!MPC_LINFlexD_3.LINSR.B.RMB); /* Wait 4 realse mem buf*/

/* Code waits here if no slave response */
for (i=0; i<4;i++){ /* If received less than or equal 4 data bytes */
RxBuffer[i]= (MPC_LINFlexD_3.BDRL.R>>(i*8)); /* Fill buffer in reverse order */
}
for (i=4; i<8;i++){ /* If received more than 4 data bytes: */
RxBuffer[i]= (MPC_LINFlexD_3.BDRM.R>>((i-4)*8)); /* Fill rest in reverse order */
}
MPC_LINFlexD_3.LINSR.R = 0x00000004; /* Clear DRF flag */
MPC_LINFlexD_3.LINSR.B.RMB = 0; /**/
printf("reset of rmb bit\r\n");

}

 

Tags (3)
0 Kudos
1 Solution
347 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

only LINFlexD_0 supports Slave mode

PetrS_0-1622057517697.png

BR, Petr

View solution in original post

0 Kudos
2 Replies
348 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

only LINFlexD_0 supports Slave mode

PetrS_0-1622057517697.png

BR, Petr

0 Kudos
341 Views
ZD-Zhengkun
Contributor II

Thanks for your reply!

But I still have a question, is it possible to use LINFlexD2~17 as the master node and receive the lin frames from the other master nodes? Since they can receive the frames from slave nodes that contain only data without a header, is there a solution to extract the data from frames(wither header) from other master nodes?

besides, I changed my codes above and it can work on LINFlexD1:

MPC_LINFlexD_0.LINCR1.B.SLEEP = 0; /* Put LINFlex hardware in init mode */
MPC_LINFlexD_0.LINCR1.B.INIT = 1; /* Put LINFlex hardware in init mode */
MPC_LINFlexD_0.LINCR1.B.MME = 0; /* LIN master */
MPC_LINFlexD_0.LINCR1.B.MBL = 0b1110; /* master break length */
MPC_LINFlexD_0.LINIBRR.B.IBR= 130; /* Mantissa baud rate divider component */
/* Baud rate divider = 80 MHz LIN_CLK input / (16*19200 bps) ~=130 */
MPC_LINFlexD_0.LINFBRR.B.FBR = 0; /* Fraction baud rate divider component */
MPC_LINFlexD_0.LINCR1.B.INIT = 0; /* Put LINFlex hardware in init mode */
MPC_LINFlexD_0.BIDR.B.DIR = 0; /*REIEVES DATA*/
MPC_LINFlexD_0.BIDR.B.CCS = 0;/*ENHANCED CCS*/
MPC_LINFlexD_0.BIDR.B.DFL = 0b111; /*length = 8 */
MPC_LINFlexD_0.LINSR.B.HRF = 0;
MPC_LINFlexD_0.LINSR.B.RMB = 0;

while(!time_out){
k = 5000;
while(k){
if(!MPC_LINFlexD_0.LINSR.B.HRF){/* Wait 4 header recieve flag*/
k--;
mpc_delay(1);
}
else
break;
}
if (k == 0){
printf("time out.\r\n");
time_out = 1;
continue;
}
MPC_LINFlexD_0.BIDR.B.DFL = 0b111; /*specify the data field length = 8 */
uint8_t identifier_lin = MPC_LINFlexD_0.BIDR.B.ID; /*read identifier*/
printf("The id of the target is %d. \r\n",identifier_lin);
while(!MPC_LINFlexD_0.LINSR.B.RMB); /* Wait 4 realse mem buf*/
for (i=0; i<4;i++){ /* If received less than or equal 4 data bytes */
RxBuffer[i]= (MPC_LINFlexD_0.BDRL.R>>(i*8)); /* Fill buffer in reverse order */
}
for (i=4; i<8;i++){ /* If received more than 4 data bytes: */
RxBuffer[i]= (MPC_LINFlexD_0.BDRM.R>>((i-4)*8)); /* Fill rest in reverse order */
}
printf("Recieved data: %x %x %x %x %x %x %x %x \r\n",RxBuffer[0],RxBuffer[1],RxBuffer[2],RxBuffer[3],RxBuffer[4],RxBuffer[5],RxBuffer[6],RxBuffer[7]);

MPC_LINFlexD_0.LINSR.R = 0x00000004; /* Clear DRF flag */
MPC_LINFlexD_0.LINSR.B.HRF = 0; /*SW reset of two HRF AND RMB*/
MPC_LINFlexD_0.LINSR.B.RMB = 0;
}

Thx again

0 Kudos