Online Development Notebook > Index > Programming Overview > Device Commands > SPISlaveWrite

SPISlaveWrite - Write bytes for a SPI master to read


Description:

This is a 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, dataarray )

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.
dataarray The function will transmit this array to the SPI master device when commanded by that device. Minimum array size of 6.

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 dataarray 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 Prototype

int USBm_SPISlaveWrite( unsigned char device, unsigned char index, unsigned char *data );

C Example

 


RobotBASIC

usbm_SPISlaveWrite(ne_DeviceNumber,se_DataBytes)

Returns true if successfull, false otherwise. Writes 1 to 6 bytes to the SPI slave buffer. The length of the data string determines the number of bytes written. Use Char() to create the data string.


Raw Command  Format:

Byte Number Description
0 16h: SPISlaveCmd
1 Data Index (0-5)
2 Byte Data
3 Byte Data
4 Byte Data
5 Byte Data
6 Byte Data
7 Byte Data

Raw Command  Format Details:

Byte 0 contains the command. Byte 1 is the index to the data. A value of 0 indicates that the first buffer byte, at location 2, will be the first byte read by the master. Byte 2 through byte 7 contain the data to be read by the SPI master.

Raw Command Response Format:

Byte Number Description
0 16h: SPISlaveCmd
1 <not used>
2 <not used>
3 <not used>
4 <not used>
5 <not used>
6 <not used>
7 <not used>

Raw Command Response Format Details:

Byte 0 contains the command. Byte 1 through byte 7 are unused.

Raw Command Example Usage:

When the U4xx is operated as a slave device, an external master can read the data placed into the SPI buffer. If 16-00-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, pin 24 for the U421) has a special purpose when the U401⁄U421 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 U4x1 by bringing this line low.


Hardware:  U401 USB Interface    U421 USB Interface   U451 USB Interface

Programming:  USBm DLL Programming    Download Files

Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ

While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.

USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.

Copyright © USBmicro, L.L.C., 2002-2010

Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 76 of 126)

This page is created with TreePad