ClearCore Library
|
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.
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.
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.
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.
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.
Toggle the Slave Select line to send to or receive data from the connected SPI device.
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.
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.
The CcioBoardManager controls closing down of the CCIO-8 link and its associated serial port.