ClearCore Library
SerialDriver COM Ports

Overview

For applications that require sending or receiving data over a serial port ClearCore provides two COM ports (COM-0 and COM-1). The COM ports may be interfaced-with using the SerialDriver class.
In code, these connectors are represented by ConnectorCOM0 and ConnectorCOM1.

For UART communications the SerialDrivers may have their operational mode configured to facilitate either TTL or RS-232 wiring schemes. For SPI communications there is an SPI mode. The SerialDriver
connectors also have an auxiliary mode called CCIO. This mode is used to connect to the ClearCore I/O Expansion Board (CCIO-8) which provides eight additional digital I/O points.

Wiring and Initialization

RS-232/TTL Modes

RS-232 and TTL (UART) modes use one wire (Rx) for receiving and another wire (Tx) for transmitting serial data asynchronously at a pre-determined baud rate. These modes are identical except that
the signals used are inverted. Data frames are signaled by the use of start and stop bits of opposite polarity. The number of stop bits in a data frame is 1 by default, but may be set to 2.
Transmission parity may also be configured, but is turned off by default. For each mode, flow control may optionally be enabled to make use of the RTS and CTS lines.

// Configure COM-1 for TTL mode.
// Set the data baud rate.
// Open the serial port to enable data transmission.
// Configure COM-0 for RS-232 mode.
// Set the data baud rate.
// (Optional) Set the data frame parity.
// (Optional) Set each data frame to use 2 stop bits.
// (Optional) Enable flow control.
// Open the serial port to enable data transmission.

Once the port is open use Send() to output characters or numeric data to the serial port. Use SendLine() to send data appended with carriage return and newline characters.

// Output some data to COM-0.
ConnectorCOM0.Send("Hello, ");

To halt serial communications close the port using the SerialDriver::PortClose() function. Once the port is closed data will no longer be received by or transmitted from the serial port.
The port will only start receiving input again when it is re-opened.

// Close COM-0 to end serial communications.

SPI Mode

SPI (Serial Peripheral Interface) is a synchronous data transfer protocol; besides lines for transmitting and receiving data there is also a dedicated clock (SCK) to synchronize transfers. With
the ClearCore acting as an SPI master device the MOSI (Master Out, Slave In) line is analogous to the Tx signal, while the MISO (Master In, Slave Out) line is analogous to the Rx signal in
RS-232/TTL modes. As in RS-232/TTL modes, the speed of data transfers is set by the Speed() function. The difference is that in SPI there are no start or stop bits since data transfer is
synchronized using the clock signal. The polarity of the SPI clock can be configured to be idle low (default) or idle high. The SPI clock's phase may be configured so that data is sampled on a
falling edge and shifted out on a rising edge (default) or vice versa.

// Configure COM-0 for SPI mode.
// Set the clock frequency / data transfer rate.
// Set the SPI clock polarity and phase to match the target device.
// Open the serial port to enable data transmission.

Toggle the Slave Select line to send to or receive data from the connected SPI device.

// Assert the Slave Select line to begin data transfer.
// Receive up to 100 bytes of data from the connected SPI device.
uint8_t received[100] = {0};
ConnectorCOM0.SpiTransferData(nullptr, received, 100);
// De-assert the Slave Select line to end data transfer.

To halt serial communications close the port using the SerialDriver::PortClose() function. Once the port is closed, data will no longer be received by or transmitted from the serial port.
The port will only start receiving input again when it is re-opened.

// Close COM-0 to end serial communications.

CCIO-8 Mode

Both SerialDriver ports may be configured for communications with up to eight ClearCore I/O Expansion Boards (CCIO-8). The operations of the attached CCIO-8 boards will be controlled by
ClearCore's CcioBoardManager, but the initial port setup is controlled by the SerialDriver functions.

// Set the mode of COM-0 to control the attached CCIO-8 boards.
// Open the serial port in CCIO-8 mode.

The CcioBoardManager controls closing down of the CCIO-8 link and its associated serial port.

// Close down the CCIO-8 link when we're done.
CcioMgr.LinkClose();