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

SPISlaveWrite


Description:

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

 

Command Syntax: (USBm.dll)

USBm_SPISlaveWrite(device, index, data)

The USBm_SPISlaveWrite function syntax has these parts:

Part Description
device A zero-based index to address the appropriate USB device.
index Index to the data. A value of 0 indicates that the first buffer byte will be the first byte read by the master.
data The function will transmit this information to the SPI master device when commanded by that device.

 

Remarks:

When the U4xx is operated as a slave device, an external master can read the data placed into the SPI buffer. If 11, 22, 33, 44, 55, 66 is written to the SPI buffer, then the master can read the first buffer byte (11h) when it transfers a byte to the U401. The second SPI master transfer will read 22h.

Port A bit 4 (pin 19 for the U401) 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_SPISlaveWrite _
    Lib "USBm.dll" _
        (ByVal device As Byte, _
        ByVal index As Byte, _
        ByRef data As Byte) _
    As Integer

 

VB Example

Dim dataarray(6) As Byte
    dataarray(0) = &H11
    dataarray(1) = &H22
    dataarray(2) = &H33
    dataarray(3) = &H44
    dataarray(4) = &H55
    dataarray(5) = &H66

    USBm_SPISlaveWrite 6, 0, dataarray(0)

When the U4xx is operated as a slave device, an external master can read the data placed into the SPI buffer. If this finction is called to write to the SPI buffer, then the master can read the first buffer byte (11h) when it transfers a byte to the U4xx. The second SPI master transfer will read 22h.

Port A bit 4 (pin 19 for the U401, pin 24 for the U421) 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