Online Development Notebook > Index > ODN > USBm DLL Programming > Device Commands > SPISlaveRead

SPISlaveRead


Description:

This is a USBm.dll function that transfers bytes from the slave SPI buffer. This buffer holds the data transferred from the master SPI device, when that device sends data. A maximum of six bytes will fit in this buffer.

 

Command Syntax: (USBm.dll)

USBm_SPISlaveRead(device, count, data)

The USBm_SPISlaveRead function syntax has these parts:

Part Description
device A zero-based index to address the appropriate USB device.
count The count of bytes sent by the SPI master.
data The function causes these variables to be changed to the data received from the SPI transfer.

 

Remarks:

Reading count = 00h from the SPI buffer indicates that the master has transferred no data. Reading count = 02h indicates that the master SPI device has transferred 2 bytes of valid data.

Port A bit 4 (pin 19 for the U401, pin 24 for the U421) has a special purpose when the U401 is used in SPI slave mode. The pin becomes an input when the U401 is configured to ba a slave. The function of the pin is "SS", an active low slave select. SS behaves much like the slave selects (or chip selects) of SPI devices (an EEPROM, for example). Initializing the SPI subsystem also takes care of setting the port direction for the SPI pins. The SPI initialization should come after the port direction init. The master SPI device should select the U401 by bringing this line low.

 

VB Declaration

Public Declare Function USBm_SPISlaveRead _
    Lib "USBm.dll" _
        (ByVal device As Byte, _
        ByRef count As Byte, _
        ByRef data As Byte) _
    As Integer

 

VB Example

Dim dataarray(6) As Byte
Dim bytecount As Byte

    USBm_SPISlaveRead 6, bytecount, dataarray(0)

Reading a bytecount of 0 from the SPI buffer indicates that the master has transferred no data.

Port A bit 4 (pin 19 for the U401) has a special purpose when the U4x1 is used in SPI slave mode. The pin becomes an input when the U4x1 is configured to ba a slave. The function of the pin is "SS", an active low slave select. SS behaves much like the slave selects (or chip selects) of SPI devices (an EEPROM, for example). Initializing the SPI subsystem also takes care of setting the port direction for the SPI pins. The SPI initialization should come after the port direction init. The master SPI device should select the U4x1 by bringing this line low.

C Example

-TBD-


Hardware:  U401 USB Interface    U421 USB Interface
Programming:  USBm DLL Programming    Download Files
Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ