AnsweredAssumed Answered

MPC574xP EVB(MPC5744P-144DS ) LIN mode can't receive any data by SW pooling or interrupt

Question asked by 大伟 庞 on Sep 24, 2017
Latest reply on Sep 25, 2017 by Petr Stancik

I  use two  MPC574xP EVB   ,one of MPC574xP EVB's LIN1 as  slave  mode  another as  master mode 。The  configeration is shown below:

 slave mode config:

    LINFLEX_InitLIN(1, 200000000/2, 19200, 0);

    LINFLEX_InitRxBuffer(1,4);

master mode config:

    uint8_t lin_str[8]={0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0};

    LINFLEX_InitLIN(1, 200000000/2, 19200, 1);

    LINFLEX_InitRxBuffer(1,4);

     LINFLEX_SendFrameLIN (1, (uint8_t*)&lin_str, 0x08, 0x02);

 

void LINFLEX_InitLIN(vuint8_t nbLINFlex, double sysClk, uint32_t baudRate, uint8_t mode)
{

LINFLEX_ConfigurePads(nbLINFlex);

LINFLEX_WakeUp(nbLINFlex);

LINFLEX[nbLINFlex]->LINCR1.B.INIT = 1; // enter initialization mode
LINFLEX[nbLINFlex]->LINCR1.B.MBL = 3; //Master break length set to 13-bit
LINFLEX[nbLINFlex]->LINCR1.B.BF = 0; //Bypass filter -> no interrupt if ID does not match any filter
LINFLEX[nbLINFlex]->LINCR1.B.MME = mode; //1 -> Master, 0 -> Slave
LINFLEX[nbLINFlex]->LINTCSR.B.IOT = 0; //LIN state machine does not reset to Idle on timeout event
//LINFLEX[nbLINFlex]->LINCR1.B.LBKM = 1;

LINFLEX[nbLINFlex]->LINCR1.B.BF = 1;
LINFLEX[nbLINFlex]->LINCR1.B.CCD = 0;
LINFLEX[nbLINFlex]->LINCR1.B.CFD = 0;
LINFLEX[nbLINFlex]->LINCR2.B.IOBE = 0;
LINFLEX[nbLINFlex]->LINCR2.B.IOPE = 0;

LINFLEX[nbLINFlex]->UARTCR.B.UART = 0; //0=Lin

LINFLEX_ChangeBaudRate(nbLINFlex, sysClk, baudRate);

LINFLEX[nbLINFlex]->LINCR1.B.INIT = 0; // enter normal mode

}

 

void LINFLEX_SendFrameLIN (vuint8_t nbLINFlex, uint8_t* p_tx, uint8_t nbBytes, uint8_t ID)
{
//sends complete LIN frame on Master => header + data
uint32_t responseL=0;
uint32_t responseH=0;

if (nbBytes == 1)
{
responseL = p_tx[0];
}
else if (nbBytes == 2)
{
responseL = p_tx[0] | (p_tx[1] << 8);
}
else if (nbBytes == 3)
{
responseL = p_tx[0] | (p_tx[1] << 8) | (p_tx[2] << 16);//(uint32_t) p_tx[0] + ( ((uint32_t)p_tx[1]) * 256) + ( ((uint32_t)p_tx[2]) * 65536);
}
else if (nbBytes >= 4)
{
responseL = p_tx[0] | (p_tx[1] << 8) | (p_tx[2] << 16) | (p_tx[3] << 24);
}
if (nbBytes == 5)
{
responseH = p_tx[4];
}
else if (nbBytes == 6)
{
responseH = p_tx[4] | (p_tx[5] << 8);
}
else if (nbBytes == 7)
{
responseH = p_tx[4] | (p_tx[5] << 8) | (p_tx[6] << 16);//(uint32_t) p_tx[0] + ( ((uint32_t)p_tx[1]) * 256) + ( ((uint32_t)p_tx[2]) * 65536);
}
else if (nbBytes == 8)
{
responseH = p_tx[4] | (p_tx[5] << 8) | (p_tx[6] << 16) | (p_tx[7] << 24);
}

LINFLEX[nbLINFlex]->BDRL.R = responseL;
LINFLEX[nbLINFlex]->BDRM.R = responseH;

switch(nbBytes){ //number of data Bytes will be included into the IDentifier
case 2 : ID = 0x20 | ID; break; //0b10_0000 | ID; break;
case 4 : ID = 0x10 | ID; break; //0b01_0000 | ID; break;
case 8 : ID = 0x30 | ID; break; //0b11_0000 | ID; break;
}

LINFLEX[nbLINFlex]->BIDR.R = ((nbBytes - 1) << 10) | (1 << 9) | (0 << 8) | ID; //DIR - transmit, CCS - enhanced checksum

LINFLEX[nbLINFlex]->LINCR2.B.HTRQ = 1; 

while(LINFLEX[nbLINFlex]->LINSR.B.DTF!=1){}
LINFLEX[nbLINFlex]->LINSR.B.DTF=1;
}

 

 

 

interrupt  app:

void ISR380_LINFlEX1_Rx(void)
{
/* wait for RMB */
while (1 != LINFlexD_1.LINSR.B.RMB) {} /* Wait for Release Message Buffer */

LINFLEX_ReadLIN(1,0x8,lin1_Message);
LINFLEX_SendWordUART (0, (uint8_t*)&lin1_Message, sizeof(lin1_Message));
/* clear the HRF,DRF and RMB flags by writing 1 to them */
LINFlexD_1.LINSR.R = 0x0205;

}

Outcomes