The following information explains
the chosen value for each bit:
bit0: Receive background serial
data to the scratchpad [1 = use
scratchpad]. We must use 0 because
M2 processors don’t contain a
scratchpad.
bit1: Invert serial output data [1
= negative]. We’ll use 0 [true] for
output because M2 processors must
use “true” for input. (See bit2 next.)
bit2: Invert serial input data [1 =
negative]. We must use 0 [true] for
input because M2 processors are not
able to receive inverted serial data.
bit3: Disable hserout [1 = hserout
pin is normal I/O]. We’ll use 1
[disable] because we’re not going to
use the hserout pin for that purpose.
bit4: Disable hserin [1 = hserin
pin is normal I/O]. We’ll use 0 [don’t
disable] because we’re going to use
the hserin pin for that purpose.
various special functions of the
hardware serial port. In the next
experiment, we’re going to use
%01000 for the mode parameter.
As we discussed previously, M2
processors do not have a scratchpad
storage area; instead, they use an
internal two-byte first-in first-out
(FIFO) storage buffer. A maximum of
two bytes can be received in the
background at any time — not just
when the hserin command is
executed. If more than two bytes are
received before they are processed,
the extra ones are lost.
To summarize all the above
information, the hsersetup statement
that we will use in the next
experiment is hsersetup B9600_ 8,
%01000.
Understanding the M2-
Class Hserin Command
Now that we’ve specified our
hsersetup statement, we can move on
to discussing the M2-class hserin
command. The syntax is mercifully
simple: It’s just hserin myVar, where
myVar is the variable that receives the
incoming serial data byte. However,
the question of how the incoming
background-received data byte
actually gets transferred to the
variable is a little more complicated.
Whenever an hserin command is
executed, the first byte in the buffer
is transferred to the myVar variable. If
there is a second byte in the buffer,
it’s moved up to the first position.
Finally, if the buffer is empty, the
value of myVar is not changed.
Experiment 4: Using
Hserin to Receive Serial
Data in the Background
The program for this experiment
( HserinFromPC.bas) includes the
following subroutine:
getCmd:
16 May 2015