Start Back Next End
  
ZBasic System Library
275
ZBasic Microcontrollers
SerialGetByte
Type
Function returning Byte
Invocation
SerialGetByte(inAddr, mask, loopCnt, flags, delayCnt)
SerialGetByte(inAddr, mask, loopCnt, flags)
SerialGetByte(inAddr, mask, loopCnt)
Parameter
Method
Type
Description
inAddr
ByVal
integral
The address of the input register of a port.
bitMask
ByVal
Byte
A bit mask for the input pin of the port.
loopCnt
ByVal
integral
The loop count to effect the baud rate.
flags
ByVal
Byte
Flag bits controlling the reception process.
delayCnt
ByVal
integral
The delay count to effect the start of sampling.
Discussion
This function reads a byte, transmitted in 8-N-1 serial form (8 data bits, no parity, 1 stop bit) via a pin.  It is
intended to be called from a routine (e.g. an ISR) that has detected the presence of the start bit.
The pin, assumed to be configured as an input, is specified by giving the address of the input register of
the port containing the pin (inAddr) and a bit mask containing a single 1 bit corresponding to the bit
position in the port (bitMask).  The loopCnt parameter controls the timing of the bit window sampling,
specifying a number of 4-cycle loops to delay for each iteration.  Note that, in addition to the delay loop,
there is an 11-cycle loop overhead that must be taken into account.  Consequently, the total number of
cycles between each sample is 11 + loopCnt * 4.
The flags parameter allows control of some aspects of the reception process.  The table below
describes the meaning of the fields.  If the flags parameter is omitted, zero is assumed.
Flag Parameter Values
Function
Hex Value
Bit Mask
Non-inverted Logic
&H00
xxxx xxx0
Inverted Logic
&H01
xxxx xxx1
 
The remaining bits are currently undefined but may be used in the future.  For compatibility with new
functionality that may be added in the future, the unused bits should always be zero.
If the delayCnt parameter is specified, it gives the number of 4-cycle loops to execute before beginning
sampling; this allows for adjusting the beginning of the sampling cycle which should optimally begin in the
approximate middle of the start bit.  The actual delay from entry to the first sample is approximately  16 +
delayCnt * 4.  For diagnostic purposes, you may configure a pin to be an output and then specify that pin
as the read strobe pin using the compiler directive Option SerialReadStrobe.  Immediately before taking
the first sample (the start bit) the pin's state will be toggled.  Observing this signal transition and its
position relative to the center of the start bit can provide information to adjust the delayCnt parameter.  It
should be noted that the toggling operation adds 3 more cycles before the first sample.
Compatibility
This function is not available in BasicX compatibility mode nor on VM-based devices.
See Also
Previous page Top Next page