Using the QuickUSB Library
SPI-Compatible Port
The QuickUSB module implements a ‘soft’ SPI port using pins on port E and
optionally port A. These routines support from 1 to 10 devices with individual
slave select lines for each device. The slave select lines are active low and are
shown in
Table 7 - QuickUSB Pin Definitions
. The signals are MOSI, SCK, MISO
and nSS0-9. By default, data is shifted in and out MSbit to LSbit. The bit shift
order can be configured by changing Bit 0 of the
setting.
The SPI bus runs at approximately 500Kbps. You can learn more about
QuickUSB’s SPI interface in the
section of this document.
QuickUsbReadSpi
Purpose
Read a block of bytes from the specified SPI slave port.
Parameters
hDevice: A HANDLE that was returned from a call to QuickUsbOpen.
portNum: The SPI device address (nSS line) to read from.
data:
A pointer to a buffer in which to place the received data.
length:
A pointer to the number of bytes to read. The maximum length
is 64 bytes.
Returns
A non-zero value if successful, 0 otherwise. In addition, the data buffer is
filled with the received data and the length is set to the number of bytes
actually received on success. Both data and length are left unchanged if
the function failed.
Notes
This function applies a logic low (0) to the MOSI port while reading in the
data.
QuickUsbWriteSpi
Purpose
Write a block of bytes to the specified SPI slave port.
Parameters
hDevice: A HANDLE that was returned from a call to QuickUsbOpen.
portNum: The SPI device address (nSS line) to write to.
data:
A pointer to the data to send.
length:
The number of bytes to send. The maximum length is 64 bytes.
Returns
A non-zero value if successful, 0 otherwise.
Notes
This function ignores data received at the MISO pin while writing. If you
need to capture MISO data while writing, you should use the
function.
68
SPI-Compatible Port