Python IIC question

2 thoughts on “Python IIC question



        i have a GE864-GPS module and i am attmeping to program a MAC9867 audio codec.  It works using the following AT commands however it seems to fail when i try to program via python.


    Here is the AT commands that work.


            > 00101000A40A330000330C0C09092424400060<ctrlZ>




            > 8A<ctrlZ>



    I tried to replicate this in python using the IIC module however it fails when it tries to write. I suspect it has something to do with the slave write and read addresses. Any help would be greatly apprecated.



    Python code…. 

            I2C_SDA = 8 # GPIO for SDA pin
            I2C_SCL = 7 # GPIO for SCL pin 
            I2C_WR = 0x30 # MAX9867 slave write address
            I2C_RD = 0x31 # MAX9867 slave read address
  "creating IIC bus")
            write =, I2C_SCL, I2C_WR)
            #set DVI interface
  "setting DVI")
            MDM.send("AT#DVI=1,1,0r", 2)
            success, ans = SMS.waitForOK(5)
            if success:
      "doing write init")
                BUSstatus = write.init()
                if BUSstatus == -1:
                    return -1
                # set the codec registers start at 4
                # see included codec config documentation for explanation
      "Doing register config")
                    if write.readwrite(‘x04x00x10x10x00xA4x0Ax33x00x00x33x0Cx0Cx09x09x24x24x40x00x60’, 0) == -1:
                        LOG.error("register write failed")
                        return -1
                except Exception,e:
      "Register config done")
                # turning on codec
      "turning on codec")
                if write.readwrite(‘x17x8A’, 0) == -1:
                   LOG.error("power on failed")
                   return -1

            return 0 


    1. Hi Robi,


      I believe the problem could be in how the register address has to be write..

      In the py module readwrite the  addr wrote via the function is automatically shifted to left by 1 and theLSB bit isset to 0 or 1 to perform a read or a write.

      So try to change the code as below:


      I2C_WR = 0x18  # MAX9867 address shifted right by 1