public interface SpiMaster
FDI SPI master support library
Example (Single Read Write)
-----------------------------------------
FTDevice mFTDevice0 = m_pFtD2xx.openByIndex(m_pActivity, 0, params);
if(mFTDevice0 != null)
{
mFT4222Device0 = new FT_4222_Device(mFTDevice0);
mFT4222Device0.init();
mFT4222Device0.setClock((byte)FT4222_ClockRate.SYS_CLK_80); //80 MHZ
mSPIMaster = m_FT4222Device0.getSpiMasterDevice();
mSPIMaster.init(FT4222_SPIMode.SPI_IO_SINGLE, FT4222_SPIClock.CLK_DIV_4, FT4222_SPICPOL.CLK_ACTIVE_LOW, FT4222_SPICPHA.CLK_LEADING, 1);
mSPIMaster.singleReadWrite(rd_buf, wr_buf, wr_buf.length, sizeTransferred, false);
}
Example (Multi Read Write)
-----------------------------------------
mFTDevice0 = m_pFtD2xx.openByIndex(m_pActivity, 0, params);
if(mFTDevice0 != null)
{
mFT4222Device0 = new FT_4222_Device(mFTDevice0);
mFT4222Device0.init();
mFT4222Device0.setClock((byte)FT4222_ClockRate.SYS_CLK_80); //80 MHZ
mSPIMaster = mFT4222Device0.getSpiMasterDevice();
mSPIMaster.init(FT4222_SPIMode.SPI_IO_SINGLE, FT4222_SPIClock.CLK_DIV_4, FT4222_SPICPOL.CLK_ACTIVE_LOW, FT4222_SPICPHA.CLK_LEADING, 1);
FT_4222_Spi_Master ft4222_spi_ext = (FT_4222_Spi_Master) mSPIMaster;
if(ft4222_spi_ext != null)
ft4222_spi_ext.setDrivingStrength(SPI_DrivingStrength.DS_8MA, SPI_DrivingStrength.DS_8MA, SPI_DrivingStrength.DS_8MA);
mSPIMaster.setLines(FT4222_SPIMode.SPI_IO_QUAD);
byte[] readBuffer = new byte[32];
int [] sizeOfRead = new int[1];
ftStatus = mSPIMaster.multiReadWrite(readBuffer, eeCmd, 1, 6, readBuffer.length, sizeOfRead);
}
Modifier and Type | Method and Description |
---|---|
int |
init(int ioLine,
int clock,
int cpol,
int cpha,
byte ssoMap)
Initialize FT4222H as an SPI master.
|
int |
multiReadWrite(byte[] readBuffer,
byte[] writeBuffer,
int singleWriteBytes,
int multiWriteBytes,
int multiReadBytes,
int[] sizeOfRead)
Under SPI dual or quad mode, write data to and read data from an SPI slave.
|
int |
reset()
Reset the SPI master or slave device.
|
int |
setLines(int spiMode)
Switch FT4222H SPI master to single, dual, or quad lines.
|
int |
singleRead(byte[] readBuffer,
int sizeToTransfer,
int[] sizeOfRead,
boolean isEndTransaction)
Under SPI single mode, read data from an SPI slave.
|
int |
singleReadWrite(byte[] readBuffer,
byte[] writeBuffer,
int sizeToTransfer,
int[] sizeTransferred,
boolean isEndTransaction)
Under SPI single mode, full-duplex write data to and read data from an SPI slave.
|
int |
singleWrite(byte[] writeBuffer,
int sizeToTransfer,
int[] sizeTransferred,
boolean isEndTransaction)
Under SPI single mode, write data to an SPI slave.
|
int init(int ioLine, int clock, int cpol, int cpha, byte ssoMap)
ioLine
- SPI transmission linesclock
- Clock dividercpol
- Clock polaritycpha
- Clock phasessoMap
- Slave selection output pinsint reset()
int setLines(int spiMode)
spiMode
- SPI mode could be: SPI_IO_SINGLE , SPI_IO_DUAL, SPI_IO_QUADint singleWrite(byte[] writeBuffer, int sizeToTransfer, int[] sizeTransferred, boolean isEndTransaction)
writeBuffer
- buffer that contains the data to be written to the device.sizeToTransfer
- The size of read and write buffer. They must be the same.sizeTransferred
- Pointer to a variable of type uint16 which receives the number of bytes read and written to the device.isEndTransaction
- TRUE to raise the pin of SS at the end of the transactionint singleRead(byte[] readBuffer, int sizeToTransfer, int[] sizeOfRead, boolean isEndTransaction)
readBuffer
- buffer that receives the data from the devicesizeToTransfer
- The size of read and write buffer. They must be the same.sizeTransferred
- Pointer to a variable of type uint16 which receives the number of bytes read and written to the device.isEndTransaction
- TRUE to raise the pin of SS at the end of the transactionint singleReadWrite(byte[] readBuffer, byte[] writeBuffer, int sizeToTransfer, int[] sizeTransferred, boolean isEndTransaction)
readBuffer
- buffer that receives the data from the devicewriteBuffer
- buffer that contains the data to be written to the device.sizeToTransfer
- The size of read and write buffer. They must be the same.sizeTransferred
- Pointer to a variable of type uint16 which receives the number of bytes read and written to the device.isEndTransaction
- TRUE to raise the pin of SS at the end of the transactionint multiReadWrite(byte[] readBuffer, byte[] writeBuffer, int singleWriteBytes, int multiWriteBytes, int multiReadBytes, int[] sizeOfRead)
readBuffer
- buffer that receives the data from the device.writeBuffer
- buffer that contains the data to be written to the device. .singleWriteBytes
- number of bytes in writeBuffer will be written as single-line.multiWriteBytes
- number of bytes in writeBuffer will be written as multi-line.multiReadBytes
- number of bytes to read as multi-line.sizeOfRead
- number of bytes read from the device.