Maple Reference Documentation

# Maple Reference Documentation: USART

- Hardware/Circuit Design
- Compatible Devices and Specifications
- Function Reference

## Hardware/Circuit Design

The Maple has 3 seperate USART devices: Serial1, Serial2, and Serial3. In the most simple use case the RX and TX pins are used to send data at a predetermined baudrate with the the line voltage level relative to ground.

Port | Function | Pin
--- | --- | ---
Serial1 | TX RX CK | D7 D8 D6
Serial2 | TX RX CK CTS RTS | D1 D0 D10 D2 D3
Serial3 | TX RX CK CTS RTS | D29 D30 D31 D32 D33

## Compatible Devices and Specifications

We have successfully used the Maple USART ports with an FT232R-based USB-serial converter at up to 115200 baud; higher speeds should certainly be possible.

## Function Reference

In the following replace "SerialN" with Serial1, Serial2, or Serial3.

`SerialN.begin(baudrate)`
  `begin()` is usually called in `setup()` to configure the baudrate of the given serial port and to set up the header pins appropriately. It can be called at any time to reconfigure a port or to change the baudrate. 9600 baud is the generic speed most widely supported by other devices and terminals.
`SerialN.print(...)`
`SerialN.println(...)`
  Writes data into the port buffer to be transmitted as soon as possible. Accepts strings (character arrays). If a raw integer is passed the corresponding ASCII character will be transmitted; to print out a number in human readable form add a second parameter with the base system. Eg, to print out the decimal number '1234' use print(1234,DEC); to print out the binary numner '1001' use print(9,BIN).
`SerialN.available()`
`SerialN.read()`
  `read()` will return any data that has been recieved over the port and `available()` will tell if any such data acutally exists, and if so how many bytes. If there is no data `read()` will block/fail, so the usual program structure is to poll with `available()` and only `read()` if there's something ready.

## Recommended Reading

- Wikipedia article on Universal asynchronous receiver/transmitter (USART)
- Arduino reference on Serial
- STMicro documentation for STM32F103RB microcontroller:
  - All
  - Datasheet (pdf)
  - Reference Manual (pdf)

### About this Document

A more recent version of this document may be available from the LeafLabs website. Our documentation is versioned on github; you can track changes to the master branch at this link.

This documentation is released under a Creative Commons Attribution-Share Alike 3.0 license.

Translations are welcomed; give us a ping to make sure we aren't in the process of revising or editing first.