Page 1 of 1

[MIMXRT] Hardware I2C not working with SSD1306?

Posted: Wed Dec 01, 2021 12:30 am
by Shards
I'm driving a SSD1306 board using I2C from several MIMXRT boards (Teensy 4.0 & 4.1, MIMXRT1010 & 1020). This works just fine if I use SoftI2C but fails using the Hardware I2C module. The MIMXRT1020 includes pin definitions for the I2C ports and SoftI2C can use these pins.

Code: Select all

from machine import Pin, I2C, SoftI2C

i2cS= SoftI2C(scl = 'I2C_SCL',sda = 'I2C_SDA')
print(i2cS.scan())
i2cS.start()
i2cS.stop()

i2cH= I2C(0)
print(i2cH.scan())
i2cH.start()
i2cS.stop()

This is run on a MIMXRT-1020 with the SSD1306 connected. The output is:

Code: Select all

[60]
[60]
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
OSError: I2C operation not supported
So the scan reports the same value with both I2C and SoftI2C but 'start' fails with I2C. It's no different if all the SoftI2C code is commented out and the board restarted. The program driving the screen results in the same ' OSError: I2C operation not supported ' error with I2C. Practically this isn't a problem as SoftI2C works just fine but it would be nice to know if this is a bug or I'm missing something.

This is the same on all the MIMXRT boards I've tested though I have only tested it with SSD1306 screens and not other I2C devices.

Re: [MIMXRT] Hardware I2C not working with SSD1306?

Posted: Wed Dec 01, 2021 4:11 am
by FeK9
Hi @Shards

I don't have my Teensy 4 with me at the moment to test...

I see the last line of your code is 'i2cS.stop()', maybe a miss type line 9...?

I've never used I2C start and stop as yet, I've just used the snippet of code below
to scan I2C bus shown below...

Code: Select all

from machine import I2C

# Create the I2C interface.
i2c = I2C(0)
print("I2C Address      : "+hex(i2c.scan()[0]).upper()) # Display device address
print("I2C Configuration: "+str(i2c))                   # Display I2C config

Re: [MIMXRT] Hardware I2C not working with SSD1306?

Posted: Wed Dec 01, 2021 7:18 am
by Roberthh
That's right. i2c.start() and i2c.stop() are not (yet) implemented for the hardware I2C. I can add it. Nevertheless, it is not needed for the ssd1306 display. The official driver does not use i2c.start() or i2c.stop(). See:
https://github.com/micropython/micropyt ... ssd1306.py

Re: [MIMXRT] Hardware I2C not working with SSD1306?

Posted: Wed Dec 01, 2021 1:05 pm
by Roberthh
So I looked into the MIMXRT data sheets and the MicroPython code. Different to my first assumption, it is NOT possible to implement the start() method identical to the method used by MicroPython.
Reason: In MicroPython, start() just sets the start condition on the bus. The MIMXRT I2C hardware however expects the address byte and intended communication mode to be supplied with the start command, and transmits that. There is no mode which just sets the start condition on the bus.
I do not have a SSH1306 display for testing, but I used the hardware I2c with a SSH1106 display.

Re: [MIMXRT] Hardware I2C not working with SSD1306?

Posted: Wed Dec 01, 2021 2:13 pm
by Shards
Thanks for the clarification Robert, things now make more sense.

I was apparently using an unofficial SSD1306 driver. This had a much more complex _write_data method which included both i2c.start and stop. Having tweaked the code the display now works fine with both I2C and SoftI2C.