85 of 323
ZBasic System Library 75 ZX Microcontroller Family 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 (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. For a software UART channel, 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. 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 ZX from receiving false transmissions. This subroutine may be used to specify the data width, parity mode and stop bits for a hardware UART channel (e.g. Com1) provided that it is called when the channel is closed. When used this way, the txPin and rxPin parameters are ignored and values of 2 or more for the stopBits parameter will select 2 stop bits. Also, the flag for inverted data mode is likewise ignored. Example Call ComChannels(2, 9600) Call DefineCom(4, 0, 12, &H08) This call prepares channel 4 for transmit-only using pin 12, eight data bits, no parity and non-inverted logic. Compatibility This function is not available in BasicX compatibility mode; you must use DefineCom3(). Additionally, BasicX does not support 8-bit plus parity modes nor does it support the “Strip Parity” mode. Furthermore, in BasicX characters received in 7-bit/no parity mode are aligned toward the MSB while in this implementation they are properly aligned toward the LSB. For mega32-based ZX devices (e.g. the ZX-24), the ability to define the characteristics of Com1 is not supported nor is half-duplex bussed mode. Specifying the same pin for rx and tx on these devices will produce undefined results. See Also ComChannels, ControlCom, OpenCom, StatusCom