Recent

Author Topic: Does anybody have example code for UART for the ATMEGA16A ?  (Read 3233 times)

Hartmut

  • Hero Member
  • *****
  • Posts: 736
Re: Does anybody have example code for UART for the ATMEGA16A ?
« Reply #15 on: November 28, 2023, 03:44:50 pm »
...
{$DEFINE UART_UCSRA := 0x86}
{$DEFINE UART_UCSRB := 0x85 }
{$DEFINE UART_UCSRC := 0x84 }
{$DEFINE UART_UBRRL := 0x81 }
{$DEFINE UART_UBRRH := 0x82 }
{$DEFINE UART_UDR := 0x80}
...

Some remarks to this:
1) I'm not sure whether "0x86" etc. works correctly. On my system it's not allowed. I would use "$86" instead.

2) FPC has already a file which contains those constants which you IMHO should use:
Code: Pascal  [Select][+][-]
  1. ...
  2. // USART
  3. var
  4.   UDR : byte absolute $00+$2C; // USART I/O Data Register
  5.   UCSRA : byte absolute $00+$2B; // USART Control and Status Register A
  6.   UCSRB : byte absolute $00+$2A; // USART Control and Status Register B
  7.   UCSRC : byte absolute $00+$40; // USART Control and Status Register C
  8.   UBRRH : byte absolute $00+$40; // USART Baud Rate Register Hight Byte
  9.   UBRRL : byte absolute $00+$29; // USART Baud Rate Register Low Byte
  10. ...
On my system this file is located in <installdir>/fpcsrc/rtl/embedded/avr/atmega16.pp and is automaticly included, when you have correctly selected ATMega16A CPU.

3) You see, that your values do not correspond with above file atmega16.pp. A difference of $20 may be correct, depending on how you adress these ports:
Quote
When using the I/O specific commands IN and OUT, the I/O addresses $00 - $3F must be used. When addressing I/O Registers as data space using LD and ST instructions, $20 must be added to these addresses => use $20 - $5F.
From page 19 of my Link in reply #13.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: Does anybody have example code for UART for the ATMEGA16A ?
« Reply #16 on: November 28, 2023, 04:54:39 pm »
I am afraid something got confused...

I need the values for the ATtiny841

to many problems with the list of values from here.

Using ufp_uartserial.pas

Anybody crazy enough to send me up the complete list ? to compile at once ?

Because i am confused.
« Last Edit: November 28, 2023, 05:18:56 pm by pascalbythree »

Hartmut

  • Hero Member
  • *****
  • Posts: 736
Re: Does anybody have example code for UART for the ATMEGA16A ?
« Reply #17 on: November 28, 2023, 05:27:35 pm »
On my different Lazarus-Installations I found only 1 file for ATtiny841: <installdir>/fpcsrc/rtl/embedded/avr/attiny841.pp
It is from Lazarus ver=2.1.0 rev=64456 / FPC ver=3.3.1 rev=48497
It contains e.g.:

Code: Pascal  [Select][+][-]
  1. ...
  2. var
  3.   UDR0: byte absolute $80;  // USART I/O Data Register
  4.   UBRR0: word absolute $81;  // USART Baud Rate Register Bytes
  5.   UBRR0L: byte absolute $81;  // USART Baud Rate Register Bytes
  6.   UBRR0H: byte absolute $82;  // USART Baud Rate Register Bytes;
  7.   UCSR0D: byte absolute $83;  // USART Control and Status Register D
  8.   UCSR0C: byte absolute $84;  // USART Control and Status Register C
  9.   UCSR0B: byte absolute $85;  // USART Control and Status Register B
  10.   UCSR0A: byte absolute $86;  // USART Control and Status Register A
  11. ...
  12.  
I attached this file. HTH.

pascalbythree

  • Sr. Member
  • ****
  • Posts: 255
Re: Does anybody have example code for UART for the ATMEGA16A ?
« Reply #18 on: November 28, 2023, 06:01:21 pm »
Yay!

It got to work! thank you for your time...

 

TinyPortal © 2005-2018