LIN

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LIN

1,709 Views
monicabagade
Contributor II

Hello,

I am trying to learn LIN functionality on MPC5634m. In this I have tried basic transfer of single message using following code.


#include "mpc563m.h" /* Use proper include file such as mpc5510.h or mpc5554.h */

const uint8_t FrameSpecAndData[] = {0x35,0x08,0xD0,'H','e','l','l','o',' ',' ',' '}; 
uint8_t  RecData; 

void initSysclk (void) {
    FMPLL.ESYNCR1.B.CLKCFG = 0X7;       /* Change clk to PLL normal mode from crystal */ 
    FMPLL.SYNCR.R = 0x16080000;         /* 8 MHz xtal: 0x16080000; 40MHz: 0x46100000 */
    while (FMPLL.SYNSR.B.LOCK != 1) {}; /* Wait for FMPLL to LOCK  */
    FMPLL.SYNCR.R = 0x16000000;         /* 8 MHz xtal: 0x16000000; 40MHz: 0x46080000 */
}

void initESCI_B (void) {
     ESCI_B.CR2.R = 0x6240;      /* Module is enabled, 13 bit break, stop on errors */
     ESCI_B.CR1.R = 0x0180000C;  /* 10417 baud, 8 bits, no parity, Tx & Rx enabled */
     ESCI_B.LCR.R = 0x01000000;  /* eSCI put in LIN mode */
     SIU.PCR[91].R = 0x400;      /* Configure pad for primary func: TxDB */
    SIU.PCR[92].R = 0x400;      /* Configure pad for primary func: RxDB */
}

void TransmitData (void) {
  uint8_t j;                                      /* Dummy variable */
 
  for (j=0; j< sizeof (FrameSpecAndData); j++) {    /* Loop for character string */
        while (ESCI_B.SR.B.TXRDY == 0) {}               /* Wait for LIN transmit ready = 1 */
        ESCI_B.SR.R = 0x00004000;                       /* Clear TXRDY flag */
        ESCI_B.LTR.R = FrameSpecAndData[j];      /* Write byte to LIN Trans Reg. */
  }
}

void ReceiveData (void) {
    while (ESCI_B.SR.B.RXRDY == 0) {}   /* Wait for LIN transmit ready = 1 */
    ESCI_B.SR.R = 0x00008000; 
    RecData = ESCI_B.LRR.R;             /* Read byte of Data*/
    ESCI_B.LRR.R = RecData;            /* Echo back byte of Data read */
}


void main(void) {
    initSysclk();       /* Set sysclk = 64MHz running from PLL */
    initESCI_B();       /* Enable Tx for 10417 baud, 8 bits, no parity */
    TransmitData();     /* Transmit string of characters on eSCI B */
    ReceiveData();
    while (1) {}        /* Wait forever */
}

If I want to transmit multiple messages. How to do that?

Can i transfer multiple messages with same ID?

Is there any demo code with the help of DMA transfer?

Please help me out?

Thanks in advance.

Tags (4)
5 Replies

1,219 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi Monica,

What do you mean by multiple messages? The communication is based on single-master/multiple-slave concept. So the only Master initiates a communication by sending a header, then either transmit a data to slave or receive data from slave nodes.

Once the LIN Master transmit/receive full frame it can start another. Similarly as you did it in TransmitData function. The same ID can be used. Your ReceiveData function cannot work.

Unfortunately we do not have example which uses DMA for LIN TX/RX operation.  

BR, Petr

0 Kudos

1,219 Views
monicabagade
Contributor II

And how to make receive function active then?

0 Kudos

1,219 Views
15870467687
Contributor I

Hi Monica,

I used the demo same method on MPC5634M, but could not receive data normally. Could you share the code that you successfully tested?

Looking forward to your help.

Thanks in advance.

0 Kudos

1,219 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi Monica,

At the same time just single message can be sent. After message is fully transmited or received another message can be sent again. If you need to send another ID and/or data you need to modify the code as you need.

 

Attached is simple example for CPU controlled LIN TX/RX frame generation tested on MPC5668G eSCI module.

It should be similar on MPC5634M.

BR, Petr

1,219 Views
monicabagade
Contributor II

Dear Petr,

Multiple messgaes means,

At the same time if i want to send the more than 1 message with different Id or same Id.

Like in above example HELLO (8 byte) message is passed with Id 0x3.

like that if another message i want to send like HOW ARE YOU or whatever. How can I send? Can I send with same ID or different ID.

0 Kudos