Device::FTDI::SPI - use an FTDI chip to talk the SPI protocol


This subclass of Device::FTDI::MPSSE provides helpers around the basic MPSSE to fully implement the SPI protocol.



    $spi = Device::FTDI::SPI->new( %args )

In addition to the arguments taken by "new" in Device::FTDI::MPSSE, this constructor also accepts:

mode => INT

The required SPI mode. Should be 0, 1, 2, or 3.

wordsize => INT

The required wordsize. Values up to 32 are supported.

clock_rate => INT

Sets the initial value of the bit clock rate; as per "set_clock_rate".


Any of the following methods documented with a trailing ->get call return Future instances.


    $i2c->set_clock_rate( $rate )->get

Sets the clock rate for data transfers, in units of bits per second.


    $spi->set_spi_mode( $mode )->get

Sets the current SPI mode. This will affect the clock sense and the idle state of the CLK pin.


    $spi->set_wordsize( $bits )->get

Sets the number of bits per word, used by the "write", "read" and "readwrite" methods. Normally, this value is 8 but it may be set anywhere between 1 and 32.

When set to a value smaller than 8, only the least significant bits of each word are used.

When set to a value greater than 8, the string values operated on will consist of wide characters, having codepoints greater than 255. Care should be taken not to treat these strings as Unicode text strings, as in general the values they contain may not be compatible with Unicode.





Set the SS GPIO pin to LOW or HIGH state respectively. Normally these methods would not be required, as "read", "write" and "readwrite" perform these steps automatically. However, they may be useful when combined with the $no_ss argument to split an SPI transaction over multiple method calls.


    $spi->write( $words, $no_ss )->get


    $words = $spi->read( $len, $no_ss )->get;


    $words_in = $spi->readwrite( $words_out, $no_ss )->get;

Performs a full SPI write, or read-and-write operation, consisting of asserting the SS pin, transferring bytes, and deasserting it again.

If the optional $no_ss argument is true, then the SS pin will not be adjusted. This is useful for combining multiple write or read operations into one SPI transaction.

If the wordsize is set to a value other than 8, the actual serial transfer is achieved by first reshaping the outbound data into 8-bit bytes with optionally a final bitmode transfer of between 1 and 7 bits, and reshaping inbound 8-bit bytes with this final bitmode transfer back into the required shape to be returned to the caller.


Paul Evans <>