Telit Python IIC (I2C) question

I need some help, I am trying to get a TMP102 to work with my SFE GE865 eval board by means of python code. I can use the AT command method.

import MOD
import IIC
import MDM
import SER2

# set serial parameter, this is needed for the debug information on port ASC0
SER2.set_speed('115200','8N1' )
SER2.send('\r\n')
MDM.send('AT#SELINT=2\r\n',5)  # AT command interface 2

loop = 0
while(loop < 20):
    a = SER2.send('Try #' + str(loop) + '\r\n')
    a = MDM.send('AT#I2CRD=7,6,90,0,2\r\n',0)
    a = SER2.send('AT#I2CRD=7,6,90,0,2\r\n')
    res = MDM.receive(5)
    SER2.send('Response : ' + str(res) + '\r\n')
    MOD.sleep(10)
    loop = loop + 1
    
SER2.send('Done\r\n')
MDM.send('AT#SHDN\r',0)

This works fine, I get a temp back and have an MSO-19 sniffing the scl and sda lines to confirm what I’m getting.

My problem is that I am trying to do it with IIC.readwrite and only get a -1 returned from the .readwrite command. Any help would be appreciated. FYI I am very new to python (taking an online class now) so I wouldn’t be suprised if its a rookie mistake. When executing this program, I see nothing on the MSO-19. Here is the code (didn’t inlcuded module doing basic cell network registration stuff).

import IIC
import MOD
import SER2
import MDM
#import GPIO
import CELL # Requires CELL.pyo to be uploaded

status = 0

# set serial parameter, this is needed for the debug information on port ASC1
SER2.set_speed('115200','8N1' )
SER2.send('\r\n')
MDM.send('AT#SELINT=2\r\n',5)  # AT command interface 2

res = CELL.CELLULAR_init()    # Call Module CELLULAR_init in CELL.py to perform network registration report
res = CELL.CELLULAR_sim_status() # Call Module CELLULAR_sim_status in CELL.py to perform network registration report

SER2.send('Initialize GPIO pins\r\n')
I2C_SDA = 7     # GPIO used for SDA pin
I2C_SCL = 6     # GPIO used for SCL pin
I2C_ADDR = 0x90 # TMP_102 address ADD0 pin to ground

TMP_102 = IIC.new(I2C_SDA, I2C_SCL, I2C_ADDR)
status = TMP_102.init()

if (status == 1):
    a = SER2.send('TMP_102 initialization successful.\r\n')
if (status == -1):
    a = SER2.send('TMP_102 initialization failed.\r\n')

a = SER2.send('Ready to GO\r\n')
a = SER2.send('I2C_SDA:' + str(I2C_SDA) + '\r\n')
a = SER2.send('I2C_SDC:' + str(I2C_SCL) + '\r\n')
a = SER2.send('I2C_ADDR:' + str(hex(I2C_ADDR)) + '\r\n')

loop = 0

while (loop < 500):
    SER2.send('In loop ' + str(loop) + '\r\n')
    tmploop = 10

    while (tmploop > 0):
        ret = TMP_102.readwrite('\x90', 2) # Random read
        if (ret == -1):
            a = SER2.send('readwrite Error Acknowledged.\r\n')
            tmploop = tmploop -  1
        else:
            a = SER2.send('Temperature ret is ' + str(hex(ret)) + '\r\n')
            break
        
    ret = 0
    MOD.sleep(5)

    loop = loop + 1

SER2.send('Done\r\n')
MDM.send('AT#SHDN\r',0)

Thanks in advnace,

Eric

GOT IT!!!

I2C_ADDR should be 0x48 (hex 90 bitshift 1 right)

Also, str(hex(ret)) is an invalid command, so I still can’t see the value, but the MSO19 sees " 0x90, 0x0 0x91 0x16 0x20", aka “device address, I2C general call, 2 wire slave address byte, then 2 data bytes”…sweet, it is 72.5 degF (22.5degC)

So now its time to figure out how to see the hex string and/or do math.

Sometimes its good to talk things out.