AVR-Ada Wiki
Ada cross compiler and libraries for AVR µCs
Status: Beta
Brought to you by:
rolf_ebert
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;
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:
This argument can be computed from WormFood's AVR Baud Rate Calculator. The divider depends upon the clock rate of your MCU.
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.