Serial Protocol - KL25Z - KSDK

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

Serial Protocol - KL25Z - KSDK

844 Views
hmal
Contributor I

Dear all, I'm trying to send the word "Hello World" to the serial port using the KSDK library.

I'm following the official documentation, but I'm having trouble finding the error.

I wrote the code below, but nothing is being sent. Could someone tell me what I'm doing wrong?

CLOCK_SYS_EnableUartClock(UART0_IDX);

uart_user_config_t uartConfig;
uart_state_t uartState;
uint8_t sourceBuff[19] = "\r\nHello World!\n\n\r";

uartConfig.baudRate = 115200;
uartConfig.bitCountPerChar = kUart8BitsPerChar;
uartConfig.parityMode = kUartParityDisabled;
uartConfig.stopBitCount = kUartOneStopBit;

OSA_Init();

UART_DRV_Init(UART0_IDX, &uartState, &uartConfig);
uint32_t byteCount = sizeof(sourceBuff);
UART_DRV_SendDataBlocking(UART0_IDX, sourceBuff, byteCount, 1);

Thank you very much!

0 Kudos
9 Replies

770 Views
hmal
Contributor I

Thanks @Robin_Shen,

I consulted your reference and was able to identify several errors I was making. However, I still haven't been able to solve it. Please see the code below:

 

 

uint8_t rxChar = 0;
	uint32_t byteCountBuff = 0;
	uint32_t uartSourceClock = 0;
	UART_Type * baseAddr = BOARD_DEBUG_UART_BASEADDR;

	CLOCK_SYS_EnableUartClock(BOARD_DEBUG_UART_INSTANCE);

	uartSourceClock = CLOCK_SYS_GetUartFreq(BOARD_DEBUG_UART_INSTANCE);

	UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD);
	UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
	UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
	UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);

	UART_HAL_EnableTransmitter(baseAddr);
	UART_HAL_EnableReceiver(baseAddr);

	const char* message = "Teste\r\n";
	size_t messageLength = strlen(message);

	UART_HAL_SendDataPolling(baseAddr, (const uint8_t*)message, messageLength);

 

 

I believe I am making a mistake in the initialization because the examples I see on the internet use the functions hardware_init() and dbg_uart_init(), but I cannot use those resources. I need to resolve it using only the KSDK library.

 

Thanks again!

0 Kudos

747 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

If you have to use KSDK library, then please refer to the examples:
C:\Freescale\KSDK_1.3.0\examples\frdmkl25z\demo_apps\hello_world
C:\Freescale\KSDK_1.3.0\examples\frdmkl25z\driver_examples\lpsci

0 Kudos

729 Views
hmal
Contributor I

@Robin_Shen ,

I studied the demo and attempted to reproduce it, following the documentation provided on the website: https://www.nxp.com/docs/en/reference-manual/KSDK12APIRM.pdf

In the documentation, it states:

1 - To initialize the LPSCI driver, call the LPSCI_DRV_Init() function and pass the instance number of the relevant LPSCI peripheral, memory for the run-time state structure, and a pointer to the user configuration structure. For example, to use LPSCI0 pass a value of 0 to the initialization function.

2 - Then, pass the memory for the run-time state structure and, finally, pass a user configuration structure of the type lpsci_user_config_t

lpsci_user_config_t lpsciConfig;
lpsciConfig.baudRate = 9600;
lpsciConfig.bitCountPerChar = kLpsci8BitsPerChar;
lpsciConfig.parityMode = kLpsciParityDisabled;
lpsciConfig.stopBitCount = kLpsciOneStopBit;

This example shows how to call the LPSCI_DRV_Init() function given the user configuration structure and the LPSCI instance 0.

uint32_t lpsciInstance = 0;
lpsci_state_t lpsciState; // user provides memory for the driver state structure
LPSCI_DRV_Init(lpsciInstance, &lpsciConfig, &lpsciState);

For blocking transfer functions transmit and receive:

uint8_t sourceBuff[26] ={0}; // sourceBuff is populated with desired data
uint8_t readBuffer[10] = {0}; // readBuffer is populated with LPSCI_DRV_ReceiveData function

uint32_t byteCount = sizeof(sourceBuff);
uint32_t rxRemainingSize = sizeof(readBuffer);

// for each use there, set timeout as "1"
// lpsciState is the run-time state. Pass in memory for this
// declared previously in the initialization chapter
LPSCI_DRV_SendDataBlocking(&lpsciState, sourceBuff, byteCount, 1); // function won’t return until transmit is complete
LPSCI_DRV_ReceiveDataBlocking(&lpsciState, readBuffer, 1, timeoutValue); //function won’t return until it receives all data

I tried to adapt the code as follows:

lpsci_user_config_t lpsciConfig;

lpsciConfig.baudRate = 115200;
lpsciConfig.bitCountPerChar = kLpsci8BitsPerChar;
lpsciConfig.parityMode = kLpsciParityDisabled;
lpsciConfig.stopBitCount = kLpsciOneStopBit;

uint32_t lpsciInstance = 0;
lpsci_state_t lpsciState;

LPSCI_DRV_Init(lpsciInstance, &lpsciConfig, &lpsciState);

uint8_t sourceBuff = 1;
uint32_t byteCount = sizeof(sourceBuff);

LPSCI_DRV_SendDataBlocking(&lpsciState, sourceBuff, byteCount, 1);

However, I am still unable to send anything through the USB port.

I am using PuTTY to monitor the USB port.

Could you please advise me on what I might be doing wrong?

Thank you for the help and patience.

0 Kudos

693 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Are you using the FRDM-KL25Z board or a circuit board designed by yourself? Have you measured the UART0_TX pin with a logic analyzer or oscilloscope, and can you observe the waveform output? Is there any difference in the relevant register values when you debug the official example and your new project? For example: UART0, SIM_SOPT2, SIM_SOPT5, SIM_SCGC4, PORTx_PCRn[MUX] registers.

0 Kudos

687 Views
hmal
Contributor I

I am using the KL25Z board connected to my computer through the OpenSDA port. I would like to read the message sent by the board on my computer through the USB port.

0 Kudos

679 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Does psci_polling work on your FRDM-KL25Z? If you can obersive signal on UART0_TX(J2.4) but did not receive information on PuTTY , then you may need to check that the drivers for PEMicro are installed correctly and check the settings for PuTTY.

0 Kudos

672 Views
hmal
Contributor I

I believe the issue is not with the PEMicro driver because the Hello World example works perfectly. I think I'm forgetting to configure the ports or initialize some functionality on the board.

0 Kudos

658 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

So did you compare the difference in register values while debugging?

0 Kudos

822 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi

Please download MCUXpresso SDK for KL25Z, for example: SDK_2.2.0_FRDM-KL25Z. There are several UART examples.

By the way, please note: MCUXpresso IDE and Semihosting


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------