Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Atmega8-usart-hyperteminal problem

Status
Not open for further replies.

calin17us

Junior Member level 1
Joined
May 6, 2009
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,429
i use atmega8, and y program to send "Hallo" to USART(Tx), and when i look in hyperterminal i see other character. i serch on the net and the character is from extended ascii code.
i dont understand why it happen this.
Please can you give me a hand.

This is the cod i am useing it:

#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 1000000UL
#define BAUD 9600
#define UBRR_VAL F_CPU/16/BAUD-1

void delay_ms(int delay) {
int i;
for (i=0;i<=delay;i++) {
_delay_ms(1);
}
}

void init_uart(unsigned int ubrr) {
/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8 ) ;
UBRRL = (unsigned char)(ubrr);
/* Enable receiver and transmitter */
UCSRB |= (1<<RXEN);
UCSRB |= (1<<TXEN);
/* Set frame format: 8data, 2stop bit */
UCSRC = (1<<URSEL)|(1<<USBS)|(3<<UCSZ0);
}

void send_char(unsigned char data) {
/* Wait for empty transmit buffer */
while (!(UCSRA & (1<<UDRE)));
/* Put data into buffer, sends the data */
UDR = data;
}

void send_string(char *data) {
while (*data) {
send_char(*data);
data++;
}
}

int main(void) {
init_uart(UBRR_VAL);
while (1) {
send_string("Hallo");
delay_ms(1000);
}
return 1;
}

This is a picture of what see hyperterminal:
https://images.elektroda.net/55_1274543482.jpg

Please give me a hand.
 

Kurenai_ryu

Advanced Member level 2
Joined
Jun 10, 2006
Messages
671
Helped
159
Reputation
316
Reaction score
99
Trophy points
1,308
Location
Bolivia
Activity points
5,913
so it's working with a 1MHz crystal... or with the internal oscillator (which could be innacurated) or if you are using an external oscilator is it correctly configured with the programming fuses?
 

Enlightenment

Full Member level 3
Joined
Jul 26, 2006
Messages
174
Helped
29
Reputation
58
Reaction score
23
Trophy points
1,298
Location
3rd Rock From Sun
Activity points
2,671
Most of the time you get garbage on a terminal when the transmission baud rate from your embedded device doesn't match the baud rate setting for your terminal.

Sometimes you will get messed up characters if you are running high baud rates with long cables, because of capacitance or other cable issues.

I looks like you need to change your crystal to a different frequency so your baud rate will be more accurate speed.

Try changing from 9600 baud to 2400 baud or lower so see if the timing error goes away.

If you can change your crystal, then change it to 1.8432 MHz, since 115200 * 16 is dead-on, and 9600 is exactly 1/12 of 115200. See this table for some other crystal frequencies to get dead-on UART baud rates... https://en.wikipedia.org/wiki/Crystal_oscillator_frequencies
 

    calin17us

    Points: 2
    Helpful Answer Positive Rating

calin17us

Junior Member level 1
Joined
May 6, 2009
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,429
thank you very much, i change baud rates to 2400 and it work ...thank you again
 

Enlightenment

Full Member level 3
Joined
Jul 26, 2006
Messages
174
Helped
29
Reputation
58
Reaction score
23
Trophy points
1,298
Location
3rd Rock From Sun
Activity points
2,671
CRYSTAL / 16 / BAUD

1000000 / 16 / 9600 = 6.510

integer conversion rounds this down to 6

6 * 9600 * 16 = 921600

921600 / 1000000 = 0.9216

Your baud rate is 7.84% slower than 9600 baud.

You could have rounded up to 7, but since 6.510 is almost dead center it likely wouldn't make much difference.

To round to the nearest integer, you should use the following:
(unsigned int)((double)F_CPU / (double) 16 / (double) BAUD + (double)0.5)
then
subtract 1 for the value to be placed in your register.

Added after 3 minutes:


CRYSTAL / 16 / BAUD

1000000 / 16 / 2400 = 26.041666

integer conversion rounds this down to 26

26 * 2400 * 16 = 998400

998400 / 1000000 = 0.9216

Your baud rate is 0.16% slower than 2400 baud.

In this situation, you are almost dead-on your 2400 baud rate, thus you are fine.

Added after 8 minutes:

fix for typo above:
998400 / 1000000 = 0.9984

Added after 7 minutes:

If you want higher baud rates, then you should choose a higher speed crystal clock rate, and if you want dead-on baud rates then you'll have to choose something like 1.8432 MHz or some multiple of it.

The better microcontrollers have more flexibility in their UART baud rate generators, where the best have a N/M fractional multiplier so you can get dead-on baud rates.

Added after 2 minutes:

Hyperterminal sucks, plus it doesn't come with Vista and 7, so a good choice is the free bare-bone uCon terminal. Not fancy, but it is 100% free and works.
https://www.umonfw.com/ucon/index.html
 

calin17us

Junior Member level 1
Joined
May 6, 2009
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,429
The problem is i have 1 MHz because i use the internal oscillator and is standar set with this value, end i dont know how to changeit. On my board i have a 4Mhz clock, but i dont use it.
I program my avr with ponyprog, and try to change my clock, with setting the fuse bit (CTR+s), but when i program, at the end, have a message "Writing fail" and my avr is gone(if i try to read or write to him it dont work).
It is another way to set this fuse bit?
Can you help me....
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top