SoftUart
NOTE | This article describes a (discontinued) internal module/interface. As of version 2013.r6 available as External Library, see Libraries |
---|
Is LunaAVR's Software-Uart-Interface and ea simplified Uart-Emulation. Any Port-Pin can be assigned to RX/TX. SoftUart uses 1 Start and 1 Stop-Bit (Standard-Configuration). The Baudrate can be set freely. Similar to the Hardware-Uart, you must watchout for the error rate. You should select a Baudrate with a low error rate. Baudrats upto about 1/100 of the CPU Frequency are possible (200000 Baud @ 20 Mhz).
Initialization is done once and is globally valid. Modification to initialization or Pins is not possible at runtime. Initialization must take place textually before any calls are made. The Preprocessor uses constants to optimize speed.
Properties(write only) | ||
---|---|---|
Name | Description | Value |
.Mode = | Signal Mode | normal, inverted |
.PinRxd = | Rxd-Pin (Receive) define | Port.n |
.PinTxd = | Txd-Pin (Transmit) define | Port.n |
.Baud = | Baudrate define | Constant |
.AdjustDelay = | Bit-Time adjust1) | Constant |
Methods | |||
---|---|---|---|
Name | Description | Type | r/w |
Transmit several values, see Print. | - | write | |
.InpStr([echo,[breakChar]]) | Read max. 254 characters from the port and exits when breakChar (Default: 13) is encountered. If echo = 0 (Default: 1), echoing will be suppressed. Both paramters are optional. | string | read |
.ReadByte | Byte read (waits for character) | byte | read |
.ReadWord | Word read (waits for character) | word | read |
.ReadInteger | Integer read (waits for character) | integer | read |
.ReadLong | Long read (waits for character) | long | read |
.ReadSingle | Single read (waits for character) | single | read |
.Read sramAdresse,Anzahl | Read number of Byte and save to memory (waits until all characters are read). | - | read |
.ReadC sramAdresse | Read number of Byte and save to memory (Waits until a Null-Byte is read. The Null-Byte is discarded.). | - | read |
.ReadP sramAdresse | Read number of Byte and save to memory (The first Byte received holds the number of Byte to read. Waits until all characters are read.). | - | read |
.WriteByte | Byte write (waits until transmission is ready) | byte | write |
.WriteWord | Word write (waits until transmission is ready) | word | write |
.WriteInteger | Integer write (waits until transmission is ready) | integer | write |
.WriteLong | Long write (waits until transmission is ready) | long | write |
.WriteSingle | Single write (waits until transmission is ready) | single | write |
.Write sramAdresse,Anzahl | Transmit a number of Byte from memory (waits until all characters have been sent). | - | write |
.WriteC sramAdresse | Transmit a number of Byte from memory until a Null-Byte is encountered(waits until all characters have been sent including Null-Byte). | - | write |
.WriteP sramAdresse | Transmit a number of Byte from memory, the first Byte denotes the number of Byte to transmit(waits until all characters have been sent. | - | write |
.CWrite flashAdresseBytes,Anzahl | Transmit a number of Byte from Flash (waits until all characters have been sent). | - | write |
.CWriteC flashAdresseBytes | Transmit a number of Byte from Flash until a Null-Byte is encountered (waits until all characters have been sent except the Null-Byte). | - | write |
.CWriteP flashAdresseBytes | Transmit a number of Byte from Flash, the first Byte denotes the number of Byte to (waits until all characters have been sent. | - | write |
.Dump | Hexdump for debuggin puposes, see Dump. | - | call |
Notice
Emulation takes place in the software, therefore timing is very important. A interrupt during transmission will influence the timing.
Example
avr.device = attiny2313 avr.clock = 20000000 avr.stack = 4 ' SoftUart Example: simple terminal ' Setup Pins you want to use and baud rate first SoftUart.PinRxd = PortB.0 ' Receive Pin: RXD SoftUart.PinTxd = PortB.1 ' Transmit Pin: TXD SoftUart.Baud = 19200 ' Baud rate up to 1/100 of avr.clock (200000 baud @ 20 Mhz) dim a as byte SoftUart.Write 12 ' clear terminal SoftUart.Print " > "; ' the prompt do a=SoftUart.Read ' wait and get byte from input select case a case 13 SoftUart.Write 13 ' CR SoftUart.Write 10 ' LF SoftUart.Print " > "; ' the prompt default SoftUart.Write a endselect loop