A UART problem

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

A UART problem

734 Views
john71
Senior Contributor I

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'.

0 Kudos
6 Replies

521 Views
john71
Senior Contributor I

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;

0 Kudos

521 Views
kerryzhou
NXP TechSupport
NXP TechSupport

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!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

521 Views
john71
Senior Contributor I

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...;)

0 Kudos

521 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello Evgeny Erenburg,

    The TWR-K70F120M have the according sample code, you can refer to it:

http://www.nxp.com/webapp/sps/download/license.jsp?colCode=KINETIS_120MHZ_SC&Parent_nodeId=132253864...

 

Wish it helps you!

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

521 Views
kerryzhou
NXP TechSupport
NXP TechSupport

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!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

521 Views
john71
Senior Contributor I

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.

0 Kudos