4 spi object method: sendbyte(byte, <ss_number>) – Rainbow Electronics GM862-GPS User Manual
Page 54

Easy Script
in Python
80000ST10020a Rev.8 - 01/10/08
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved
page 54 of 100
CMD_RESET = '\xC0'
REG_ADDR_X = '\x0E' #this value is not the value for any SPI device, but for tested one only!
REG_ADDR_Y = '\x0F' #this value is not the value for any SPI device, but for tested one only!
TWO_READ_ACCESS = '\x00\x00' # string of the length equal to the number of bytes to receive
MySPI1 = SPI.new (3,10,8,6) # (SCLK, MOSI, MISO, SS0)
MySPI1.init (0,0,0,0) # (CPOL, CPHA, SSPOL, SS)
#Power Up, Reset and Clock ON routine for the SPI device can also be implemented from outside
MySPI1.readwrite (CMD_WRITE + REG_ADDR_Y + '\xAC') # write 0xAC in REG_ADDR_Y
myString = MySPI1.readwrite (CMD_READ + REG_ADDR_X, 4)
print "DATA VALUE AT ADDR_X and _Y =",hex(ord(myString[2]))+' and '+ hex(ord(myString[3]))
# values of myString [0] and myString [1] correspond to the status output while writing
myString = MySPI1.readwrite(CMD_READ + REG_ADDR_X + TWO_READ_ACCESS,4)
# does the same as previous: this is to maintain the backward compatibility with the past version of the
readwrite method
ret = MySPI1.readwrite (CMD_READ, 129) # read first byte (cmd) plus 128 bytes starting from the last
position
i = 0
print "STATUS =",hex(ord(ret[i]))
while (i < 128):
print "REGISTER[",hex(i),"]:",hex(ord(ret[i + 1]))
i = i + 1
#end of SPI example
2.9.4 SPI object method: sendbyte(byte, <SS_number>)
NOTE: We advice to use the new readwrite (2.9.3) method to send bytes or strings.
Sends a byte to the SPI bus previously created addressed for the Slave number SS_number whose
Slave Select signal is activated. Input parameter byte is a Python byte which is the byte to be sent to
the SPI bus. Optional parameter SS_number is a Python byte representing the Slave number to be
activated; if not present no slave line is activated.
Return value is a Python integer which is -1 if an error occurred otherwise is 1 the byte has been sent.
Example:
a = bus3.sendbyte(123)
sends byte 123 to the SPI bus , assigning return result value to a.