![]() ZBasic System Library
97
ZBasic Microcontrollers
Type
Subroutine
Invocation
DefineCom(channel, rxPin, txPin, flags)
DefineCom(channel, rxPin, txPin, flags, stopBits)
Parameter
Method
Type
Description
channel
ByVal
Byte
The serial channel being defined.
rxPin
ByVal
Byte
The pin which will serve as the receive line.
txPin
ByVal
Byte
The pin which will serve as the transmit line.
flags
ByVal
Byte
Configuration flags. See the discussion below.
stopBits
ByVal
Byte
The desired number of stop bits.
Discussion
This routine configures a serial channel, preparing it to be opened using OpenCom(). This routine may
be called with the channel parameter specifiying either a hardware UART channel (1, 2 and 7-12) or a
software UART channel (3-6). If the specified channel is already open, this routine does nothing.
Likewise, there is no effect if the specified channel is invalid or if either of the rxPin and txPin
parameters is invalid for the target device or the specified serial channel.
Hardware Channels
For hardware UART channels the rxPin and txPin parameters are meaningless and, therefore,
ignored. By default, a hardware channel is opened in 8 data bits, no parity, 1 stop bit mode (sometimes
referred to as 8-N-1), the most common serial format. Unless you want configure a hardware channel for
a different mode it is not necessary to call DefineCom() before opening the channel. Specifying a value
for the optional stopBits parameter that is greater than 1 will select 2 stop bits; otherwise, the default of
1 stop bit is used. Note that some of the bits in the flags parameter are ignored for hardware channels
as indicated by shaded entries in the table below.
Software Channels
For software UART channels, either of the rxPin and txPin parameters (but not both) may be zero
allowing you to define a transmit-only or receive-only serial. If the two parameter values are different, the
specified pins are automatically configured as input and output, respectively. As a special case, the
rxPin and txPin parameters may specify the same pin and the pin is initially configured as an input to
support half-duplex, bussed operation. In this mode, the the pin will be made an output when transmitting
a zero bit if configured for non-inverted operation or when transmitting a one bit if configured for inverted
operation. A pull-up resistor (non-inverted mode) or pull-down resistor (inverted mode) is required for
bussed operation since the pin will only be actively driven in one of the two output states.
If the optional stopBits parameter is not specified, one stop bit is transmitted for each character sent.
Otherwise, the specified number of stop bits is transmitted. The allowable range for stopBits is 1 to
240. If a value outside this range is specified, the default of 1 stop bit will be used. The ability to specify
two or more stop bits is useful for slowing down the transmission of data in cases where the receiver
needs additional time to process received data.
Configuration Flags
The flags parameter contains several bit fields used to specify some of the details of the operation of
the serial channel. Note, however, that some of the bits are applicable only to software UART channels.
|