USART receive function causes hyperterminal to crash

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

Hello,
I working with an ATMEGA 16. I am trying to transmit and receive data using the USART and hyperterminal. I have had no trouble initializing the USART or transmitting data. In fact, I've done a dozen projects using the transmit function. But I'm not having any luck when I try to receive data from the keyboard. If I press one or two keys, I get nothing. If I keep trying, hyperterminal locks up. I've taken my code directly out of the ATMEGA 16 manual. My two subroutines are shown below.

#define UDRE 5
#define RXC 7

void transmit(unsigned char data)
{
while(!(UCSRA & (1<<UDRE)))
;
UDR=data;
}

unsigned char receive(void)
{
while(!(UCSRA & (1<<RXC)))
;
return UDR;
}

Does anyone have any idea why these simple subroutines wouldn't work?

thanks,
andy

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

Before doing anything else make sure that Hyperteminal is set up for no handsake or it will hang waiting for a CTS signal.

Alternatively you can short out the RTS and CTS pins in the DB9 connector.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

At what data rates are you TX/RX ing?

are you using internal clock or external Xtal?

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

It has to be something else. Please post more of your code (using code tags), including the initialization.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

The crystal is 7.3278 which results in a 0% error. I bought these crystals because of their compatibility with USART. The baud rate is 9600. I don't have my code on this computer, so I cannot post it. But as I said, I've used the USART (as a transmitter) quite a few times, so I am familiar with the initialization. For that matter, I use Codevision to automatically generate my init code.

Now, about the handshake...I am using defaults of 9600-8-N-1. How would I tell hyperterminal not to use a handshake?

Another thing which I hadn't thought of is that I may have a problem with my Max232N circuit. I will re-check the wiring when I get home.

Thanks for your ideas.
Andy

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

I just looked over the max232n circuit. In the datasheet, it is stated that the chip operates from a single power supply of 5V. But in the typical application drawing, there are three sources shown, a 5V, 8.5V, and -8.5V. My circuit has only the 5V supply connected. So before I go much further, can someone verify that they have successfully used the max232n chip with only a 5V supply?

thanks.

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

When starting hyperterminal, the default handshaking setting is *not* "none" (on my computer). It is the last option in the screen where you choose baud rate, number of bits, parity, stop bits and - at last - handshaking (Xon/Xoff, hardware, none).

Check your hyperterminal settings and see if it's trying to use hardware handshaking.

I tend to post off-topic replies when I've noticed some interesting detail.
Feel free to stop me.

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

My hyperterminal connection does say "hardware". So this should be set at "none"?

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

Why don't you just try it? Disconnect, change flow control to "none", connect and tell us what's happening.

I tend to post off-topic replies when I've noticed some interesting detail.
Feel free to stop me.

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

I will, when I get home.

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

Well Mr/Ms buffi, the hyperterminal "flow control" setting of "hardware" was the problem, as you suggested. I changed this setting to "none" and everything works. Thanks for your help.

Andy

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

..so I don't get thanked for suggesting it FIRST?? :cry: Only kidding. :)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

No, because you included more technical information.

I tend to post off-topic replies when I've noticed some interesting detail.
Feel free to stop me.

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

Sorry js, I totally missed that. And it was the first response. This selective observation could also be why I can't get my circuit to work.