Start Back Next End
  
ZBasic System Library
100
ZBasic Microcontrollers
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.
Serial Channel Configuration Flag Values
Function
Hex Value
Bit Mask
Inverted Logic¹
&H80
1x xx xxxx
Non-inverted Logic
&H00
0x xx xxxx
Ignore Parity Bit
&H40
x1 xx xxxx
Store Parity Bit
&H00
x0 xx xxxx
Even Parity
&H30
xx 11 xxxx
Odd Parity
&H20
xx 10 xxxx
No Parity
&H00
xx 00 xxxx
5-bit Data²
&H05
xx xx 0101
6-bit Data²
&H06
xx xx 0110
7-bit Data
&H07
xx xx 0111
8-bit Data
&H08
xx xx 1000
7-bit Data, bussed mode¹
&H0b
xx xx 1011
8-bit Data, bussed mode¹
&H0c
xx xx 1100
   ¹ Applicable only to software-based channels (3-6).
   ² Applicable only to hardware-based channels (1, 2, 7 and up).
The remaining bit values are currently undefined but may be employed in the future.
When Non-inverted Logic is selected, the idle state of the transmit line will be logic 1.  When a character
transmission is begun, a “start bit” of logic zero will be sent for one bit time (the inverse of the baud rate). 
Next the data bits are sent, each for one bit time, beginning with the least significant bit and continuing
through the eighth data bit or parity bit as the case may be.  Finally, one or more “stop bits” of logic one
are sent, each for one bit time.  With Inverted Logic, each of these elements is complemented – the idle
state of the transmit line is logic 0.
Whether you should choose the inverted or non-inverted mode depends on the device that you intend to
communicate with and how many, if any, level converters exist between the two devices.  Typically, if the
other device is capable of sending and receiving TTL-level serial data, you’ll likely choose non-inverted
Logic.
If the “Ignore Parity” flag is asserted, in 7-bit mode the most significant bit of each character received will
be zero and in 8-bit mode only one byte will be stored in the queue for each character received.  If the
“Ignore Parity” bit is not asserted, in 7-bit mode the MSB will contain the received parity bit and in 8-bit
mode a second byte containing the parity bit will be stored in the queue for each character received.  The
ParityCheck() function is useful for checking the parity of a received character.
The software UART channels support a bussed mode where the transmit pin is actively driven only during
logic zero periods (low for non-inverted mode, high for inverted mode).  This mode, selected by using the
special values shown in the table above for 7-bit and 8-bit data widths (i.e., the normal values augmented
by 4), is useful for having multiple devices driving the same transmit line.  This mode is commonly
referred to as open drain (non-inverted mode) or open source (inverted mode) operation and requires a
pullup resistor (non-inverted mode) or a pulldown resistor (inverted mode) on the common transmit line in
order to establish the proper logic level when the line is not being actively driven by any device.
Note that a pullup resistor (non-inverted mode) or a pulldown resistor (inverted mode) is recommended
on the transmit line to force the transmit line to the idle state prior to the time your program initializes the
COM port.  If you don’t do this, the receiving device may see false transmissions prior to the first
character actually transmitted.  Depending on what other circuitry is connected to the receive line, you
may need to do the same to prevent the ZBasic device from receiving false transmissions.
Example
Call ComChannels(2, 9600)
Call DefineCom(4, 0, 12, &H08)
Previous page Top Next page