S32k uart RX interrupt handler problem

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

S32k uart RX interrupt handler problem

3,340 Views
hjinha
Contributor II

I am configuring UART communication over S32K144 EVB.

I use LPUART1 (Rx : PTD13 , Tx : PTC7) that is inerrupt type.

But My  LPUART1_RxTx_IRQHandler only works once at first.

I don't know solution to this problem.

 this is my init function about LPUART1

void LPUART1_init(void) /* Init. summary: 9600 baud, 1 stop bit, 8 bit format, no parity */
{
PCC->PCCn[PCC_LPUART1_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Ensure clk disabled for config */
PCC->PCCn[PCC_LPUART1_INDEX] |= PCC_PCCn_PCS(1) /* Clock Src= 1 (SOSCDIV2_CLK) */
| PCC_PCCn_CGC_MASK; /* Enable clock for LPUART1 regs */

LPUART1->BAUD = ((DEBUG_OSR << 24) | (SBR(DEBUG_BAUDRATE, DEBUG_OSR))); /* Initialize for 115200baud, 1 stop: */ 
/* SBR=52 (0x34): baud divisor = 8M/9600/16 = ~52 */
/* OSR=15: Over sampling ratio = 15+1=16 */
/* SBNS=0: One stop bit */
/* BOTHEDGE=0: receiver samples only on rising edge */
/* M10=0: Rx and Tx use 7 to 9 bit data characters */
/* RESYNCDIS=0: Resync during rec'd data word supported */
/* LBKDIE, RXEDGIE=0: interrupts disable */
/* TDMAE, RDMAE, TDMAE=0: DMA requests disabled */
/* MAEN1, MAEN2, MATCFG=0: Match disabled */

LPUART1->CTRL=0x000C0000; /* Enable transmitter & receiver, no parity, 8 bit char: */
/* RE=1: Receiver enabled */
/* TE=1: Transmitter enabled */
/* PE,PT=0: No hw parity generation or checking */
/* M7,M,R8T9,R9T8=0: 8-bit data characters*/
/* DOZEEN=0: LPUART enabled in Doze mode */
/* ORIE,NEIE,FEIE,PEIE,TIE,TCIE,RIE,ILIE,MA1IE,MA2IE=0: no IRQ*/
/* TxDIR=0: TxD pin is input if in single-wire mode */
/* TXINV=0: TRansmit data not inverted */
/* RWU,WAKE=0: normal operation; rcvr not in statndby */
/* IDLCFG=0: one idle character */
/* ILT=0: Idle char bit count starts after start bit */
/* SBK=0: Normal transmitter operation - no break char */
/* LOOPS,RSRC=0: no loop back */
/* Enable transmitter & receiver, no parity, 8 bit char: */

// Enable Interrupt ---------------------------------------------------------------
S32_NVIC->ICPR[ 33 / 32 ] = 1 << (33 % 32);
/* Interrupt Enable */
S32_NVIC->ISER[ 33 / 32 ] = 1 << (33 % 32);

S32_NVIC->IP[33] = 0x10;

LPUART1->CTRL |= LPUART_CTRL_RIE_MASK; // Rx Interrupt Enable

}

this is my LPUART1_RxTx_IRQHandler

void LPUART1_RxTx_IRQHandler( void )
{

static uint8_t indx = 0;

// Tx completed
if( (LPUART1->STAT & LPUART_STAT_TDRE_MASK) )
{

}


// RX completed
if( LPUART1->STAT & LPUART_STAT_RDRF_MASK )
{

nRxData = LPUART1->DATA; // DUMMY

indx ++;

if(indx % 2 ==0)
PINS_DRV_WritePin(LED_GPIO_PORT, PORT_LED1_INDEX, 1U);
else
PINS_DRV_WritePin(LED_GPIO_PORT, PORT_LED1_INDEX, 0U);

if(indx > 100)
   indx = 0;


}

}

please reply my question.

Thank you.

0 Kudos
2 Replies

2,414 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

you are using SDK in your project. The easiest way how to use LPUART is add it in processor expert, configure it, generate Processor Expert code, init UART and assign callback in main.c like this: 

LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
LPUART_DRV_InstallRxCallback(INST_LPUART1, rxCallback, NULL);

where rxCallback is for example is: 

void rxCallback(void *driverState, uart_event_t event, void *userData)
{

 // Toggle blue LED when character is received
   PINS_DRV_TogglePins(PTD, 1 << LED0_PIN_INDEX);
}

with SDK - there is no needs to set registers. With the very simple code (above) I have no issue with Interrupt and callback. 

For reference you can look at lpuart_echo_s32k144  SDK example. 

Hope it helps. 

Jiri 

0 Kudos

2,414 Views
mikening
Contributor I

Hi Jiri Kral,

  I am using lpuart_echo_s32k144  SDK example to test uart ,  if this example with Interrupt and callback , why need the code as below:

UART_ReceiveData(&uart_instance, buffer, 1U);
/* Wait for transfer to be completed */
while(UART_GetReceiveStatus(&uart_instance, &bytesRemaining) == STATUS_BUSY);

/* Check the status */
status = UART_GetReceiveStatus(&uart_instance, &bytesRemaining);

if (status != STATUS_SUCCESS)
{
/* If an error occurred, send the error message and exit the loop */
UART_SendDataBlocking(&uart_instance, (uint8_t *)errorMsg, strlen(errorMsg), TIMEOUT);
break;
}

lpuart rx with  Interrupt and callback , why add rec function in while loop ? 

thank you very much!

Mike

0 Kudos