LPC54608 LIN slave basic usage sharing

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

LPC54608 LIN slave basic usage sharing

LPC54608 LIN slave basic usage sharing

1 Abstract

      This post is mainly about the LPC54608 LIN slave basic usage, it is similar to the post about the LPC54608 LIN master basic usage.     

      NXP LPC54608 UART module already have the LIN master and slave function, so this post will give a simple slave code and test result which is associated with the LIN analyzer. Use the LIN analyzer as the LIN master, LPC54608 as the LIN slave, master will send the specific ID frame (publish frame and the subscribe frame) to LIN slave, and wait the feedback from LIN slave side.

2 LPC54608 LIN slave example

     Now use the LPCXpresso54608 board as the LIN slave, the PCAN-USB Pro FD LIN analyzer as the LIN master, give the hardware connection and the simple software code about the LIN slave.

2.1 Hardware requirement

       HardwareLPCXpresso54608TRK-KEA8PCAN-USB Pro FD(LIN analyzer), 12V DC power supply

       LIN bus voltage is 12V, but the LPCXpresso54608 board don’t have the on-board LIN transceiver chip, so we need to find the external board which contains LIN transceiver chip, here we will use the TRK-KEA8, this board already have the MC33662LEF LIN transceiver, or the board KIT33662LEFEVB which is mentioned in the LPC54608 LIN master post.  The MC33662LEF LIN transceiver circuit from TRK-KEA8 just as follows:

pastedImage_2.png

Fig 2-1. LIN transceiver schematic

2.1.1 LPCXpresso54608 and TRK-KEA8 connections

     LPCXpresso54608 UART port need to connect to the LIN transceiver:

No.

LPCXpresso54608

TRK-KEA8

note

1

P4_RX

J10-5

UART0_RX

2

P4_TX

J10-6

UART0_TX

3

P4_GND

J14-1

GND

2.1.2 TRK-KEA8 and LIN master analyzer tool connections

       LIN analyzer LIN bus is connected to the TRK-KEA8 LIN bus.

       LIN analyzer GND is connected to the TRK-KEA8 GND.     

       TRK-KEA8 P1 port powered with 12V, LIN master analyzer Vbat pin also need to be connected to 12V.

       TRK-KEA8 J13_2 need to connect to 3.3V DC power, but because TRK-KEA8 is the 5V and 12V, so need to find another 3.3V supply to connect J13_2, here use the FRDM-KL43 as the 3.3V supply. Just make sure the LIN transceiver can input 3.3V and output the 3.3V signal to the UART port.   

2.1.3 Physical connections

pastedImage_3.png

2.2 Software flow and code

       This part is about the LIN publisher data and the subscriber ID data between the LIN master and slave. The code is modified based on the SDK  LPCXpresso54608 usart interrupt project.

 2.2.1 software flow chart

pastedImage_4.png

2.2.2 software code

   Code is modified based on SDK_2.3.0_LPCXpresso54608 usart interrupt, the modified code is as follows:

void DEMO_USART_IRQHandler(void)
{
   
  if(DEMO_USART->STAT & USART_INTENSET_DELTARXBRKEN_MASK) // detect LIN break
     {
       DEMO_USART->STAT |= USART_INTENSET_DELTARXBRKEN_MASK;// clear the bit
       Lin_BKflag = 1;
       cnt = 0;
       state = RECV_SYN;
       DisableLinBreak;
      
     }
    if((kUSART_RxFifoNotEmptyFlag | kUSART_RxError) & USART_GetStatusFlags(DEMO_USART))
     {
       USART_ClearStatusFlags(DEMO_USART,kUSART_TxError | kUSART_RxError);
          rxbuff[cnt] = USART_ReadByte(DEMO_USART);;
         
         switch(state)
         {
            case RECV_SYN:
                          if(0x55 == rxbuff[cnt])
                          {
                              state = RECV_PID;
                          }
                          else
                          {
                              state = IDLE;
                              DisableLinBreak;
                          }
                          break;
            case RECV_PID:
                          if(0xAD == rxbuff[cnt])
                          {
                              state = RECV_DATA;
                          }
                          else if(0XEC == rxbuff[cnt])
                          {
                              state = SEND_DATA;
                          }
                          else
                          {
                              state = IDLE;
                              DisableLinBreak;
                          }
                          break;
            case RECV_DATA:
                          recdatacnt++;
                          if(recdatacnt >= 4) // 3 Bytes data + 1 Bytes checksum
                          {
                              recdatacnt=0;
                              state = RECV_SYN;
                              EnableLinBreak;
                          }
                          break;
         default:break;
                          
         }
         
         cnt++;
     }
  
 
    /* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
      exception return operation might vector to incorrect interrupt */
#if defined __CORTEX_M && (__CORTEX_M == 4U)
    __DSB();
#endif
}

/*!
 * @brief Main function
 */
int main(void)
{
    usart_config_t config;

    /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
    CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

    BOARD_InitPins();
    BOARD_BootClockFROHF48M();
    BOARD_InitDebugConsole();

    /*
     * config.baudRate_Bps = 19200U;
     * config.parityMode = kUSART_ParityDisabled;
     * config.stopBitCount = kUSART_OneStopBit;
     * config.loopback = false;
     * config.enableTxFifo = false;
     * config.enableRxFifo = false;
     */
    USART_GetDefaultConfig(&config);
    config.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE;
    config.enableTx = true;
    config.enableRx = true;

    USART_Init(DEMO_USART, &config, DEMO_USART_CLK_FREQ);

    /* Enable RX interrupt. */
    DEMO_USART->INTENSET |= USART_INTENSET_DELTARXBRKEN_MASK; //USART_INTENSET_STARTEN_MASK | 
    USART_EnableInterrupts(DEMO_USART, kUSART_RxLevelInterruptEnable | kUSART_RxErrorInterruptEnable);
    EnableIRQ(DEMO_USART_IRQn);


    while (1)
    {
  
       if(state == SEND_DATA)
       {

        while (kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(DEMO_USART))
        {
            USART_WriteByte(DEMO_USART, 0X01);
            break;  //just send one byte, otherwise, will send 16 bytes
        }
        while (kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(DEMO_USART))
        {
            USART_WriteByte(DEMO_USART, 0X02);
            break;  //just send one byte, otherwise, will send 16 bytes
        }
        while (kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(DEMO_USART))
        {
            USART_WriteByte(DEMO_USART, 0X10);// 0X10 correct 0Xaa wrong
            break;  //just send one byte, otherwise, will send 16 bytes            
        }
    
          recdatacnt=0;
          state = RECV_SYN;
          EnableLinBreak;
       }     
    }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

3 LPC54608 LIN slave test result

  Master define two frames

Unconditional ID

Protected ID

Direction

Data

checksum

0X2C

0XEC

subscriber

0x01,0x02

0x10

0X2D

0XAD

Publisher

0x01,0x02,0x03

0x4c

  Now, LIN master send the above two frame to the slave LIN, give the test result and the wave from the LIN bus.

3.1 LIN master configuration

Uart baud rate is: 19200bps

pastedImage_5.png

3.2 send 0X2C,0X2D frames

pastedImage_7.png

From the above test result, we can find 0X2D send successfully, 0X2C can receive the data from the LIN save side, the received data is 0X01,0X02 and the checksum 0x10.

3.2.1 0X2D frame LIN bus wave and debug result

 

pastedImage_1.png

pastedImage_9.jpg

From the LIN slave debug result, we can find LIN slave can receive the correct data from the LIN master, and after check, the checksum also correct.

3.2.2 0X2C frame LIN bus wave

pastedImage_2.png

pastedImage_12.jpg

From the LIN Master tool interface, we can find if the slave give the wrong checksum 0XAA, the master will also can find the checksum is wrong.

This is the according LIN bus wave with wrong checksum.

pastedImage_3.png

From the above test result, we can find LPC54608 LIN slave, can receive the correct LIN bus data, and send back the correct LIN data to the master.

Labels (1)
Attachments
No ratings
Version history
Last update:
‎09-10-2020 03:05 AM
Updated by: