Menu

AVR.UART Log in to Edit

AVR.UART

with AVR.Strings;                  use AVR.Strings;
with AVR.Programspace;             use AVR.Programspace;

package AVR.UART is
pragma Preelaborate;

-- Initialize the registers, internal clock and baud rate generator
procedure Init(Baud_Divider : Unsigned_16; Double_Speed : Boolean := False);

type Chars_Ptr is access all Character;
pragma No_Strict_Aliasing (Chars_Ptr);

procedure Put(Ch : Character);
procedure Put_Raw(Data : Unsigned_8);

procedure Put(S : AVR_String);
procedure Put(Str : Program_Address; Len : Unsigned_8);
procedure Put_C(S : Chars_Ptr);
procedure Put(S : Chars_Ptr) renames Put_C;

procedure Put_Line(S : AVR_String);
procedure Put_Line(S : Chars_Ptr);

procedure New_Line;                   -- Transmit 16#0A#

procedure Put(Data : Unsigned_8;  Base : Unsigned_8 := 10);
procedure Put(Data : Integer_16;  Base : Unsigned_8 := 10);
procedure Put(Data : Unsigned_16; Base : Unsigned_8 := 10);
procedure Put(Data : Unsigned_32; Base : Unsigned_8 := 10);

--  Input routines
function Get return Character;        -- Get byte as Character
function Get_Raw return Unsigned_8;   -- Get byte as Unsigned_8

procedure Get_Line(S : out AVR_String; Last : out Unsigned_8);

procedure Sender_Mode;                -- Enable transmitter & disable receiver
procedure Receiver_Mode;              -- Enable receiver & disable transmitter
procedure Send_LIN_Break;             -- Send a "Break" signal

end AVR.UART;

AVR.UART.Init

This procedure initializes the UART to start the transmitter and receiver, to operate at the baud rate determined by argument Baud_Divider. Some UARTs allow operating at double speed. When required, set argument Double_Speed to True to enable that feature.

procedure Init(Baud_Divider : Unsigned_16; Double_Speed : Boolean := False);

The UART is initialized to operate in:

  • Asynchronous mode
  • 8 bit bytes
  • No parity bit
  • 1 stop bit

Baud_Divider

This argument can be computed from WormFood's AVR Baud Rate Calculator. The divider depends upon the clock rate of your MCU.

AVR.UART.New_Line

Be aware that this procedure sends a LF character only. Sometimes what is called for is a CR and LF to be sent, especially if the terminal is a dumb tty device.


Related

Wiki: UART

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.