9 spi built-in module – Rainbow Electronics GM862-GPS User Manual
Page 51

Easy Script
in Python
80000ST10020a Rev.8 - 01/10/08
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved
page 51 of 100
2.9 SPI built-in module
SPI built-in module
17
is an implementation on the Python core of the SPI bus Master using the "bit-
banging" technique. You need to use SPI built-in module if you want to create one or more SPI bus on
the available GPIO pins.
This SPI bus handling module is mapped on creation on three or more GPIO pins that will become the
Serial Data In/Out and Serial Clock pins of the bus, plus a number of optional chip select pins up to 8.
It can be created more than one SPI bus over different pins and these pins must not be used for other
purposes.
NOTE: Python core does not verify if the pins are already used for other purposes (IIC module or
GPIO module) by other functions, it's the customer responsibility to ensure that no conflict over pins
occurs.
If you want to use SPI built-in module you need to import it first:
import SPI
the functions to use are: create your SPI object (new), initialize (init) and transfer data (readwrite) like
in the example:
mySPIobject = SPI.new(3, 4 ,5, 6)
mySPIobject.init(0, 0, 0, 0)
d = mySPIobject.readwrite(’test’, 4)
sends 'test' and receives byte from the SPI bus device.
More details about SPI built-in module object methods are in the following paragraphs.
2.9.1 SPI.new(SCLK_pin, MOSI_pin, MISO_pin,
This command creates a new SPI bus object on the corresponding GPIO pins. Input parameter
SCLK_pin, MOSI_pin and MISO_pin are Python bytes that represent the GPIO pin number where the
SCLK (Serial CLocK), MOSI (Master Output Slave Input), MISO (Master Input Slave Output) lines are
mapped.
Input parameter SSi_line is a mandatory Python byte if the SPI device needs to be selected by Slave
Select line: it is the GPIO pin number where the SSi (i
th
Slave Select) line is mapped. Up to 8 Slave
Select lines can be defined.
17
Note: SPI module cannot be simulated in Python Win