UART Junk with TWR-k53n512

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

UART Junk with TWR-k53n512

ソリューションへジャンプ
1,667件の閲覧回数
smaschy
Contributor II

Hey Guys,

I'm trying to develop an UART Connection with the TWR-k53n512 TowerSystem. I use the Pins A41 and A42 from the Expansion Port for the UART 4.

My Code i use:

#include <stdio.h>
#include "derivative.h"

#include "io.h"
#include "uart.h"
#include "mcg.h"


int main(void)
{
     SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK;
     PORTC_PCR14 = PORT_PCR_MUX(0x03);
     PORTC_PCR15 = PORT_PCR_MUX(0x03);

     uart_init(TERM_PORT, 50000, 115200);

     uart_putchar(TERM_PORT, '0');
     printf("0");

     uart_putchar(TERM_PORT, '1');
     printf("1");


     for(;;) {
     }

     return 0;
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Now my Problem, i just receive junk in my terminal.

Line 17 and 18 gave me: "00 F0" and "00F0".

Line 20 and 21 gave me: "0E 3E FE" and "0E 3E FE".

So has anyone a clue for me? 

EDIT:

OK, it works!?

uart_init(TERM_PORT, 50000, 300);

When I change the baud rate in the code to 300 and the baud rate in my terminal to 600 it works. I receive the right data. It seems that I don't understand the baud rate or  the code correctlySmiley Sad.

ラベル(1)
0 件の賞賛
返信
1 解決策
1,432件の閲覧回数
smaschy
Contributor II

After the post from Hui_Ma I figured out that it was a hardware problem. The oscillator was broken.

元の投稿で解決策を見る

0 件の賞賛
返信
6 返答(返信)
1,433件の閲覧回数
smaschy
Contributor II

After the post from Hui_Ma I figured out that it was a hardware problem. The oscillator was broken.

0 件の賞賛
返信
1,432件の閲覧回数
skyviper
Contributor I

Since I can't see how you initialization function works, I can make several suggestions.

If you are attempting to use a 50 KHz clock to produce a 115200 baudrate, it won't work. You will need to have a clock that is at least baudrate times the divider of the UART.

Ensure the UART parity and stop bits match the terminal you are talking to.

Ensure your baudrate is correctly set.

Verify you are basing your baudrate on the correct clock and divider.

0 件の賞賛
返信
1,431件の閲覧回数
smaschy
Contributor II

Thank you Tony Sims for your answer!

I'm using files (K53 Learning Modules, Lab 5 - Serial Port) from Dan Cheung, Josh Watts and Sam Skalicky. I placed the files in the annex.

void uart_init (UART_MemMapPtr uartch, int sysclk, int baud)
{
    uint16_t sbr, brfa;
    uint8_t temp;

     /* Enable the clock to the selected UART */
    if(uartch == UART0_BASE_PTR)
          SIM_SCGC4 |= SIM_SCGC4_UART0_MASK;
    else
         if (uartch == UART1_BASE_PTR)
               SIM_SCGC4 |= SIM_SCGC4_UART1_MASK;
         else
              if (uartch == UART2_BASE_PTR)
                   SIM_SCGC4 |= SIM_SCGC4_UART2_MASK;
              else
                   if(uartch == UART3_BASE_PTR)
                        SIM_SCGC4 |= SIM_SCGC4_UART3_MASK;
                   else
                        if(uartch == UART4_BASE_PTR)
                             SIM_SCGC1 |= SIM_SCGC1_UART4_MASK;
                        else
                             SIM_SCGC1 |= SIM_SCGC1_UART5_MASK;

    /* Make sure that the transmitter and receiver are disabled while we
     * change settings.
     */
    UART_C2_REG(uartch) &= ~(UART_C2_TE_MASK
                    | UART_C2_RE_MASK );

    /* Configure the UART for 8-bit mode, no parity */
    UART_C1_REG(uartch) = 0;     /* We need all default settings, so entire register is cleared */

    /* Calculate baud settings */
    sbr = (uint16_t)((sysclk*1000)/(baud * 16));

    /* Save off the current value of the UARTx_BDH except for the SBR field */
    temp = UART_BDH_REG(uartch) & ~(UART_BDH_SBR(0x1F));

    UART_BDH_REG(uartch) = temp |  UART_BDH_SBR(((sbr & 0x1F00) >> 8));
    UART_BDL_REG(uartch) = (uint8_t)(sbr & UART_BDL_SBR_MASK);

    /* Determine if a fractional divider is needed to get closer to the baud rate */
    brfa = (((sysclk*32000)/(baud * 16)) - (sbr * 32));

    /* Save off the current value of the UARTx_C4 register except for the BRFA field */
    temp = UART_C4_REG(uartch) & ~(UART_C4_BRFA(0x1F));

    UART_C4_REG(uartch) = temp |  UART_C4_BRFA(brfa);

    /* Enable receiver and transmitter */
     UART_C2_REG(uartch) |= (UART_C2_TE_MASK
                    | UART_C2_RE_MASK );
}

The code above is from the uart.c file.

  • UART parity and stop bit match my terminal
0 件の賞賛
返信
1,431件の閲覧回数
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

I using your attached UART software and made some modification,which works with TWR-K53N512 board and TWR-SER2 board (For customer wants to use PTC14 and PTC15 pins). I attached the updated UART software code for your reference.

Please check below serial terminal print info:

pastedImage_1.png

Below is my test environment:

pastedImage_2.png


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信
1,431件の閲覧回数
smaschy
Contributor II

Thanks Hui_Ma for your input. But i still have the some problem. I just have the TWR-Ser Board without these jumpers. I'm using UART4: A41 (RXD0 / PTC14), A42 (TXD0 / PTC15) and UART3: A43 (RXD1 / PTC16), A44 (TXD1 /PTC17) in my code but it's just working with the baud rate 300 / 600.
But this code in the main.c file:

MCG_FEI_BLPE();

caught my attention. I can't execute this code thats why i changed it to:

MCG_BLPE_FEI();

Maybe this is my Problem?

0 件の賞賛
返信
1,431件の閲覧回数
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

Customer need to check the external 50MHz clock source from TWR-K53N512 board or TWR-SER board .

Then customer need to check related jumpers setting.

And customer also can set K53 PTC3 pin ALT5 function is CLKOUT, which could be used to measure the bus clock frequency.

I think it was the hardware issue,no the software.

Please check your hardware platform.


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------