PDA

View Full Version : accessing multiple MCP23016s



ecoli-557
- 19th May 2008, 23:02
Hello All-
With great help from this forum, I have the ability to read and write to a MCP23016. I now want to read and write to the max which is 8 of these on one I2C line.

In debugging and troubleshooting - and learning, it looks as if the 23016s are addressed not one after the other (addr $40 for device zero, addr$41 for device 1, etc) but skipping one address such as $40 for the 1st device at address0 then $42 for the second device at address1, and so on which does not make sense.

This is not what I read from the datasheet or from other examples on this forum.

Partial code below which reads from the device. I use PORT0 for output and PORT1 for inputs.

iaddr=$40 '1st switch board's address
i2cread idata,iclock,iaddr,ireg,[switches[0]]
pause 20
iaddr=$42 '2nd switch board's address
i2cread idata,iclock,iaddr,ireg,[switches[1]]
pause 20
iaddr=$44
i2cread idata,iclock,iaddr,ireg,[switches[2]]
pause 20
iaddr=$46
i2cread idata,iclock,iaddr,ireg,[switches[3]]
pause 20

I get back data and can write to the device so I think I got it, but it does not agree with the datasheet.

What am I doing wrong?

mister_e
- 19th May 2008, 23:28
It's about normal



CONTROL WORD
------------
BIT7 BIT6 BIT5 BIT4 BIT3 BIT2 BIT1 BIT0
0 1 0 0 A2 A1 A0 R/W
0 1 0 0 0 0 0 x 40
0 1 0 0 0 0 1 x 42
0 1 0 0 0 1 0 x 44
0 1 0 0 0 1 1 x 46
0 1 0 0 1 0 0 x 48
0 1 0 0 1 0 1 x 4A
etc etc etc

BIT0 is handled by PBP.

ecoli-557
- 19th May 2008, 23:31
Well yes, you are absolutely correct!
I completely forgot the R/W bit was counted.........
Time to go to sleep or grab a wine glass <grin>!

Thanks

mister_e
- 19th May 2008, 23:35
Try both :D

ecoli-557
- 20th May 2008, 23:04
Mr. E (or anyone <grin>-
What is the 'best' way to bus these 23016s off board? I will have 8 of these devices on their own I/O board and looking at the waveforms on 3 of them - the multi-ground cable may not be the best solution.

The leading edge of the waveform rounds off to the falling edge of the pulse. The cable I have selected is instrument-grade but without a foil shield. I am sending +5 with the 2 signals but I do have 3 ground wires and the twist in the cable should have been good enough for the 1 foot of cable between the 8 boards.

The proc is in the middle and 4 boards go out from the left and right.

Should I use a schmidt buffer?

ecoli-557
- 20th May 2008, 23:54
I changed the pullups to 2.2k based on the graph in the I2C specs of 2000. I believe since I am using all MCP23016s and they are 'fast' devices, I should be fine.

The waveforms have a bit of roll-off on the leading edge but look better.

Has anyone used the switched pull up circuit from this refrence?