User Guide For LibMPSSE - SPI - FTDI

Transcription

Application NoteAN 178User Guide For libMPSSE - SPIDocument Reference No.: FT 00492Version 1.1Issue Date: 2012-02-13This application note is a guide to using the libMPSSE-SPI – a library whichsimplifies the design of firmware for interfacing to the FTDI MPSSE configuredas an SPI interface. The library is available for Windows and for Linux.Use of FTDI devices in life support and/or safety applications is entirely at the user’s risk, and theuser agrees to defend, indemnify and hold harmless FTDI from any and all damages, claims, suitsor expense resulting from such use.Future Technology Devices International Limited (FTDI)Unit 1, 2 Seaward Place, Glasgow G41 1HH, United KingdomTel.: 44 (0) 141 429 2777 Fax: 44 (0) 141 429 2758Web Site: http://ftdichip.comCopyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215Table of Contents1Introduction . 32System Overview. 53Application Programming Interface (API) . 63.1SPI Functions . 63.1.1SPI GetNumChannels . 63.1.2SPI GetChannelInfo . 63.1.3SPI OpenChannel. 73.1.4SPI InitChannel . 73.1.5SPI CloseChannel . 83.1.6SPI Read . 83.1.7SPI Write . 93.1.8SPI ReadWrite . 93.1.9SPI IsBusy . 103.1.10SPI ChangeCS. 113.2GPIO functions . 113.2.1FT WriteGPIO . 113.2.2FT ReadGPIO . 123.3Library Infrastructure Functions . 123.3.1Init libMPSSE . 123.3.2Cleanup libMPSSE . 123.4Data types . 133.4.1ChannelConfig . 133.4.2Typedefs . 154Example Circuit . 165Example Program . 176Contact Information. 24Appendix A – References . 25Document References. 25Acronyms and Abbreviations . 251Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215Appendix C – Revision History . 262Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 2151 IntroductionThe Multi Protocol Synchronous Serial Engine (MPSSE) is a generic hardware found inseveral FTDI chips that allows these chips to communicate with a synchronous serialdevice such an I2C device, a SPI device or a JTAG device. The MPSSE is currentlyavailable on the FT2232D, FT2232H, FT4232H and FT232H chips, which communicatewith a PC (or an application processor) over the USB interface. Applications on a PC oron an embedded system communicate with the MPSSE in these chips using the D2XXUSB drivers.The MPSSE takes different commands to send out data from the chips in the differentformats, namely I2C, SPI and JTAG. libMPSSE is a library that provides a user friendlyAPI that enables users to write applications to communicate with the I2C/SPI/JTAGdevices without needing to understand the MPSSE and its commands. However, if theuser wishes then he/she may try to understand the working of the MPSSE and use itfrom their applications directly by calling D2XX functions.User ApplicationlibMPSSE(SPI/I2C/JTAG Library)D2XX APIUSB Bus driverFTDI USB-to-Legacybridge chipsLegacy protocol slavedeviceFigure 1: The software and hardware stack through which legacy protocol dataflows3Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215As shown in the above figure, libMPSSE has three different APIs, one each for I2C, SPIand JTAG. This document will only describe the SPI section.The libMPSSE (Linux and Windows versions) sample code, release notes and allnecessary files can be downloaded from the FTDI website at MPSSE.htmThe sample source code contained in this application note is provided as an example andis neither guaranteed nor supported by FTDI.4Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 2152 System OverviewPC/HostFTDI ChipSPI DeviceApplicationSPI BusSCLKMOSIlibMPSSE – SPIMISOUSBCSD2XX DriverFigure 2: System organizationThe above figure shows how the components of the system will typically be organized.The PC/Host may be desktop/laptop machine or an embedded system. The FTDI chipand the SPI device would usually be on the same PCB. Though only one SPI device isshown in the figure above, up to five SPI devices can actually be connected to eachMPSSE.5Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 2153 Application Programming Interface (API)The libMPSSE-SPI APIs can be divided into two broad sets. The first set consists of sixcontrol APIs and the second set consists of two data transferring APIs. All the APIs returnan FT STATUS. This is the same FT STATUS that is defined in the D2XX driver.3.1 SPI Functions3.1.1SPI GetNumChannelsFT STATUS SPI GetNumChannels (uint32 *numChannels)This function gets the number of SPI channels that are connected to the hostsystem. The number of ports available in each of these chips is different.Parameters:out*numChannelsThe number of channels connected to the hostReturns:Returns status code of type FT STATUSNote:FTDI’s USB-to-legacy bridge chips may have multiple channels in it but not allthese channels can be configured to work as SPI masters. This function returnsthe total number of channels connected to the host system that has a MPSSEattached to it so that it may be configured as an SPI master.For example, if an FT2232D (1 MPSSE port), an FT232H (1 MPSSE port), anFT2232H (2 MPSSE ports) and an FT4232H (2 MPSSE ports) are connected to aPC, then a call to SPI GetNumChannels would return 6 in numChannels.Warning:This function should not be called from two applications or from two threads atthe same time.3.1.2SPI GetChannelInfoFT STATUS SPI GetChannelInfo (uint32 index, FT DEVICE LIST INFO NODE*chanInfo)This function takes a channel index (valid values are from 0 to the value returned bySPI GetNumChannels - 1) and provides information about the channel in the form ofa populated FT DEVICE LIST INFO NODE structure.Parameters:inindexIndex of the channelout*chanInfoPointer to FT DEVICE LIST INFO NODE structureReturns:Returns status code of type FT STATUS6Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215Note:This API could be called only after calling SPI GetNumChannels.See also:Structure definition of FT DEVICE LIST INFO NODE is in the D2XXProgrammer's Guide.Warning:the3.1.3This function should not be called from two applications or from two threads atsame time.SPI OpenChannelFT STATUS SPI OpenChannel (uint32 index, FT HANDLE *handle)This function opens the indexed channel and provides a handle to it. Valid values forthe index of channel can be from 0 to the value obtained using SPI GetNumChannels- 1).Parameters:inindexIndex of the channelouthandlePointer to the handle of type FT HANDLEReturns:Returns status code of type FT STATUSNote:Trying to open an already open channel will return an error code.3.1.4SPI InitChannelFT STATUS SPI InitChannel (FT HANDLE handle, ChannelConfig *config)This function initializes the channel and the communication parameters associatedwith it.Parameters:inhandleHandle of the channelinconfigPointer to ChannelConfig structure with the value ofclock and latency timer updatedReturns:Returns status code of type FT STATUSSee also:Structure definition of ChannelConfigNote:This function internally performs what is required to get the channel operational suchas resetting and enabling the MPSSE.7Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 004923.1.5Clearance No.: FTDI# 215SPI CloseChannelFT STATUS SPI CloseChannel (FT HANDLE handle)Closes a channel and frees all resources that were used by itParameters:inhandleoutnoneHandle of the channelReturns:Returns status code of type FT STATUS3.1.6SPI ReadFT STATUS SPI Read(FT HANDLE handle, uint8 *buffer, uint32 sizeToTransfer, uint32*sizeTransferred, uint32 transferOptions)This function reads the specified number of bits or bytes (depending on transferOptionsparameter) from an SPI slave.Parameters:inhandleHandle of the channeloutbufferPointer to the buffer where data is to be readinsizeToTransferNumber of bytes or bits to be readout*sizeTransferredPointer to variable containing the number of bytes orbits readintransferOptionsThis parameter specifies data transfer options. Thebit positions defined for each of these options are:BIT0: if set then sizeToTransfer is in bits, otherwisebytes. Bit masks defined for this bit areSPI TRANSFER OPTIONS SIZE IN BYTES andSPI TRANSFER OPTIONS SIZE IN BITSBIT1: if set then the chip select line is assertedbefore beginning the transfer. Bit mask defined forthis bit isSPI TRANSFER OPTIONS CHIPSELECT ENABLEBIT2: if set then the chip select line is disserted afterthe transfer ends. Bit mask defined for this bit isSPI TRANSFER OPTIONS CHIPSELECT DISABLEBIT3 – BIT31: reservedReturns:Returns status code of type FT STATUS8Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215Warning:This is a blocking function and will not return until either the specified amounts ofdata are read or an error is encountered.3.1.7SPI WriteFT STATUS SPI Write(FT HANDLE handle, uint8 *buffer, uint32 sizeToTransfer, uint32*sizeTransferred, uint32 transferOptions)This function writes the specified number of bits or bytes (depending on transferOptionsparameter) to a SPI slave.Parameters:inhandleHandle of the channeloutbufferPointer to the buffer from where data is to be writteninsizeToTransferNumber of bytes or bits to writeout*sizeTransferredPointer to variable containing the number of bytes orbits writtenintransferOptionsThis parameter specifies data transfer options. Thebit positions defined for each of these options are:BIT0: if set then sizeToTransfer is in bits, otherwisebytes. Bit masks defined for this bit areSPI TRANSFER OPTIONS SIZE IN BYTES andSPI TRANSFER OPTIONS SIZE IN BITSBIT1: if set then the chip select line is assertedbefore beginning the transfer. Bit mask defined forthis bit isSPI TRANSFER OPTIONS CHIPSELECT ENABLEBIT2: if set then the chip select line is disserted afterthe transfer ends. Bit mask defined for this bit isSPI TRANSFER OPTIONS CHIPSELECT DISABLEBIT3 – BIT31: reservedReturns:Returns status code of type FT STATUSWarning:This is a blocking function and will not return until either the specified amount ofdata is read or an error is encountered.3.1.8SPI ReadWriteFT STATUS SPI ReadWrite(FT HANDLE handle, uint8 *inBuffer, uint8 *outBuffer,uint32 sizeToTransfer, uint32 *sizeTransferred, uint32 transferOptions)This function reads from and writes to the SPI slave simultaneously. Meaning that,one bit is clocked in and one bit is clocked out during every clock cycle.9Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215Parameters:inhandleHandle of the channelin*inBufferPointer to buffer to which data read will bestoredoutoutBufferPointer to the buffer from where data is to bewritteninsizeToTransferNumber of bytes or bits to writeout*sizeTransferredPointer to variable containing the number ofbytes or bits writtenintransferOptionsThis parameter specifies data transfer options.The bit positions defined for each of theseoptions are:BIT0: if set then sizeToTransfer is in bits,otherwise bytes. Bit masks defined for this bitare SPI TRANSFER OPTIONS SIZE IN BYTESand SPI TRANSFER OPTIONS SIZE IN BITSBIT1: if set then the chip select line is assertedbefore beginning the transfer. Bit mask definedfor this bit isSPI TRANSFER OPTIONS CHIPSELECT ENABLEBIT2: if set then the chip select line is dissertedafter the transfer ends. Bit mask defined forthis bit isSPI TRANSFER OPTIONS CHIPSELECT DISABLEBIT3 – BIT31: reservedReturns:Returns status code of type FT STATUSWarning:This is a blocking function and will not return until either the specified amount ofdata is transferred or an error is encountered.3.1.9SPI IsBusyFT STATUS SPI IsBusy(FT HANDLE handle, bool *state)This function reads the state of the MISO line without clocking the SPI bus.Some applications need the SPI master to poll the MISO line without clocking the busto check if the SPI slave has completed previous operation and is ready for the nextoperation. This function is useful for such applications.Parameters:inhandleHandle of the channelout*statePointer to a variable to which the state of the MISO10Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215line will be readReturns:Returns status code of type FT STATUS3.1.10 SPI ChangeCSFT STATUS SPI ChangeCS(FT HANDLE handle, uint32 configOptions)This function changes the chip select line that is to be used to communicate to theSPI slave.Parameters:inhandleHandle of the channelinconfigOptionsThis parameter provides a way to select the chipselect line and the slave's SPI mode. It is the sameparameter as ConfigChannel.configOptions that ispassed to function SPI InitChannel and it isexplained in section 3.4.1Returns:Returns status code of type FT STATUS3.2 GPIO functionsEach MPSSE channel in the FTDI chips are provided with a general purpose I/O porthaving 8 lines in addition to the port that is used for synchronous serial communication.For example, the FT232H has only one MPSSE channel with two 8-bit ports, ADBUS andACBUS. Out of these, ADBUS is used for synchronous serial communications(I2C/SPI/JTAG) and ACBUS is free to be used as GPIO. The two functions describedbelow have been provided to access these GPIO lines (also called the higher byte lines ofMPSSE) that are available in various FTDI chips with MPSSEs.3.2.1FT WriteGPIOFT STATUS FT WriteGPIO(FT HANDLE handle, uint8 dir, uint8 value)This function writes to the 8 GPIO lines associated with the high byte of the MPSSEchannelParameters:inhandleHandle of the channelindirEach bit of this byte represents the direction of the 8respective GPIO lines. 0 for in and 1 for outinvalueIf the direction of a GPIO line is set to output, theneach bit of this byte represent the output logic stateof the 8 respective GPIO lines. 0 for logic low and 1for logic highReturns:Returns status code of type FT STATUS11Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 004923.2.2Clearance No.: FTDI# 215FT ReadGPIOFT STATUS FT ReadGPIO(FT HANDLE handle, uint8 *value)This function reads from the 8 GPIO lines associated with the high byte of the MPSSEchannelParameters:inhandleHandle of the channelout*valueIf the direction of a GPIO line is set to input, theneach bit of this byte represent the input logic state ofthe 8 respective GPIO lines. 0 for logic low and 1 forlogic highReturns:Returns status code of type FT STATUSNote:The direction of the GPIO line must first be set using FT WriteGPIO functionbefore this function is used.3.3 Library Infrastructure FunctionsThe two functions described in this section typically do not need to be called fromthe user applications as they are automatically called during entry/exit time.However, these functions are not called automatically when linking the librarystatically using Microsoft Visual C . It is then that they need to be calledexplicitly from the user applications. The static linking sample provided with thismanual uses a macro which checks if the code is compiled using Microsofttoolchain, if so then it automatically calls these functions.3.3.1Init libMPSSEvoid Init libMPSSE(void)Initializes the eanup libMPSSEvoid Cleanup libMPSSE(void)12Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215Cleans up resources used by the libraryParameters:innoneoutnoneReturns:void3.4 Data types3.4.1 ChannelConfigChannelConfig is a structure that holds the parameters used for initializing a channel. Thefollowing are members of the structure:uint32 ClockRateThis parameter takes the value of the clock rate of the SPI bus in hertz. Valid rangefor ClockRate is 0 to 30MHz.uint8 LatencyTimerRequired value, in milliseconds, of latency timer. Valid range is 0 – 255. However,FTDI recommend the following ranges of values for the latency timer:Range for full speed devices (FT2232D):Range 2 – 255Range for Hi-speed devices (FT232H, FT2232H, FT4232H):Range 1 - 255uint32 configOptionsBits of this member are used in the way described below:BitnumberDescriptionValueMeaning ofvalueDefined macro(if any)BIT1BIT0These bitsspecify to whichof the standardSPI modesshould the SPImaster beconfigured to00SPI MODE0SPI CONFIG OPTION MODE001SPI MODE1SPI CONFIG OPTION MODE1( Please refer to the release notes within therelease package zip file for revision history andknown limitations of this version)10SPI MODE2SPI CONFIG OPTION MODE211SPI MODE3SPI CONFIG OPTION MODE3(Please refer to the release notes within therelease package zip file for revision history andknown limitations of this version)BIT4BIT2These bitsspecify which ofthe availablelines should beused as chip000xDBUS3 ofMPSSE ischip selectSPI CONFIG OPTION CS DBUS3001xDBUS4 ofMPSSE isSPI CONFIG OPTION CS DBUS413Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492selectBIT5BIT6BIT31This bit specifiesif the chip selectline should beactive lowClearance No.: FTDI# 215chip select010xDBUS5 ofMPSSE ischip selectSPI CONFIG OPTION CS DBUS5011xDBUS6 ofMPSSE ischip selectSPI CONFIG OPTION CS DBUS6100xDBUS7 ofMPSSE ischip selectSPI CONFIG OPTION CS DBUS70Chip select isactive high1Chip select isactive lowSPI CONFIG OPTION CS ACTIVELOWReservedNote: The terms xDBUS0 – xDBUS7 corresponds to lines ADBUS0 – ADBUS7 if thefirst MPSSE channel is used, otherwise it corresponds to lines BDBUS0 – BDBUS7 ifthe second MPSSE channel(i.e. if available in the chip) is used.The SPI modes are:SPI MODE0 - data are captured on rising edge and propagated on falling edgeSPI MODE1 - data are captured on falling edge and propagated on rising edgeSPI MODE2 - data are captured on falling edge and propagated on rising edgeSPI MODE3 - data are captured on rising edge and propagated on falling edgeuint32 PinsThis member specifies the directions and values of the lines associated with the lower byte ofthe MPSSE channel after SPI InitChannel and SPI CloseChannel functions are called.Bit numberDescriptionCommentBIT7-BIT0Direction of the lines afterA 1 corresponds to outputand a 0 corresponds toinputSPI InitChannel is calledBIT15-BIT8Value of the lines afterSPI InitChannel is calledBIT23-BIT16Direction of the lines afterSPI CloseChannel is calledBIT31-BIT24Value of the lines afterSPI CloseChannel is calledA 1 corresponds to logichigh and a 0 correspondsto logic lowA 1 corresponds to outputand a 0 corresponds toinputA 1 corresponds to logichigh and a 0 correspondsto logic lowNote that the directions of the SCLK, MOSI and the specified chip select line will beoverwritten to 1 and the direction of the MISO like will be overwritten to 014Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215irrespective of the values passed by the user application. Other than these 4 lines,the rest of the lines will be an a state that is specified via this parameter.uint16 reservedThis parameter is reserved and should not be used.3.4.2 TypedefsFollowing are the typedefs that have been defined keeping cross platform portability ypedefunsigned char uint8unsigned short uint16unsigned long uint32signed char int8signed short int16signed long int32unsigned char bool15Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 2154 Example CircuitThis example will demonstrate how to connect a MPSSE chip (FT2232H) to an SPI device (93LC56B– EEPROM) and program it using libMPSSE-SPI library.Figure 3: Schematic for connecting FT2232H to SPI EEPROM device (93LC56B)The above schematic shows how to connect a FT2232H chip to an SPI EEPROM. Pleasenote that the FT2232H chip is also available as a module which contains all thecomponents shown in the above schematic (except the 93LC56B and the pull-upresistors connected to it). This module is called FT2232H Mini Module and details about itcan be found in the device datasheet. The FT2232H chip acts as the SPI master here andis connected to a PC running using USB interface.16Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 2155 Example ProgramThe required D2XX driver should be installed into the system depending on the OS thatis already installed in the PC/host. If a linux PC is used then the default drivers usbserialand ftdi sio must be removed (using rmmod command).Once the hardware shown above is connected to a PC and the drivers are installed, wecan place the following sample code (sample-static.c), D2XX.h, libMPSSE spi.h andlibMPSSE.a into one folder, compile the sample and run it./*!* \file sample-static.c** \author FTDI* \date 20110512** Copyright 2011 Future Technology Devices International Limited* Company Confidential** Project: libMPSSE* Module: SPI Sample Application - Interfacing 94LC56B SPI EEPROM** Rivision History:* 0.1 - 20110512 - Initial version* 0.2 - 20110801 - Changed LatencyTimer to 255*Attempt to open channel only if available*Added & modified macros*Included stdlib.h* 0.3 - 20111212 - Added ***************************************//*Include ************************************//* Standard C libraries */#include stdio.h #include stdlib.h /* OS specific libraries */#ifdef WIN32#include windows.h #endif/* Include D2XX header*/#include "ftd2xx.h"/* Include libMPSSE header */#include "libMPSSE ***********************************//*Macro and type **************************************//* Helper macros */#define APP CHECK STATUS(exp) {if(exp! FT OK){printf("%s:%d:%s(): status(0x%x) \! FT OK\n", FILE , LINE , FUNCTION ,exp);exit(1);}else{;}};#define CHECK NULL(exp){if(exp NULL){printf("%s:%d:%s(): NULL expression \encountered \n", FILE , LINE , FUNCTION );exit(1);}else{;}};/* Application specific macro definations */#define SPI DEVICE BUFFER SIZE25617Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492#define SPI WRITE COMPLETION RETRY#define START ADDRESS EEPROM#define END ADDRESS EEPROM#define RETRY COUNT EEPROM#define CHANNEL TO OPEN#define SPI SLAVE 0#define SPI SLAVE 1#define SPI SLAVE 2#define DATA OFFSETClearance No.: FTDI# 215100x00 /*read/write start address inside the EEPROM*/0x1010/* number of retries if read/write fails */0/*0 for first available channel, 1 for next. ***********************************//*Global ****************************************/uint32 channels;FT HANDLE ftHandle;ChannelConfig channelConf;uint8 buffer[SPI DEVICE BUFFER ***********************************//*Public function ******************************************//*!* \brief Writes to EEPROM** This function writes a byte to a specified address within the 93LC56B EEPROM** \param[in] slaveAddress Address of the I2C slave (EEPROM)* \param[in] registerAddress Address of the memory location inside the slave to where the byte*is to be written* \param[in] data The byte that is to be written* \return Returns status code of type FT STATUS(see D2XX Programmer's Guide)* \sa Datasheet of 93LC56B 794F.pdf* \note* \warning*/FT STATUS read byte(uint8 slaveAddress, uint8 address, uint16 *data){uint32 sizeToTransfer 0;uint32 sizeTransfered;bool writeComplete 0;uint32 retry 0;bool state;FT STATUS status;/* CS High Write command Address */sizeToTransfer 1;sizeTransfered 0;buffer[0] 0xC0;/* Write command (3bits)*/buffer[0] buffer[0] ( ( address 3) & 0x0F );/*5 most significant add bits*/status SPI Write(ftHandle, buffer, sizeToTransfer, &sizeTransfered,SPI TRANSFER OPTIONS SIZE IN BYTES SPI TRANSFER OPTIONS CHIPSELECT ENABLE);APP CHECK STATUS(status);/*Write partial address bits */sizeToTransfer 4;sizeTransfered 0;buffer[0] ( address & 0x07 ) 5; /* least significant 3 address bits */status SPI Write(ftHandle, buffer, sizeToTransfer, &sizeTransfered,SPI TRANSFER OPTIONS SIZE IN BITS);APP CHECK STATUS(status);/*Read 2 bytes*/sizeToTransfer 2;sizeTransfered 0;status SPI Read(ftHandle, buffer, sizeToTransfer, &sizeTransfered,18Copyright 2011 Future Technology Devices International Limited

Application NoteAN 178 Programming Guide for libMPSSE - SPIVersion 1.1Document Reference No.: FT 00492Clearance No.: FTDI# 215SPI TRANSFER OPTIONS SIZE IN BYTES SPI TRANSFER OPTIONS CHIPSELECT DISABLE);APP CHECK STATUS(status);*data (uint16)(buffer[1] 8);*data (*data & 0xFF00) (0x00FF & (uint16)buffer

3.1 SPI Functions 3.1.1 SPI_GetNumChannels FT_STATUS SPI_GetNumChannels (uint32 *numChannels) This function gets the number of SPI channels that are connected to the host system. The number of ports available in each of these chips is different. Parameters: out *numChannels The number of channels connected to the host Returns: