Read bytes sent by a SPI master
Description:
This is a 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, countarray, dataarray )
The USBm_SPISlaveRead function syntax has these parts:
Part | Description |
device | A zero-based index to address the appropriate USB device. |
countarray | An array of the count of bytes sent by the SPI master. Minimum array size of 1. |
dataarray | The function causes this array of variables to be changed to the data received from the SPI transfer. Minimum array size of 6. |
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 countarray As Byte, _ ByRef dataarray As Byte) _ As Integer |
VB Example
Dim dataarray(6) As Byte Dim countarray(1) As Byte USBm_SPISlaveRead 6, countarray(0), dataarray(0) |
Reading a countarray(0) 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 Prototype
int USBm_SPISlaveRead( unsigned char device, unsigned char *count, unsigned char *data ); |
C Example
RobotBASIC
usbm_SPISlaveRead(ne_DeviceNumber)
Returns a string of byte data from the Slave buffer (maximum 6 bytes). You can use the ArrayStr() function to extract the individual bytes.
Raw Command Format:
Byte Number | Description |
0 | 17h: SPISlaveCmd |
1 | <not used> |
2 | <not used> |
3 | <not used> |
4 | <not used> |
5 | <not used> |
6 | <not used> |
7 | <not used> |
Raw Command Format Details:
Byte 1 through byte 7 are unused.
Raw Command Response Format:
Byte Number | Description |
0 | 17h: SPISlaveCmd |
1 | Byte Count |
2 | Byte Data |
3 | Byte Data |
4 | Byte Data |
5 | Byte Data |
6 | Byte Data |
7 | Byte Data |
Raw Command Response Format Details:
Byte 0 contains the command. Byte 1 contains the count of bytes sent by the SPI master. Byte 2 through byte 7 contain the data from the master SPI device.
Raw Command Example Usage:
Reading 17-00-01-02-03-04-05-06 from the SPI buffer indicates that the master has transferred no data. Reading 17-02-01-02-03-04-05-06 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⁄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.