AnsweredAssumed Answered

s12p64 number of data received by LIN

Question asked by SHIREN SUN on Jun 6, 2017
Latest reply on Jun 20, 2017 by Radek Sestak

Hi,

 

I'm now working on the LIN communication with MC9S12P64 and my module can receive and send LIN message perfectly. But the only problem is that in the receiving part, I want to get exactly the number of data that I receive by LIN.

 

I'm new to NXP microcontroller and also to LIN communication. I didn't know by which function I can find the DLC number. So can anyone tell me which function or register I can get the number of data received?

 

Here is a part of my code of LIN recerving:

 

/////////////////////////////////////////////////////////////////////////////////////////
// LINGetChar
// --------------------------------------------------------------------------------------
// SCI data receive routine
/////////////////////////////////////////////////////////////////////////////////////////
Bool LINGetChar(unsigned char lin_num)
{
unsigned int somme=0;
unsigned char y;
unsigned volatile char *lin_pt, ch;
lin_pt = lin_periph[lin_num];

// State of the LIN receive channel
switch(rx[lin_num].state++)
{
case IDLE:
//Clear RDRF or OR SCI Flag
if(!(lin_pt[SCI0SR1]&(SCISR1_RDRF_MASK|SCISR1_FE_MASK)))
return(FALSE);
if(lin_pt[SCI0DRL] != 0x00)
return(FALSE);
break;
case _BREAK:
//Clear RDRF Flag
if(!(lin_pt[SCI0SR1]&SCISR1_RDRF_MASK))
return(FALSE);
if(lin_pt[SCI0DRL] != 0x55)
return(FALSE);
break;
case SYNCH:
//Clear RDRF Flag
if(!(lin_pt[SCI0SR1]&SCISR1_RDRF_MASK))
return(FALSE);
ch = lin_pt[SCI0DRL];
rx[lin_num].protected_id = ch;
break;

case PROTECTED_IDENTIFIER:
case DATA_0:
case DATA_1:
case DATA_2:
case DATA_3:
case DATA_4:
case DATA_5:
case DATA_6:
case DATA_7:
//Clear RDRF Flag
if(!(lin_pt[SCI0SR1]&SCISR1_RDRF_MASK))
return(FALSE);
ch = lin_pt[SCI0DRL];
if (ch==0){


if((rx[lin_num].data[0]== 0) && (rx[lin_num].data[1]== 0) && (rx[lin_num].data[2]== 0) && (rx[lin_num].data[3]== 0) && (rx[lin_num].data[4]== 0) && (rx[lin_num].data[5]== 0) && (rx[lin_num].data[6]== 0) && (rx[lin_num].data[7]== 0)){

testid2=7;

}

}

for(y = 0; y <(rx[lin_num].state-DATA_0); y++)
{
somme += rx[lin_num].data[y];
if(somme&0xFF00)
{
somme = (somme&0x00FF) + 1;
}
}
somme += rx[lin_num].protected_id;
if(somme&0xFF00)
{
somme = (somme&0x00FF) + 1;
}
somme ^= 0x00FF;

if (ch == somme)
{
nombre_octets_recuperes = (rx[lin_num].state-DATA_0);
rx[lin_num].check = ch;
rx[lin_num].state = CHECKSUM;
}

else
{
rx[lin_num].data[rx[lin_num].state-DATA_0] = ch;
}
break;

case CHECKSUM:

return(FALSE);
}
return(TRUE);

}

/////////////////////////////////////////////////////////////////////////////////////////
// LINGetMsg
// --------------------------------------------------------------------------------------
// LIN Message Receive Routine
/////////////////////////////////////////////////////////////////////////////////////////
Bool LINGetMsg(unsigned char nombre_octets_recu, unsigned char lin_num, Bool get_data, struct message *msg,unsigned char version_lin)
{

unsigned char i;

if(rx[lin_num].state < PROTECTED_IDENTIFIER)
return(FALSE);
msg->identifier = (rx[lin_num].protected_id&0x3f);
if(get_data)
{
if(rx[lin_num].state == CHECKSUM)
{
nombre_octets_recuperes = (rx[lin_num].state-DATA_0);

for(i = 0; i < sizeof(rx[lin_num].data); i++)
msg->data_field[i] = rx[lin_num].data[i];
for(i = sizeof(rx[lin_num].data); i < 8; i++)
msg->data_field[i] = 0;
rx[lin_num].state = IDLE;

}
} else{

for(i = 0; i < 8; i++)
msg->data_field[i] = 0;

}

return TRUE;
}

Outcomes