Is the MCP23017 the best choice for many dozens of devices running in parallel ?

Hi all,
Hoping someone can point me in the right direction here.

I am thinking of running a great many devices using multiple MPC23017's. (A hundred or so)

They need 3 wires to run. 2 to control the steps and 1 is feedback.
Just on off. No PWM required.

At the moment I have 16 running really well on a MEGA2650 using almost all the IO.
But now I have run out of outputs so I need to expand the output using the MPC23017 ? maybe ?

Are there other IO expanders people like/prefer (preferably with libraries).

Needs to be fairly quick, and I see that this chip is so will probably be the one if nobody has any other "You MUST use this one" ideas :slight_smile:

Thanks guys.

Because of the addresses available on the MCP23017 chips only 8 can be on the I2C bus without multiplexing.

8x16 = 128 are there any other chips that are popular and or have libraries available ?

You can use the Address lines as chip selects.
Pull all three pins high.
On one device, pull one pin low and send I2C commands only for that one address.
The other 99 will be looking for the address of all pins high and will stay off the bus.

100 devices on the I2C bus will be a lot of capacitance that will play havoc on signal edges, so you'll probably want to break them into smaller groups with some buffering as well.

nixnay:
I am thinking of running a great many devices

Which devices exactly?

There are many more options for port extension, but without knowing what you're driving we can't give sensible advice.

CrossRoads:
You can use the Address lines as chip selects.
Pull all three pins high.
On one device, pull one pin low and send I2C commands only for that one address.
The other 99 will be looking for the address of all pins high and will stay off the bus.

Sounds like this solution may need a few port extenders to be able to select the port extenders...

You can use the Address lines as chip selects.
Pull all three pins high.
On one device, pull one pin low and send I2C commands only for that one address.
The other 99 will be looking for the address of all pins high and will stay off the bus.

Great stuff and a big help in pointing me in the right direction.
A little google and I found this with your help.

From this article.

The solution

Suddenly, an idea came to my mind. Why not use I²C just like SPI - with a chip select? I²C devices don't have a chip select pin, but the address select pin. Why hardwire it to VCC or GND, just hook it up to a GPIO on your microcontroller. There, you select all of them with the same address, the address with the pin tied to ground - and the software controls which one that is. Only the one with the address pin pulled low will activate, the others have the address pin high and therefore listen to another address. Actually that means there are several chips with the same address, but as long as the controller only talks to the device with the address pin pulled low, there won't be any interference.

100 devices on the I2C bus will be a lot of capacitance that will play havoc on signal edges, so you'll probably want to break them into smaller groups with some buffering as well.


Interesting. Even with very short buss lengths, under 500mm ?
Not at all familiar with the I2C bus spec really.
I did find this.

From here. https://www.ti.com/lit/an/slyt770/slyt770.pdf?ts=1617083837580

. Since bus capacitance and pullup resistors directly influence rise times, rise-time issues can typically be resolved by using a stronger pullup resistor (meaning one with a lower resistance value). The I2C protocol dictates the maximum allowed rise times based on the maximum clock frequency used. In version 2.6 of the I2C specification, the maximum rise time for standard mode and fast mode is 1,000 ns and 300 ns, respectively.

Very useful post CrossRoads . Thank you very much.

P.S. I just found this article too.

I2C bus splitters (multiplexing) is a thing :slight_smile: Great!

Holy hand grenade.
Just how far can you go.

https://mindbleach.com/words/2012/10/23/i2c-and-device-limits/

wvmarle:
Sounds like this solution may need a few port extenders to be able to select the port extenders...

Yes. What a rabbit hole I am digging here.
Probably best to start breadboarding up the 128 to start with and seeing how that goes.
Perhaps by also splitting 64 onto another section with the chip select idea and see what that does to performance.

Each of SDA and SCL will have capacitance associated with the trace from the bus thru the package leads down to the chip and from the input protection circuit and finally the input receive transistors and output drive transistors.
Multiply that by 100, and it adds up.

nixnay:
Yes. What a rabbit hole I am digging here.

now if you tell us WHAT you're trying to drive exactly we may be able to give other, possibly better solutions... shift registers come to mind, or a set of PCF8575...

You also have to consider distances as well as the timing requirements of the devices you are driving. Are these devices going to be grouped closely together?

I agree that you should say what these devices are to get the most relevant suggestions.

Thanks guys. I have enough information to make me dangerous.
I can't say what it is other than I can run it at over 10kHz and it's not physical (like a motor etc), if that helps.

No, other than raising red flags (asking for free advice on what's probably yet another top secret new form of world domination), and at 10 kHz no chance using the I2C bus (just do the math).

wvmarle:
No, other than raising red flags (asking for free advice on what's probably yet another top secret new form of world domination), and at 10 kHz no chance using the I2C bus (just do the math).

Lol's. No it's just an idea I have that's all. No world domination required.

Don't quite know what you are on about with red flags to be honest.

I am not going to run it at 10kHz I just mentioned that the device can run at that speed. That's all.

I get it, It's hard to really specify a projects direction without a full spec.

Unfortunately I am not in a position to provide one at this stage.

Just looking for general project guidance. Specific advice not required.

I think CrossRoads has given me the nudge I needed though (even with out a full spec) and I am loving that idea about address Lines as chip selects. Gold.

Though, now that multiplexing has been suggested, I will look at breadboarding that to see if it is a solution.

And thanks too for the heads up about capacitance issues. Will look carefully into that also.

You also have to consider distances as well as the timing requirements of the devices you are driving. Are these devices going to be grouped closely together?

Yup. All good points thanks. In general terms this is all going to be less than a 500mm run for all devices and close together.

I have developed my own switch mode power supply for this that is quite slow at around 100kHz so will be looking around for interference on all the lines.

As it is, it does buzz a bit as it is flyback and a little annoying so can move that up a tad I guess with the help of LTSpice.

Thanks again all.

CrossRoads:
Each of SDA and SCL will have capacitance associated with the trace from the bus thru the package leads down to the chip and from the input protection circuit and finally the input receive transistors and output drive transistors.
Multiply that by 100, and it adds up.

Humm somehow I skimmed over this.
So shorter narrower tracks.
No flying leads.
Adjustments to risetime with changing pullup resistors.

Ok... I have a lot to consider here. I see. You are a literal mine of information Sir/Ma'am
Great general project advice and just what I am looking for. Thank you once again.

Not ever having had more than 3 or 4 devices on a bus before I had not really taken this into consideration but now that you point it out it's very possible that this could be an issue.

Quick google is getting me up to speed here.

Even more gold for those reading along at home.
https://www.ti.com/lit/an/scpa054/scpa054.pdf?ts=1617174190835&ref_url=https%253A%252F%252Fwww.google.com%252F

From the article above.

Suppose an I 2C system using Fast Mode has 40 slave devices, which adds 10 pF per slave, a master device that adds 10 pF, and a PCB trace that adds 200 pF of capacitance, see Figure 8. The total capacitance on that bus is equal to 610 pF, which exceeds the max bus capacitance (CBUS MAX) specification that is outlined in the I 2C standard for Fast Mode operation.

Even More useful information. Why does the device type even matter ? The general principles are all similar are they not ?

Well... since nobody was dead set against the MCP23017 and there IS a library for it.
8 of these on the way to start the party.

Will report back on how much fun was had.

I'd have probably used the DIP versions instead of the breakout board. However, the only problem you might encounter is that that breakout appears to have an I2C pullup resistor set on each board. 8 lots of 10k in parallel may get a bit strong so you may have to unsolder some.

But, anyway, have fun experimenting with this project.

If all that's needed is either outputs or inputs shift registers would be the way to go... way faster, no address selection issues, far cheaper.

wvmarle:
If all that's needed is either outputs or inputs shift registers would be the way to go... way faster, no address selection issues, far cheaper.

You know I think you may actually be right here. Sometimes I tend to overthink things.

I have no need of the interrupts after all. Just a shedtonne of shift registers.

The code will be harder though as you mentioned in this post of yours some time ago.
Keeping track of it all would be "problematic" no ?

And, I do like "very easy to control".

Shift registers being cheaper is only by a small margin in the scheme of things. (my scheme of things).
The MCP23017 is pretty cheap after all at around $1.70 per vs the 74HC595 @ around $0.50.

The I2C port extenders such as PCF8574 and MCP23017 work very much like the internal pins: input, output, internal pull-up resistor, and with the libraries that exist for them allow you to read/set each pin individually. Two pins control up to 128 I/O. Very easy to control.

Shift registers are input only or output only depending on the type (the 595 is output), and you have to do more work in code to keep track of all the pins and very time write them all at the same time. Three pins control virtually unlimited inputs or outputs; limits are mostly practical

Shift registers are cheaper and faster.

6v6gt:
I'd have probably used the DIP versions instead of the breakout board. However, the only problem you might encounter is that that breakout appears to have an I2C pullup resistor set on each board. 8 lots of 10k in parallel may get a bit strong so you may have to unsolder some.

But, anyway, have fun experimenting with this project.

Roger, Hot air gun at the ready. Cheers.