Skip to content
alexanderhiam edited this page Dec 8, 2012 · 2 revisions

SPI, or Serial Peripheral Interface, is a standard of synchronous serial communication (Wikipedia:SPI). These functions provide a software implementation.

Functions:

shiftIn(data_pin, clk_pin, bit_order, n_bits=8, edge=FALLING)

Receives the given number of bits from a slave device, generating the clock signal on clk_pin and reading data from data_pin, and returns as an integer. bit_order sets the endianess of the data, and should be either MSBFIRST or LSBFIRST. edge is the edge which triggers the device to write the next bit.

shiftOut(data_pin, clk_pin, bit_order, data, edge=FALLING)

Sends the given data to the slave, generating the clock signal on clk_pin and reading data from data_pin. bit_order sets the endianess of the data, and should be either MSBFIRST or LSBFIRST. edge is the edge which triggers the device to write the next bit.


In shiftOut(), data can be of type string or int, or can be a list containing any combination of strings and ints. Any value with more than one byte will be shifted out with the same byte-endianess as the given bit-endianess. Lists will be iterated in that order as well, e.g.

shiftOut(data_pin, clk_pin, MSBFIRST, ['a', 'bc', ['d', 'e']])

will send the same data as

shiftOut(data_pin, clk_pin, MSBFIRST, 'abcde')
Clone this wiki locally