Using SAMD21's SERCOMs with two I2C devices with the same address?

Hi all,

TL;DR: using two I2C devices, both have the same fixed address. Want to wire each to different I2C pins on my microcontroller. Will it work?

I'm using two of these tiny I2C LCD modules for a project I'm working on. These seem to have a fixed I2C address, and it's making my life a whole lot more difficult than it really needs to be. My project uses a SAMD21G17 as its brains and I've decided to use one of its handy SERCOMs to become an I2C port.

The thing is, I'm not really sure if this will work. I know two I2C devices with the same address can't exist on the same I2C bus. Adafruit seems to be implying this will work, as stated in one of their tutorials. But what I'm using here is a SERCOM port, which I guess is slightly different from a legit hardware I2C port?

Both my LCDs will have an I2C address of 0x70, but they will both be wired to different I2C pins. Will everything work out well or will there be address conflicts?

Normally I would try this out on my own, but I don't have my stuff with me at the moment. Bummer.

Thanks everyone.

Should work. The samd sercom ports support UART, spi, AND i2c, and you can repurpose any sercom to support any protocol, as long as the right pins are broken out to … board pins.

1 Like

this thread using-twowire-i2c2-with-esp32-two-pressure-sensors may give you some ideas

That isn't going to work with a SAMD21 because the SAMD21 only has one I2C bus. The ESP32 has two (wire and wire1).
The adafruit tutorial you are talking about talks about using different pins for the I2C SDA and SCL lines but not at the same time. If you only have one 12C bus you can't make more out of software.

Nope. Any of the SERCOM ports can be used for I2C, and there are 6 of them.
Not all of them end up going to pins, and some are dedicated to other uses, but you can implement more than one.
There is by default only one Wire interface in the Arduino environment, but it is not difficult to create an additional Wire1 and Wire2 (and probably two more than that if you're willing to give up Serial1 and SPI.)
The correct Adafruit Tutorial for doing this is here: Creating a new Wire | Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports | Adafruit Learning System
Similar logic can be used to make multiple additional UART ports.

It's also possible to "bit-bang" I2C on GPIO pins, entirely in software. But there shouldn't be any need on a SAMD21.

3 Likes

Thanks, your reply gives me a huge piece of mind. Now I know my project will work, as long as I can go through all the hoops that come with setting up a SERCOM port.

Yeah I've been looking into Adafruit's excellent tutorials, they're gonna be a huge help for sure.

Thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.