S32K144 Uart Receive Problem

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

S32K144 Uart Receive Problem

Jump to solution
2,468 Views
cabz
Contributor II

Hello Sirs,
 I'm using the S32K144 sample cookbook for UART. The transmit function works fine however the receive doesn't work. I've debugged it a little and the program gets stuck in the line
while((LPUART1->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0);

You can see in the attached photo, the character 'a' should've been echoed in the terminal, but its not.

AllenGlen_0-1687764935066.png

The source code :
int main(void)
{
/*!
* Initialization:
* =======================
*/
WDOG_disable(); /* Disable WDOG */
SOSC_init_8MHz(); /* Initialize system oscilator for 8 MHz xtal */
SPLL_init_160MHz(); /* Initialize SPLL to 160 MHz with 8 MHz SOSC */
NormalRUNmode_80MHz(); /* Init clocks: 80 MHz sysclk & core, 40 MHz bus, 20 MHz flash */
PORT_init(); /* Configure ports */

LPUART1_init(); /* Initialize LPUART @ 9600*/
LPUART1_transmit_string("Running LPUART example\n\r"); /* Transmit char string */
LPUART1_transmit_string("Input character to echo...\n\r"); /* Transmit char string */

while(1)
{
LPUART1_transmit_char('>'); /* Transmit prompt character*/
LPUART1_receive_and_echo_char(); /* Wait for input char, receive & echo it*/
}
}

char LPUART1_receive_char(void) { /* Function to Receive single Char */
static char receive;
while((LPUART1->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0);
/* Wait for received buffer to be full */
PTD->PCOR |= (1 << 0);
receive= LPUART1->DATA; /* Read received data*/
return receive;
}

void LPUART1_receive_and_echo_char(void) { /* Function to echo received char back */
char send = LPUART1_receive_char(); /* Receive Char */
LPUART1_transmit_char(send); /* Transmit same char back to the sender */
LPUART1_transmit_char('\n'); /* New line */
LPUART1_transmit_char('\r'); /* Return */
}

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(2) /* Clock src=2 (SIRCDIV2_CLK) */
| PCC_PCCn_CGC_MASK; /* Enable clock for LPUART1 regs */


LPUART1->BAUD = LPUART_BAUD_SBR(0x34) | LPUART_BAUD_OSR(15);


LPUART1->CTRL = LPUART_CTRL_RE_MASK | LPUART_CTRL_TE_MASK;

}

 

Tags (2)
0 Kudos
Reply
1 Solution
2,393 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@AllenGlen

ok, you don't need to connect like this, just use USB directly

View solution in original post

0 Kudos
Reply
10 Replies
2,455 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@AllenGlen

You type the character 'a' and the device responds with ">a", isn't that normal?

0 Kudos
Reply
2,450 Views
cabz
Contributor II

no, the pink color signifies I sent it. The black color signifies I received it.

I should receive a black colored 'a' character.

0 Kudos
Reply
2,444 Views
Senlent
NXP TechSupport
NXP TechSupport
0 Kudos
Reply
2,441 Views
cabz
Contributor II

AllenGlen_0-1687770941359.png

do you think this is hardware problem sir?
I also see the CTS in your terminal is shining... what do you think it means

btw I'm using IAR, and this code is from its samples.

 

0 Kudos
Reply
2,431 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@AllenGlen

Very likely, I tested the "S32K144_Project_LPUART" routine, the result is normal

 

0 Kudos
Reply
2,418 Views
cabz
Contributor II
I've checked the 2 other boards, they also doesn't work...
0 Kudos
Reply
2,413 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@AllenGlen

Are you using S32K144EVB? The following is the code I tested, I don't see any difference.

/*
 * Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.
 * Copyright (c) 2016 - 2018, NXP.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "device_registers.h"	/* include peripheral declarations S32K144 */
#include "LPUART.h"

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(0b010)    /* Clock src=2 (SIRCDIV2_CLK) */
                            	 |  PCC_PCCn_CGC_MASK;     /* Enable clock for LPUART1 regs */

	LPUART1->BAUD = LPUART_BAUD_SBR(0x34)  	/* Initialize for 9600 baud, 1 stop: */
                	|LPUART_BAUD_OSR(15);  	/* 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 =	LPUART_CTRL_RE_MASK
					|LPUART_CTRL_TE_MASK;   	/* 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 */
}

void LPUART1_transmit_char(char send) {    /* Function to Transmit single Char */
	while((LPUART1->STAT & LPUART_STAT_TDRE_MASK)>>LPUART_STAT_TDRE_SHIFT==0);
	/* Wait for transmit buffer to be empty */
	LPUART1->DATA=send;              /* Send data */
}

void LPUART1_transmit_string(char data_string[])  {  /* Function to Transmit whole string */
	uint32_t i=0;
	while(data_string[i] != '\0')  {           /* Send chars one at a time */
		LPUART1_transmit_char(data_string[i]);
		i++;
	}
}

char LPUART1_receive_char(void) {    /* Function to Receive single Char */
	char receive;
	while((LPUART1->STAT & LPUART_STAT_RDRF_MASK)>>LPUART_STAT_RDRF_SHIFT==0);
	/* Wait for received buffer to be full */
	receive= LPUART1->DATA;            /* Read received data*/
	return receive;
}

void LPUART1_receive_and_echo_char(void)  {  /* Function to echo received char back */
	char send = LPUART1_receive_char();        /* Receive Char */
	LPUART1_transmit_char(send);               /* Transmit same char back to the sender */
	LPUART1_transmit_char('\n');               /* New line */
	LPUART1_transmit_char('\r');               /* Return */
}

 

0 Kudos
Reply
2,411 Views
cabz
Contributor II

yes sir, 

I think my pin connections are also correct, PTC6, PTC7 and 3.3V and GND

AllenGlen_0-1687773262580.jpeg

 

0 Kudos
Reply
2,394 Views
Senlent
NXP TechSupport
NXP TechSupport

Hi@AllenGlen

ok, you don't need to connect like this, just use USB directly

0 Kudos
Reply
2,381 Views
cabz
Contributor II

It works now, the problem must've been the serial wire. Thank you ^3^

0 Kudos
Reply