Hi, I studying LIN communication for mpc 5777c. I'm looking for LIN example code for mpc 5777c but I can't found it. Can I get some help for this code? I want to transmit and recieve multiple data but it doesn't work. Here's the code.
#define esci_c
#include "..\typedefs_mpc.h"
#include "..\proto_mpc.h"
void esci_init(void)
{
LIN_EN = 1;
SIU.PCR[LIN_TXD_pin].R = 0x400; // Configure pad for primary func: LIN_TXD
SIU.PCR[LIN_RXD_pin].R = 0x400; // Configure pad for primary func: LIN_RXD
eSCI_B.CR2.R = 0x2000; // module is enabled (default setting)
eSCI_B.LCR1.R = 0x0000; // LIN module deactivation
eSCI_B.BRR.B.SBR = 625;
eSCI_B.LCR1.B.LIN = 1; // LIN module activation
eSCI_B.CR2.B.BRCL = 1;
eSCI_B.CR2.B.BESTP = 1;
eSCI_B.CR2.B.BSTP = 1;
eSCI_B.CR1.B.TE = 1; // Tx enabled
eSCI_B.CR1.B.RE = 1; // Rx enabled
// transmit interrupt activation
eSCI_B.CR1.B.RIE = 1;
}
uint8_t lin_data = 0x2;
uint8_t receivedID;
// frame transmit
void LIN_SendFrame(uint8_t header, uint8_t* data, uint8_t length)
{
//eSCI_B.LRR.R = header;
uint8_t j = 0; /* Dummy variable */
for (j=0; j<length; j++)
{
if(eSCI_B.IFSR2.B.TXRDY == 1)
{
eSCI_B.IFSR2.R = 0x4000; /* Clear TXRDY flag */
eSCI_B.LTR.R = *(data+j); /* Transmit 8 bits Data */
}
}
}
#define MY_ID 0x15
uint8_t test_lin = 0;
// frame receive
void LIN_ReceiveFrame(uint8_t* header, uint8_t* data, uint8_t length)
{
uint8_t j = 0; /* Dummy variable */
if (eSCI_B.IFSR2.B.RXRDY == 1)
{
eSCI_B.IFSR2.B.RXRDY = 0x8000; /* Clear RXRDY flag */
*header = eSCI_B.LRR.R;
if (*header == MY_ID)
{
test_lin = 1;
for (j=0; j<length; j++)
{
eSCI_B.IFSR2.B.RXRDY = 0x8000; /* Clear RXRDY flag */
*(data + j) = eSCI_B.LRR.R; /* Read byte of Data*/
}
}
}
}
void LIN_IRQHandler(void) {
if (eSCI_B.IFSR2.B.OVFL)
{
eSCI_B.IFSR2.B.OVFL = 0;
}
if (eSCI_B.IFSR2.B.RXRDY)
{
uint8_t receivedID = eSCI_B.LRR.R;
if (receivedID == MY_ID)
{
uint8_t receivedData = eSCI_B.LRR.R;
}
eSCI_B.IFSR2.B.RXRDY = 0;
}
if (eSCI_B.IFSR2.B.TXRDY)
{
eSCI_B.IFSR2.B.TXRDY = 0;
}
}
uint8_t txHeader = 0x01;
uint8_t txData[] = {0x15, 0x22, 0x33,0x44};
LIN_SendFrame(txHeader, txData, 4);
LIN_ReceiveFrame(&rxHeader, rxData, 4);