FTC_STATUS
|
SPI_Read
|
(FTC_HANDLE ftHandle, PFTC_INIT_CONDITION pReadStartCondition, BOOL bClockOutControBitsMSBFirst, BOOL bClockOutControBitsPosEdge, DWORD dwNumControlBitsToWrite, PWriteControlByteBuffer pWriteControlBuffer, DWORD dwNumControlBytesToWrite, BOOL bClockInDataBitsMSBFirst, BOOL bClockInDataBitsPosEdge, DWORD dwNumDataBitsToRead, PReadDataByteBuffer pReadDataBuffer, LPDWORD lpdwNumDataBytesReturned, PFTC_HIGHER_OUTPUT_PINS pHighPinsReadActiveStates)
|
Parameters
ftHandle
|
Handle of the device.
|
pReadStartCondition
|
Pointer to the structure that contains the start output states (low or high) of the clock, data out and signal out/chip select pins of the FT2232C.
|
bClockOutControBitsMSBFirst
|
Clock out control bits most significant bit (MSB) first (TRUE), clock out control bits least significant bit (LSB) first (FALSE).
|
bClockOutControBitsPosEdge
|
Clock out control bits on positive clock edge (TRUE), clock out control bits on negative clock edge (FALSE).
|
dwNumControlBitsToWrite
|
Specifies the number of control bits to be written to an external device. Valid range 2 to 2040. 2040 bits is equivalent to 255 bytes.
|
pWriteControlBuffer
|
Pointer to buffer that contains the control data to be written to an external device. Listed below is an example of control and address bytes:
Control Address byte 1, Control Address byte 2 |
dwNumControlBytesToWrite
|
Specifies the number of control bytes in the write control buffer, which contains all the specified bits to be written to an external device. Valid range 1 to 255 bytes.
|
bClockInDataBitsMSBFirst
|
Clock in data bits most significant bit (MSB) first (TRUE), clock in data bits least significant bit (LSB) first (FALSE).
|
bClockInDataBitsPosEdge
|
Clock in data bits on positive clock edge (TRUE), clock in data bits on negative clock edge (FALSE).
|
dwNumDataBitsToRead
|
Specifies the number of bits to be read from an external device. Valid range 2 to 524280. 524280 bits is equivalent to 64K bytes.
|
pReadDataBuffer
|
Pointer to buffer that returns the data read from an external device. Size of buffer should be set to 65535.
|
lpdwNumDataBytesReturned
|
Pointer to a variable of type DWORD which receives the actual number of data bytes read from an external device. These bytes contain the specified number of bits read from an external device.
|
pHighPinsReadActiveStates
|
Pointer to the structure that contains which of the 4 upper general purpose input/output pins of a FT2232C, are to be used during a write to an external device. Each GPIO pin that is to be used during a read from an external device must have been previously configured as an output pin (see SPI_SetGPIOs).
|
Return Value
FTC_SUCCESS if successful, otherwise the return value is one of the following FTC error codes:
FTC_INVALID_HANDLE
FTC_NULL_INITIAL_CONDITION_BUFFER_POINTER
FTC_INVALID_NUMBER_CONTROL_BITS
FTC_NULL_WRITE_CONTROL_BUFFER_POINTER
FTC_INVALID_NUMBER_CONTROL_BYTES
FTC_NUMBER_CONTROL_BYTES_TOO_SMALL
FTC_INVALID_NUMBER_READ_DATA_BITS
FTC_NULL_READ_DATA_BUFFER_POINTER
FTC_NULL_OUTPUT_PINS_BUFFER_POINTER
FTC_INVALID_INIT_CLOCK_PIN_STATE
FTC_INVALID_FT2232C_CHIP_SELECT_PIN
FTC_INVALID_CONFIGURATION_HIGHER_GPIO_PIN
FTC_FAILED_TO_COMPLETE_COMMAND
FTC_IO_ERROR
Remarks
This function will read data from an external device to the FT2232C using the SPI protocol. The data will be clocked at a rate specified by the clock divisor set by calling either the SPI_InitDevice or SPI_SetClock functions.
The init condition, write control buffer, read data buffer and high pins read active states definitions are given in the Appendix.
Example
#define NUM_93LC56B_CMD_CONTOL_BITS 11
#define NUM_93LC56B_CMD_CONTOL_BYTES 2
#define NUM_93LC56B_CMD_DATA_BITS 16
FTC_STATUS Status = FTC_SUCCESS;
FTC_HANDLE ftHandle;
FTC_INIT_CONDITION ReadStartCondition;
WriteControlByteBuffer WriteControlBuffer;
ReadDataByteBuffer ReadDataBuffer;
DWORD dwNumDataBytesReturned = 0;
FTC_HIGHER_OUTPUT_PINS HighPinsWriteActiveStates;
ReadStartCondition.bClockPinState = false;
ReadStartCondition.bDataOutPinState = false;
ReadStartCondition.bChipSelectPinState = false;
ReadStartCondition.dwChipSelectPin = ADBUS3ChipSelect;
dwReadDataWordAddress = 0;
// set up read command and address
dwControlLocAddress1 = 192; //'\xC0';
dwControlLocAddress1 = (dwControlLocAddress1 | ((dwReadDataWordAddress / 8) & '\x0F'));
// shift left 5 bits ie make bottom 3 bits the 3 MSB's
dwControlLocAddress2 = ((dwReadDataWordAddress & '\x07') * 32);
WriteControlBuffer[0] = (dwControlLocAddress1 & '\xFF');
WriteControlBuffer[1] = (dwControlLocAddress2 & '\xFF');
Status = SPI_Read(ftHandle, &ReadStartCondition, true, false, NUM_93LC56B_CMD_CONTOL_BITS, &WriteControlBuffer, NUM_93LC56B_CMD_CONTOL_BYTES, true, false, NUM_93LC56B_CMD_DATA_BITS, &ReadDataBuffer, &dwNumDataBytesReturned, &HighPinsWriteActiveStates);