Uart

Module NameUart, Uart2
Import NameUart, Uart2

The Uart and Uart2 modules enable serial data to be read and written over an RS232 interface using an inbuilt hardware Uart peripheral. The Uart module is connected to pins D0 (RX) and D1 (TX) and the Uart2 module is connected to pins D2 (RX) and D3 (TX). Please note that if the Firewing loader firmware is not being used, you will need to configure the UART1 RX and TX pins manually as described here for the module to work correctly. No additional code is required for UART2.

Module Variables

SetBaudrate

Sub SetBaudrate(baud As Baudrate)
  • baud - The communication baudrate. Can be Baudrate.Is9600, Baudrate.Is19200, Baudrate.Is38400, Baudrate.Is57600 and Baudrate.Is115200. Default value if Baudrate.Is38400.

Sets the communication baudrate for the UART port. Please note that if using the Fireing main board, the baudrate for UART1 is fixed at Baudrate.Is38400.

ClearOverrun

 Sub ClearOverrun()

Clear USART overrun error by resetting receive flag

ReadByte

 Function ReadByte() As Byte

Read a Byte from the hardware USART. Note that this is a blocking call. To determine if there is data to read, make a call to DataAvailable first.

ReadBoolean

 Function ReadBoolean() As Boolean

Read a Boolean from the hardware USART. Note that this is a blocking call. To determine if there is data to read, make a call to DataAvailable first.

ReadUShort

 Function ReadUShort() As UShort

Read a Byte from the hardware USART. Note that this is a blocking call. To determine if there is data to read, make a call to DataAvailable first.

ReadUInteger

 Function ReadUInteger() As UInteger

Read a UInteger from the hardware USART. Note that this is a blocking call. To determine if there is data to read, make a call to DataAvailable first.

ReadSingle

 Function ReadSingle() As Single

Read a Single from the hardware USART. Note that this is a blocking call. To determine if there is data to read, make a call to DataAvailable first.

WriteByte

 Sub WriteByte(value As Byte)
  • value - Byte value to send.

Write a byte value to the hardware USART. If sending blocks of data, it is a good idea to check ReadyToSend before calling this routine.

WriteBoolean

 Sub WriteBoolean(value As Boolean)
  • value - Boolean value to send.

Write a Boolean value to the hardware USART. If sending blocks of data, it is a good idea to check ReadyToSend before calling this routine.

WriteUShort

 Sub WriteUShort(value As UShort)
  • value - UShort value to send.

Write a UShort value to the hardware USART. If sending blocks of data, it is a good idea to check ReadyToSend before calling this routine.

WriteUInteger

 Sub WriteUInteger(value As UInteger) 
  • value - UInteger value to send.

Write a UInteger value to the hardware USART. If sending blocks of data, it is a good idea to check ReadyToSend before calling this routine.

WriteSingle

 Sub WriteSingle(value As Single) 
  • value - Floating point number value to send.

Write a Single value to the hardware USART. If sending blocks of data, it is a good idea to check ReadyToSend before calling this routine.

Read

 Compound Sub Read(item)

Read multiple items from the hardware UART. For example:

dim myString as string
Uart.Read(myString) 

See also ReadTerminator.

Write

 Compound Sub Write(item)

Write multiple items to the hardware UART. For example:

' write some text followed by CR and LF character
Uart.Write("Hello World",13,10) 

ReadyToSend

 Function ReadyToSend() As Boolean 

Returns true if data can be sent through the serial port, false otherwise.

WaitFor

 Function WaitFor(value As Byte) As Boolean
  • value - Byte value to wait for.

Wait For a byte value to be received. Returns true if the byte received matches "value", false otherwise.

WaitForTimeout

 Function WaitForTimeout(value As Byte, timeoutMS As UShort) As Boolean
  • value - Bytes value to wait for.
  • timooutMS - Timeout values in milliseconds.

Wait for a byte value to be received, with timeout value in milliseconds. Returns true if the byte received, false if the call timed out.

WaitForCount

 Sub WaitForCount(ByRef array() As Byte, count As UShort)
  • array - Byte array to store incoming data.
  • count - Number of bytes to receive.

Wait For amount bytes to be received. The incoming data is stored in a byte array.

WaitForString

 Sub WaitForString(text As String)
  • text - String value to wait for.

Wait for a string to be received.

WaitForStringCount

 Sub WaitForStringCount(ByRef text As String, count As UShort)
  • text - String variable to received data.
  • count - Number of characters to received.

Wait for amount characters to be received. The incoming data is stored in text.

WaitForStringTimeout

 Function WaitForStringTimeout(text As String, timeoutMS As UShort) As Boolean
  • text - String variable to received the data.
  • timoutMS - Timeout value in milliseconds.

Wait for a string to be received, with timeout value in milliseconds. Returns true if the string is received, false otherwise.

DataAvailable

 Function DataAvailable() As Boolean

Checks to see if a byte value has been received.

DataAvailableTimeout

 Function DataAvailableTimeout(timeoutMS As UShort) As Boolean
  • timoutMS - Timeout value in milliseconds.

Checks to see if a byte value has been received, with timeout in milliseconds. Returns true if a byte value has been received within the specified timeout, false otherwise.

Rep

 Sub Rep(value As Byte, amount As Byte)
  • value - Byte data to be sent.
  • amount - Number of times to send the byte data.

Write a byte value, amount times.

Skip

 Sub Skip(amount As Byte)
  • amount - Number of bytes to skip.

Read and skip amount bytes of data.

Module Variables

  • RCREG - Uart receive register.
  • TXREG - Uart transmission register.
  • Overrun - True is overrun error has occurred.
  • FrameError - True if framing error has occurred.
  • ReadTerminator - identifies the line termination character for string reads.