RS232 UART

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

im trying to write to Hyperterminal on my PC using RS232 UART from a STK 500. My program is

#include <90s8515.h>
#include
#include

void main(void){

UCR = 0x18;
UBRR = 0x19;

printf("\n TEST \n");

while(1){

printf("\n TEST TEST \n");
delay_ms(2000);
};
}

will this work ? Can i use a regular RS232 cable ?

My problem is that I`m not receive anything.

Regards Gunnar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

We need to know which compiler, what xtal frequency. UART init depands on xtal freq.....

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It looks like CodeVision. Why don't you let the Wizard do the application skeleton and chip init for you, and then put in your printf()?

BTW, CodeVision's Terminal facility is pretty good and has lots of options for low-level work.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I`m using CodeVision AVR. Is it different in IAR Embedded Workbench?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello every body,

Here is a piece of code that will work. This is plain 'C' no devopen etc.

To initialise the serial port

void usart0_init (void)
{
UBRR0h = 00;
UBRR0L = 23; // this will set the serial port to 9600 baud when the crystal connected is 3.69 MHz. See ATMEL .PDF file for actual value if you are using the 4M or 8M built-in clock

UCSR0B = 0x18; // enable receive and transmit
UCSR0C = 6; // no patiry and that stuff

}

Now to transmit a NULL terminated string

usart0_tramsmit (char *cptr) // this function takes a pointer to character
{
while (*cptr)
{
UDR0 = *cptr++;
while (!UCSR0A & 0x40); // wait here till transmit complete
UCSR0A = 0x40; // clear this flag for the next byte (char)
_delay_loop_1 (200); // optional if you need delay between chars
}
}

This is written for Atmega128 processor and since it has two serial ports, I am writing to port 0. You may refer to page 190 of the mega128 pdf file to get values that need to be written to the UCSRXX registers for proper baud rate setting. Hope this helps

Regards

Parthasaradhi Nayani