Setting up UART

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

Setting up UART

2,408 Views
VinceTF
Contributor III

Device: MCF52258

Complier: CW 10.2

RTOS: none/bare metal

 

Note: Hardware design is similar to M52259DEMO

 

After reading a couple of examples on this board, I setup a bareboard project with UART support in codewarrior.

Verified divider for baud rate is setup correctly.

 

However I do not see any output on hyperterminal. Please

help.  Can anyone provide examples for this device?

 

See code snippet from the main function below:

 

/*

* main implementation: use this sample to create your own

application

*

*/

 

 

#include "support_common.h" /* include peripheral

declarations and more */

#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)

/* Standard IO is only possible if Console or UART support is

enabled. */

#include
#include "uart_support.h"
#endif

 


class counterclass
{
private:
    int m_counter;
public:
    counterclass(void)
    {
        m_counter = 0;
    };
    void increment(void)
    {
        m_counter++;
    };     
};

 

int main(void)
{
    counterclass myccounter;
//    UARTError error;
    volatile char c;
    unsigned char status;
    
//    MCF_GPIO_PORTUC;
    MCF_GPIO_PUCPAR &= 0xf0;
    MCF_GPIO_DDRUC = 0x01;
//    uart_init(int channel, unsigned long systemClockKHz,
unsigned long baudRate)
//    uart_init(3, unsigned long systemClockKHz, 19200);
    
    
//    UARTError InitializeUART(UARTBaudRate baudRate)
//    error = InitializeUART(kBaud19200);
    
    uart_init(TERMINAL_PORT, SYSTEM_CLOCK_KHZ,
TERMINAL_BAUD);
    uart_init(1, SYSTEM_CLOCK_KHZ, TERMINAL_BAUD);
    uart_init(2, SYSTEM_CLOCK_KHZ, TERMINAL_BAUD);
    
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)
//    printf("Hello World in C++ from MCF52258 derivative on
MCF52258 board\n\r");
//    printf("\n\rM52223EVB board\n\r");
#endif
    for(;;) {    
        myccounter.increment();
//        c = uart_getchar (TERMINAL_PORT); // Read a
character.
//        uart_putchar (TERMINAL_PORT, c); // echo it.
        
//        c = uart_getchar (2); // Read a character.
//        uart_putchar (2, c); // echo it.
        
        uart_putchar (0, 'a');
        uart_putchar (1, 'b');
        uart_putchar (2, 'c');
        
    }
}

 

Labels (1)
Tags (2)
0 Kudos
3 Replies

844 Views
TomE
Specialist II

> However I do not see any output on hyperterminal.


HyperTerminal? You must have a very old computer to still have that on it.


HyperTerminal is very fussy. You may only have a "three wire connection" from the board to your PC. But there are 9 pins on the serial connector, and HyperTerminal wants some of the other ones "in the right state". It also assumes you want to use a Modem, so is a little tricky to set up to use the serial port as-is.


Link pins 2 and 3 to HyperTerminal (to the PC connector) and see if characters you type into HyperTerminal are echoed back.. If they're not echoed then HyperTerminal won't show you anything from your device either.


You'd be better off downloading puTTY or TeraTerm and using them instead.


The UART pins on the CPU have 2, 3 or 4 alternate functions. These have to be selected in the Pin Assignment Registers. I see you're setting:

> MCF_GPIO_PUCPAR &= 0xf0;

You're not setting PUAPAR or PUBPAR, but are apparently trying to print to three UARTs. There are two PUCPAR variants (Figures 15-23 versus 15-26) which I can't understand at the moment. You code is very confusing as it is mixing numbers (1, 2, 3) with #defines like TERMINAL_PORT that you don't include in your sample code, so I don't know what they are.

As always you're better off using an oscilloscope to see if the pins are doing what you think they are.

Tom

0 Kudos

844 Views
VinceTF
Contributor III

Tom,

Thank you for your response.  I am now using TeraTerm and I have the gpio initialized correctly (I think).  I also cleaned up the code a little so it is more readable.

Note that this code is based off of CW 10.2 generated bareboard project for mcf52258.  For clarity, I've attached the entire project.  Rename the .tst file to .exe and run it to extract.

The uart_getchar function below is stuck waiting for RXRDY.  If I comment out "c = uart_getchar (2);", the uart_putchar() function works.

Any idea what I am doing wrong here?

Thanks,

-Vince

#include "support_common.h" /* include peripheral declarations and more */

#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)

/* Standard IO is only possible if Console or UART support is enabled. */

#include <stdio.h>

#include "uart_support.h"

#endif

class counterclass

{

private:

  int m_counter;

public:

  counterclass(void)

  {

  m_counter = 0;

  };

  void increment(void)

  {

  m_counter++;

  };

};

int main(void)

{

  counterclass myccounter;

  volatile char c;

  unsigned char status;

  //setup gpio for uart.

  MCF_GPIO_PUCPAR = 0 | MCF_GPIO_PUCPAR_UTXD2_UTXD2 | MCF_GPIO_PUCPAR_UTXD2_UTXD2;

  uart_init(2, SYSTEM_CLOCK_KHZ, TERMINAL_BAUD);

#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)

// printf("Hello World in C++ from MCF52258 derivative on MCF52258 board\n\r");

// printf("\n\rM52223EVB board\n\r");

#endif

  for(;;) {

  myccounter.increment();

  c = uart_getchar (2);      // Read a character.

  uart_putchar (2, 'c');

  status = MCF_UART_USR(2);

  }

}

char uart_getchar (int channel)

{

   

  /* Wait until character has been received */

    while (!(MCF_UART_USR(channel) & MCF_UART_USR_RXRDY))

    {


    };

  

    return (char)MCF_UART_URB(channel);

}

0 Kudos

844 Views
TomE
Specialist II

> Any idea what I am doing wrong here?

No, could be anything. There's an almost infinite number of things you could have got wrong.

> The uart_getchar function below is stuck waiting for RXRDY

It is waiting to receive a character. I assume you know this. You need to send it a character from TeraTerm for it to receive that character, return with it so uart_putchar() can echo it. If you don't want that function to get "stuck" you need to call a different function that tests if a character has been received before you call that function to receive it.

So either TeraTerm isn't sending anything (because it is configured to not send until RTS/CTS/DST/DTR are set right) or the cable is wrong, or the board or connector are wrong or the receiver isn't working or powered or the Uart RX pin isn't configured properly or the Receiver isn't configured properly. See if the data is getting to the Uart RX pin on the CPU with an Oscilloscope. That will tell you if the problem is "out" or "in" from that point.

Tom

0 Kudos