How to link 2x MCP23017 together ?

Thread Starter

q12x

Joined Sep 25, 2015
1,690
Now, the big question... - How to link 2x MCP23017 together?

[MODERATION: This and six other messages were moved here from another thread because the discussion of this topic had split between them. There may appear to be some discontinuity where those messages are in the timeline, this is the reason. This is less confusing than two completely different threads. Sorry for the potential confusion]
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
I have 10x MCP23017 and I want to link 8 of them together. I'm stumbled on the hardware point.
For the moment I will have to figure out how to link 2 of them together.
For now, I managed 1 to make it work using arduino. But I am using power from arduino that is also powered from USB. And is not good.
I want to avoid using everything from usb. I want a secondary PSU that will power all 8x MCP23017's and all their test leds.
My best guess, is to link together both grounds, from external PSU and from arduino. I didnt try it yet, better patient than stupid. But i'll go stupid in the end if no answers will come.
And after the hardware part is made, then the software from arduino... another brick in the wall to get it out.
I foresee a long day ahead.
 

Ian0

Joined Aug 7, 2020
9,814
The software part is easy. Linking multiple devices together is what the A0/A1/A2 pins are for. The devices responds to the address that is 0b0100-A2-A1-A0, so all you have to do is set the A0-A2 pins to all 8 possible combinations, then you have 8 uniquely addressable devices.

For the power supply, use a separate power supply for the MCP23017 part of the circuit, and link the 0V connection to the 0V of the arduino power supply.
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
And I already got in hero mode and connected all 3 ground together. And is working excellent. I remember I did actually something similar in the past but it was long time ago and I was unsure if I remember it right. It appears I do.
Now I see I got a similar answer. Super. Thank you mister @Ian0 !
I also made the circuit as well in this time:
MCP23017-with-arduino and external PSU.jpg
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
Mister @Ian0 , Thank you, but from where to where I connect those A2-A1-A0 ? from 1 MCP A0 to another MCP A0?
And the Serial data must be linked together I assume, right? Those A2-A1-A0 are input only from the arrow marker on their pins, I learn to pay attention to this detail on all microchip devices.
Something like this?
Is this correct?
(feel very free to draw on top of my sketch here)
MCP23017-series connections copy 1.jpg
 
Last edited:

Ya’akov

Joined Jan 27, 2019
9,150
Now, the big question... - How to link 2x MCP23017 together?
You don’t want to hook them together. The A0-A2 pins are I²C address select. it lets you assign 3 bit addresses to the devices on the I²C bus. Set each to a unique address and you can choose whichever you need to talk to.

In your application there not interactions of outputs and inputs involved, they just share the bus.
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
I made the second circuit with the second MCP on it and I am trying to figure out the connections I have to make.
It appears from my experiments so far that linking all those serial pins SCL and SDA together, is a bad idea.
Now Im trying every permutations possible because there is no clear circuit anywhere how to actually connect those A0-A1-A2.
This is how I imagine it should be...so far.
MCP23017-series connections.jpg
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
Those connections are not good.
I just made them and nothing works.
Maybe from INTA to A0? and then from INTB to A1? But what will go to A2? it's a mystery.... I will try it this way then.
These are the wiring so far but it didnt work
MCP23017-series connections.jpg
 

Ya’akov

Joined Jan 27, 2019
9,150
Look at the datasheet if you want everything about the chip.

A0-A2 are not hooked to anything other than Vcc or 0V. The pins set 3 bits for an address:

000
001
010
011
100
101
110
111

This allows 8 of the devices to live together on the I²C bus. You don’t need connections among and outputs or inputs on each to each other. You do need to make the I²C bus common. What problem do you have with putting more than one on the bus?
 

Ya’akov

Joined Jan 27, 2019
9,150
Those connections are not good.
I just made them and nothing works.
Maybe from INTA to A0? and then from INTB to A1? But what will go to A2? it's a mystery.... I will try it this way then.
A0-A2 are either pulled up to Vdd of down to 0V. They do not have any other function. They only set an address and do not change based on any activity of your circuit.
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
Aha.... ok, then I will redraw the circuit based on your explanations and you tell me after I show it to you if is good or bad.
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
to @Jon Chandler so when I will have to put all 8, Ill have to add a 3.3V also? holy caramboly.
thanks for the clarification, I think I get it now.
I will make a new updated circuit now. Oau... this is more complicated than I imagined...
 

AlbertHall

Joined Jun 4, 2014
12,346
Each of those three pins should be connected to either VSS or VDD. There are eight different combinations that can be made to give different addresses to eight devices on the bus.

A0 A1 A2
0 0 0
1 0 0
0 1 0
1 1 0
0 0 1
...........
And so on to:
1 1 1
 

Ya’akov

Joined Jan 27, 2019
9,150
to @Jon Chandler so when I will have to put all 8, Ill have to add a 3.3V also? holy caramboly.
thanks for the clarification, I think I get it now.
I will make a new updated circuit now. Oau... this is more complicated than I imagined...
Do you understand what is going on?

This is exactly like having a three position DIP switch to select a device address. It's 3 bits and in the software you have to choose one of the 3 bit addresses to talk to that device. so 0x20 has 8 I/O channels, 0x21 has 8 others, etc.
 

Thread Starter

q12x

Joined Sep 25, 2015
1,690
I didnt know you can move one thread inside another, Very cool that you can do that, very modular, very smart !!!
Is no problem from my part. Indeed I was on the problem and I wanted some faster answers. I do push sometimes. Sorry for the mess, but now is cleaned, which is nice.
So for the 2 IC's I have right now, I have to make A2=0V, A1=0V,A0=3.3V (as logical 1) and it corresponds to address 0x21.
So this is looking more like a hardware programming to me...
And if I will have 0x21 address available I will have in code
for(int i = 0; i <= 31; i++) (32 I/O's)
because 1 is already having 8A on a side and 8B ,so 16 in total. But 2 will be 32.
Correct?
 

Ya’akov

Joined Jan 27, 2019
9,150
I didnt know you can move one thread inside another, Very cool that you can do that, very modular, very smart !!!
Is no problem from my part. Indeed I was on the problem and I wanted some faster answers. I do push sometimes. Sorry for the mess, but now is cleaned, which is nice.
So for the 2 IC's I have right now, I have to make A2=0V, A1=0V,A0=3.3V (as logical 1) and it corresponds to address 0x21.
So this is looking more like a hardware programming to me...
And if I will have 0x21 address available I will have in code
for(int i = 0; i <= 31; i++) (32 I/O's)
Correct?
In the code you will have 8 sets of 8 I/O lines. The selection of each set is by the address you've assigned.

So:

0x20 1-8
0x21 1-8
...
0x27 1-8
 
Top