UART problem

General discussion on mikroPascal for AVR.
Post Reply
Author
Message
Joris
Posts: 4
Joined: 04 Mar 2006 17:25
Location: The Netherlands
Contact:

UART problem

#1 Post by Joris » 04 Mar 2006 17:38

Hello,

I received the Easyavr3 board this week, and its great!.
Iam abit new in this sorry.

Now I was playing with the uart but I cant get it working above 19200.
from 38400 to 115200 it doesnt work. Iam sending about 15 bytes it is receiving correct except on the mentioned speeds it doesnt receive anything in the uart terminal. Now i thought it has something to do with the Oscillator so i tried all faster speeds and the external oscillator. but still not working on bautrates above 19200. how can i solve this, I need to use the higher boatrates.

Thanks in advance


Regards Joris

PS: I tried it with the Atmega16 and Atmega8535

vanja
mikroElektronika team
Posts: 253
Joined: 27 Jan 2005 15:13
Contact:

#2 Post by vanja » 06 Mar 2006 09:11

For higher speed you use:

Code: Select all

  UBRRL := 8;
  UBRRH := 0;
  UCSRB := $18;
  UCSRC := $86;
instead of USart1_Init(57600); for 8MHz clock

This software problem will be correct in next release.

Joris
Posts: 4
Joined: 04 Mar 2006 17:25
Location: The Netherlands
Contact:

#3 Post by Joris » 06 Mar 2006 19:04

Thanks you for that info, however with those settings it is set to 56000 and not to 57600.
I was searching for those commands in the manual but I coudnt find it.
Could you tell me the settings for 38400, 57600 and 115200.

Thanks in advance.

Best Regards Joris

Joris
Posts: 4
Joined: 04 Mar 2006 17:25
Location: The Netherlands
Contact:

#4 Post by Joris » 06 Mar 2006 19:48

I checked the atmega datasheet, and I found a formula for it:
UBRR = Fosf / 16*baud -1, so I wrote it like this
Fosf = System Oscillator clock frequency ( 8 mhz )

Code: Select all

  testing := 8000000/921600;  // testing is a real number
  testing := testing -1; 
  UBRRL := testing;
  UBRRH := 0;
  UCSRB := $18;  // To enable Tx and Rx ?
  UCSRC := $86;  // To set data frame 8 bits, one stop bit, no parity ?
but its not completely ok, I suppose I could manualy add some delay etc
.
However I think iam doing something wrong could you explain the OK formula or just post the correct settings for the mentioned speed in my last post.... sorry for abit double posting.

Regards Joris

Joris
Posts: 4
Joined: 04 Mar 2006 17:25
Location: The Netherlands
Contact:

#5 Post by Joris » 07 Mar 2006 17:19

First of all sorry for my Laziness:)
I search abit more in the datasheet, and found UBRR tables. However it still doesnt work good at 57600.
Will try all values giving in it. but I got a 7.3728 xtal it supposed to have 0% error but not sending ok, I think I could have some settings wrong ?
Iam sorry but I never coded anything for a mcu befor.

Regards joris

PS: how to use xtall above 12mhz

vanja
mikroElektronika team
Posts: 253
Joined: 27 Jan 2005 15:13
Contact:

#6 Post by vanja » 08 Mar 2006 09:02

Original code for init :

Code: Select all

procedure Usart1_Init(baud_rate : longint);
var tmp: longint;
begin
  tmp   := Clock_kHz_ * 1000;
  tmp   := tmp div baud_rate;
  tmp   := tmp shr 4;
  dec(tmp);
  UBRRL := tmp;
  UBRRH := longint(tmp shr 8);
  UCSRB := $18;
  UCSRC := $86;
end;
For some reason it does not work for hi frequency.

Best way is to read datasheet for chip ATmega16.

Post Reply

Return to “mikroPascal for AVR General”