8 iic built-in module, 1 iic.new(sda_pin, scl_pin, ) – Rainbow Electronics GM862-GPS User Manual
Page 46

Easy Script
in Python
80000ST10020a Rev.8 - 01/10/08
Reproduction forbidden without Telit Communications S.p.A. written authorization - All Rights Reserved
page 46 of 100
2.8 IIC built-in module
IIC built-in module
14
is an implementation on the Python core of the IIC bus
15
Master (No Multi-Master)
using the "bit-banging" technique.
You need to use IIC built-in module if you want to create one or more IIC bus on the available GPIO
pins. This IIC bus handling module is mapped on creation on two GPIO pins that will become the
Serial Data and Serial Clock pins of the bus. It can be created more than one IIC bus over different
pins and the pins used must not be used for other purposes.
NOTE: Python core does not verify if the pins are already used for other purposes (SPI 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 IIC built-in module you need to import it first:
import IIC
then you can create the new bus over the GPIO pins (for example over the pins GPIO3, GPIO4) and
then use IIC built-in module methods like in the following example:
IICbus = IIC.new(3, 4, 0x50)
IICbus.init()
res = IICbus.readwrite('test', 10)
which sends 'test' and receives a string of 10 bytes from IIC bus device at address 0x50, assigning it
to res.
NOTE: you must provide external pull-up on SDA line since the line is working as open collector, on
the other hand SCLK is driven with a complete push pull.
More details about IIC built-in module object methods are in the following paragraphs.
2.8.1 IIC.new(SDA_pin, SCL_pin,
This command creates a new IIC bus object on the GPIO pins number. Input parameter SDA_pin,
SCL_pin are Python bytes, which are the GPIO pin number where the SDA (Serial Data) and SCL
(Serial Clock) lines are mapped. Optional parameter ADDR is the address of IIC bus device.
Return value is the Python custom IIC bus object pointer, which then shall be used to interface with
the IIC bus created.
Example:
myIIC1 = IIC.new(3,4,0x50)
14
Note: IIC module cannot be simulated in Python Win
15
With the following clock frequency: 0KHz min, 20KHz typical (idle mode)