p6
22-Nov-10
expandIO-USB
HW148-18
www.firmwarefactory.com
9B F0 06 01 Response – Bit set
Get Port
The identifier GETPORT (0x9C) retrieves value of a port.
Byte 1 indicates the port (A=1, B=2…). Byte 3 specifies
which bits should be set as outputs (‘0’) and which bits
should be set as inputs (‘1’). The response is the same
as the command, except the port value is given in byte 2.
Example:
9C 02 00 FF
Command – Get Port B, all inputs
9C 02 54 FF Response – Value is 0x54
Set Port
The identifier SETPORT (0x9D) sets the value of a port
output latch. Byte 1 indicates the port (A=1, B=2…).
Byte 2 specifies the new value. Byte 3 specifies which
bits should be set as outputs (‘0’) and which bits should
be set as inputs (‘1’). The response is the same as the
command.
Example:
9D 02 54 00
Command – Set Port B to 0x54
all outputs
9D 02 54 00 Response – Value set
Get Port Bit
The identifier GETPORTBIT (0x9E) retrieves a single bit
from a port. Byte 1 indicates the port (A=1, B=2…) and
byte 2 indicates the bit (0-7). Byte 3 is 0 if the bit should
be configured as an output and 1 if it should be
configured as an input. In the response, byte 3 is 0 for
clear and 1 for set.
Example:
9E 02 03 01
Command – Get Port input bit B3
9E 02 03 01 Response – Value is 0x01
Set Port Bit
The identifier SETPORTBIT (0x9F) sets or clears a
single bit of a port output latch. Byte 1 indicates the port
(A=1, B=2…) and byte 2 indicates the bit (0-7). Byte 3
bit 0 is 0 for clear and 1 for set. Byte 3 bit 1 is 0 if the bit
should be configured as an output and 1 if it should be
configured as an input. The response is the same as
the command.
9F 02 03 01
Command – Set Port bit B3 to output
0x01
9F 02 03 01 Response – Bit set
Get Analog
The identifier GETANALOG (0x96) retrieves the voltage
of an analog pin. Byte 1 bits 0-3 indicate which analog
pin (AN0 = 0, etc). Byte 1 bit 4 is 1 if AN3 should be
used as a positive voltage reference (Vref+), or Vdd /
AVdd otherwise. Byte 1 bit 5 is 1 if AN2 should be used
as a negative voltage reference (Vref-) or Vss / AVss
otherwise. In the response the analog value is in bytes
2 (MSB) and 3 (LSB). The value ranges from 0x000
(Vss / AVss / Vref-) to 0x3FF (Vdd / AVdd / Vref+).
While making the analog measurement on an analog pin,
any analog pins with index lower than the pin being
measured will temporarily enter a high-impedance state.
Example:
96 16 00 00
Command: Get AN6 using Vref+
96 16 02 36 Response: V = Vref+ * (0x236/0x3FF)
SetSerial
(18F2450, 18F4450 support UNI/O only, not SPI / I2C.)
The
identifier
SETSERIAL
(0x93)
initializes
the
synchronous serial SPI/I2C port or, from rev 0008, a
UNI/O bus.
Only one of SPI port or one I2C port can be configured.
The MSSP resource is used.
In the equations below Fo = 24MHz for expandIO-USB
and 48MHz for USB-XP.
SPI: If byte 1, bits 1 and 0 are 00, the MSSP port is
configured for SPI operation. The SDO pin shown in the
pin diagrams becomes the master output (MOSI), SDI
pin becomes the master input (MISO), and SCLK
becomes the synchronous clock.
Slave select lines
must be implemented separately using Set Port Bit
commands.
Any slave
select
lines must
be
implemented separately using the Set Port Bit command.
The data bytes are defined as follows:
Byte 1 specifies the settings for the SSPSTAT register
as follows:
Bit 7: Sample data at end (1) or middle (0) of the
clock cycle.
Bit 6: Transmit on active to idle (1) or idle to active
(0) clock transition (‘CKE’)
Other bits: Must be set to zero
Byte 2 specifies the settings for the SSPCON1 register
as follows:
Bit 5: Enable (1) or disable (0) SPI port.
Bit 4: Clock polarity: idle state is at high (1) or low
(0) level (‘CKP’)
Bits 1, 0: Clock speed is TMR22 (11), Fo64 (10),
Fo16 (01) or Fo4 (00).
Other bits: Must be set to zero
Examples:
93 80 30
Init fast Mode A (CPOL=1, CPHA = 1)
93 80 20
Init fast Mode B (CPOL=0, CPHA = 1)
93 C0 30
Init fast Mode C (CPOL=1, CPHA = 0)
93 C0 20
Init fast Mode D (CPOL=0, CPHA = 0)
In all cases the response is a repeat of the command.
UNI/O: (From rev 8) If byte 1, bits 1 and 0 are 10, the
port is configured for UNI/O operation.
Byte 2 indicates the desired bus frequency as specified
as follows:
(Bus Freq) = 3 / 2 / (Byte2)