AnsweredAssumed Answered

Using lin_lld_uart_tx_response(); function for transmitting LIN response data

Question asked by jananisubraveti on Jan 8, 2018
Latest reply on Jan 23, 2018 by Hui_Ma

I am using FSL_LIN_2x_STACK_PACKAGE_4.5.9 and running an example design for LIN slave on kinetis KEA64.

I want to use the function to transmit a response using the following function but I couldnot see any response from the slave to the master.

 

Here is my main.c file and the lin_lld_uart.c files.

 

/*
* main implementation: use this 'C' sample to create your own application
*/

#define MOTOR_SELECTION_INCREASE 1
#define MOTOR_SELECTION_DECREASE 2
#define MOTOR_SELECTION_STOP 3
/**********************************************************************************************
* Global variables
**********************************************************************************************/
l_u8 LIN_counter =0, LED_counter = 0;
l_u8 Motor1_temp = 30;
l_u8 Motor1_Selection;
/***********************************************************************************************
*
* @brief CLK_Init - Initialize the clocks to run at 20 MHz from the 10Mhz external XTAL
* @param none
* @return none
*
************************************************************************************************/
void Clk_Init()
{
ICS_C1|=ICS_C1_IRCLKEN_MASK; /* Enable the internal reference clock*/
ICS_C3= 0x50; /* Reference clock frequency = 39.0625 KHz*/
while(!(ICS_S & ICS_S_LOCK_MASK)); /* Wait for PLL lock, now running at 40 MHz (1024 * 39.0625Khz) */
ICS_C2|=ICS_C2_BDIV(1) ; /*BDIV=2, Bus clock = 20 MHz*/
ICS_S |= ICS_S_LOCK_MASK ; /* Clear Loss of lock sticky bit */
}

 

/***********************************************************************************************
*
* @brief lin_application_timer_FTM0 - Initialize the timer for LIN application
* @param none
* @return none
*
************************************************************************************************/
void lin_application_timer_FTM0()
{
SIM_SCGC |= SIM_SCGC_FTM0_MASK; /* Enable Clock for FTM0 */
FTM0_SC |= FTM_SC_PS(7); /* Select Preescaler in this case 128. 20 Mhz /128 =156.25 Khz. */
/* Counter increase by one every 6.4 us */
/* Enable Channle 0*/
FTM0_C0SC |= FTM_CnSC_CHIE_MASK; /* Enable channel 0 interrupt */
FTM0_C0SC |= FTM_CnSC_MSA_MASK; /* Channel as Output compare mode */
/*Select interrupt frequency*/
FTM0_C0V = FTM_CnV_VAL(391) ; /* Interrupt every 2.5ms */

FTM0_SC |= FTM_SC_CLKS(1); /*FTM0 use system clock*/

/* Set the ICPR and ISER registers accordingly */
NVIC_ICPR |= 1 << ((INT_FTM0-16)%32);
NVIC_ISER |= 1 << ((INT_FTM0-16)%32);
}
void main()
{
l_u8 ret;
l_u8 vector_number;
//l_u16 i;
Clk_Init();
GPIO_Init();
ret = l_sys_init();
ret = l_ifc_init(LI0);

vector_number = INT_UART0 -16;

NVIC_ICPR |= 1 << (vector_number%32);
NVIC_ISER |= 1 << (vector_number%32);
lin_application_timer_FTM0();
for (;;){
/* Check if temp signal is updated */
if (l_flg_tst_LI0_Motor1Selection_flag()){
/* Clear this flag... */
l_flg_clr_LI0_Motor1Selection_flag();
/* Store selection data */
Motor1_Selection = l_u8_rd_LI0_Motor1Selection();
/* The application will change Motor selection in case
the temperature is greater than maximum value to release motor power
This will be transfered by sporadic frame type in LIN bus */
l_u8_wr_LI0_Motor1Temp(Motor1_temp);
/* Check if power off motor due to high temperature */
if (Motor1_Selection == MOTOR_SELECTION_STOP) {
/*---------- add code here to stop motor ------------*/
}
if (Motor1_Selection == MOTOR_SELECTION_INCREASE){
LED2_ON;
}
if (Motor1_Selection == MOTOR_SELECTION_DECREASE){
LED2_OFF;
}
}

}
}

void FTM0_IRQHandler()
{
if (1==((FTM0_C0SC & FTM_CnSC_CHF_MASK)>>FTM_CnSC_CHF_SHIFT) ) /* If the CHF of the channel is equal to 0 */
{
(void)FTM0_C0SC; /* Read to clear flag */
FTM0_C0SC ^= FTM_CnSC_CHF_MASK; /* Clear flag */
FTM0_C0V = FTM0_C0V + 391 ; /* Refresh interrupt period */

if (LED_counter>=50){
/* Toggle LED for LIN transmission */
/* Reset counter */
LED0_TOGGLE;
lin_lld_uart_tx_response();  //here my slave should transmit a response for the LIN transmission 
LED_counter = 0;
if (Motor1_Selection == MOTOR_SELECTION_INCREASE){
Motor1_temp++;
LED2_ON;
LED3_OFF;
}
else if (Motor1_Selection == MOTOR_SELECTION_DECREASE){
Motor1_temp--;
LED2_OFF;
LED3_ON;
}
}
LED_counter++;
}
}

 

This part of the code or function definition is from lin_lld_uart.c file and this function is declared in lin_lld_uart.h file.

void lin_lld_uart_tx_response
(
)
{
/* calculate checksum */
response_buffer[*(response_buffer)+1] = lin_checksum(response_buffer, pid);
cnt_byte = 1;
/* Send First byte */
pUART->uartd.byte = response_buffer[1];
/* Set LIN Status */
state = SEND_DATA;
} /* End function lin_lld_UART_tx_response() */

 

How can i transmit a response from slave?

Outcomes