The functions I use
void UART_SendByte (UART_MemMapPtr channel, char ch)
{
while(!(UART_S1_REG(channel) & UART_S1_TC_MASK) ) {}
/* Send the character */
UART_D_REG(channel) = ch;
}
void UART_SendString(UART_MemMapPtr uartChannel, const char *str)
{
while (*str)
{
UART_SendByte(uartChannel, *str++);
}
}
Now I test it.
UART_SendString(UART2_BASE_PTR, "hello\r");
The problem - the first char is not displayed on a terminal. I see 'ello'.
OMG. The problem was my sloppy code. Somehow after the line
/* Configure the UART for 8-bit mode, no parity */
UART_C1_REG(uartch) = 0; /* We need all default settings, so entire register is cleared */
I uncommented the line
//set odd parity + parity enable + 9-bit
UART_C1_REG(uartch) |= UART_C1_PT_MASK | UART_C1_PE_MASK | UART_C1_M_MASK;
Hello Evgeny Erenburg,
Thank you for the solutions sharing.
Next time when you post the question, please also tell us what the chip and code you are using, then we can help you to check it directly.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I work with TWR-K70F120M. As a starting point I took an example provided on site. But I experimented with it and as a result...;)
Hello Evgeny Erenburg,
The TWR-K70F120M have the according sample code, you can refer to it:
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Evgeny Erenburg,
I don't know what the board and kinetis chip you are using, and how you configure your uart module.
Actually, you can refer to our official code, there has a lot of uart code for kinetis, you can refer to the KSDK sample code which can be downloaded from this link:
Welcome to MCUXpresso | MCUXpresso Config Tools
SDK Builder, choose the board or chip which you are using, generate the code and download it.
Take KL25 as an example, you can find the uart code in folder:SDK_2.2_FRDM-KL25Z\boards\frdmkl25z\driver_examples\uart
Please refer to our official code at first.
If you still have question after you refer to it, please let me know!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Well... It doesn't print some chars.
I send UART_SendString(UART2_BASE_PTR, "AOK"); - get 'AK'
I send UART_SendString(UART2_BASE_PTR, "AhK"); - get 'AK'
I send UART_SendString(UART2_BASE_PTR, "ABK"); - get 'ABK' - all chars OK.
I tried on two different terminals - the same result.
How can it be? I don't understand.