beautypg.com

Rainbow Electronics GM862-GPS User Manual

Page 53

background image





Easy Script

in Python

80000ST10020a Rev.8 - 01/10/08

Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved

page 53 of 100

Example:

status = mySPIobject.init(0, 0, 0)
In this initialization no SS line is defined as default, and no SS line will be moved if not set in readwrite
function.

status = mySPIobject.init(0, 0, 0, 1)
In this initialization the SS=1 refers to the use of SS1, already defined in SPI.new(6, 7, 8, 9, 10) as
GPIO10.

status = mySPIobject.init(0, 0, 0, 0)
In this initialization the SS=0 refers to the use of SS0, already defined in SPI.new(6, 7, 8, 9, 10) as
GPIO9.

2.9.3 SPI object method: readwrite(string, , )

This command sends string and receives read_len bytes at the same time from SPI bus device at
Slave Select line number SS.
First input parameter string is a Python string while the second optional

18

parameter read_len is a

Python integer used only for reading data and can assume values in the range from 0 to 254.

The third optional input parameter SS, if defined, selects which of SS line number defined in SPI.new
will be used and, if not defined, the default Slave Select line number

in SPI.init, if any, will be used.


Return value is a Python string that contains (read_len bytes) of sent and/or received data, in case an
error occurs return value will be –1 or NULL if is memory error.

Example:

myString = mySPIobject.readwrite(‘hello’, 10)

send the string "hello" and receives a string of 10 bytes from the SPI device, assigning it to myString


Example of writing and reading of a memory in a particular SPI device (addressable by a Slave Select
pin)

#start of SPI example
import SPI
import MOD
import MDM
import GPIO

CMD_WRITE = '\x02'

#this value is not the value for any SPI device, but for tested one only!

CMD_READ = '\x03'

#this value is not the value for any SPI device, but for tested one only!

18

In case of read operation this parameter is obligatory