Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Lopy4 I2C trouble [OSError: I2C bus error]

    Scheduled Pinned Locked Moved Firmware
    buglopy
    9 Posts 4 Posters 2.3k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E Offline
      Eric73
      last edited by

      Hi , i have a small trouble with i2c and Lopy4
      my firmware version is MicroPython v1.8.6-849-83e2f7f on 2018-03-19; LoPy4 with ESP32
      I have several slaves on one I2C bus and only one on the second i2c bus
      When i work with one instance of i2c with several slave all work fine, but if i initialize a second instance i2c of first instance fail to work and return OSError: I2C bus error
      Sorry for my english, it's not my native language, some code will be help to understood
      Any idea to deal with this bug ? I have misunderstood how i2c work on lopy
      ?

      from machine import I2C
      from machine import Timer
      import utime
      import PCA9534 as Slio
      import zonemgt as Heating
      import LM73 as Thermal
      import SSD1306 as Screen
      import MCP7940 as Rtc
      
      #I2C0 for  SSD1306, LM73, and MCP7940
      i2c=I2C(0)
      i2c.init(I2C.MASTER,baudrate=400000)
      
      Screen.initialize(Screen.kDisplayI2C128x64,i2c)     #<-work fine
      Rtc.init(i2c)                                   #<-work fine, rtc is read on set to correct time
      Temperature=Thermal.read_temp(i2c)              #<-work temperature is read from sensor
      print("Rtc init done")
      print("Thermal="+str(Temperature))
      Rtc.init(i2c)                                  #<-still working fine
      
      i2c_slio=I2C(1)
      i2c_slio.init(I2C.MASTER, pins=('P23','P22'),baudrate=400000)
      
      Rtc.init(i2c)                #<- any access to I2C0 slave fail with OSError, here with Rtc but LM73 or SSD1306 cannot be read/write all i2c0 function fail 
      
      
      E 1 Reply Last reply Reply Quote 0
      • E Offline
        Eric73 @Eric73
        last edited by

        A simplier code that everibody can run will show similar behaviour

        from machine import I2C
        
        i2c=I2C(0)
        i2c.init(I2C.MASTER,baudrate=400000)
        slave=i2c.scan()    #<- show slave list
        print(str(slave))
        slave=i2c.scan()    #<-show slave list
        print(str(slave))
        
        i2c_slio=I2C(1)
        i2c_slio.init(I2C.MASTER, pins=('P23','P22'),baudrate=400000)
        slave=i2c_slio.scan() #<-show slave list
        print(str(slave))
        
        slave=i2c.scan()   #<- board stucked in infinite loop, REPL is no more responsive to command
        print(str(slave))
        
        robert-hhR X P 3 Replies Last reply Reply Quote 0
        • robert-hhR Offline
          robert-hh @Eric73
          last edited by

          @eric73 P23 is used also for the SD card. Maybe that is the reason for your trouble.

          E 1 Reply Last reply Reply Quote 0
          • E Offline
            Eric73 @robert-hh
            last edited by

            @robert-hh Thank for your answer, i will specify my hardware setting, i have designed a custom board hosting my lopy4.
            So on P23 there's no sd-card i only wiil used it as i2c signal. In fact, when i used it as i2c-p23, it work fine for i2c communication (i can scan and read write for my slave).
            The "bug" is after i call init function for I2C(1) i cannot still use I2C(0) communication on default pins (P9-P10) (scan will run in endless loop and read or write function cause an os-error).
            I seem that i can't use simultaneously the both I2C instance ?

            1 Reply Last reply Reply Quote 0
            • X Offline
              Xykon administrators @Eric73
              last edited by

              @eric73 Can you try the code like this please?

              from machine import I2C
              
              i2c=I2C(0, mode=I2C.MASTER,baudrate=400000)
              slave=i2c.scan()    #<- show slave list
              print(str(slave))
              slave=i2c.scan()    #<-show slave list
              print(str(slave))
              
              i2c_slio=I2C(1, mode=I2C.MASTER, pins=('P23','P22'),baudrate=400000)
              slave=i2c_slio.scan() #<-show slave list
              print(str(slave))
              
              slave=i2c.scan()   #<- board stucked in infinite loop, REPL is no more responsive to command
              print(str(slave))
              

              Please let me know if this works better otherwise I'll set up some hardware to test this further...

              Christian Ehlers

              E 1 Reply Last reply Reply Quote 0
              • E Offline
                Eric73 @Xykon
                last edited by

                @xykon Thank for your feedback, unfortunatly i can't test this code before 15th may , i will post you a result at this date (i have a lot of holliday to finish before end of may and i don't come back at work before 15th may).

                I think you don't need any hardware to test this behaviour, just having the programm terminating is a good think as actually it's stuck in infinite loop in latest

                slave=i2c.scan()
                
                X 1 Reply Last reply Reply Quote 0
                • X Offline
                  Xykon administrators @Eric73
                  last edited by

                  @eric73 I think the reason it gets stuck is because when you run i2c_slio=I2C(1) you assign I2C bus 1 to the default gpio pins. Now I2C bus 0 no longer has any pins assigned to it and that's why the scan is never ending.

                  Either way I'll get a notification if there are any updates here so let me know when you have a chance to test this.

                  Christian Ehlers

                  E 1 Reply Last reply Reply Quote 0
                  • E Offline
                    Eric73 @Xykon
                    last edited by

                    @xykon Thank you very much, your explanation make sense, now my software works !

                    1 Reply Last reply Reply Quote 1
                    • P Offline
                      prashanth @Eric73
                      last edited by

                      @Eric73 Thank you. It helped me

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom