i2c with my bs2p and mcp23016
trend
Posts: 112
I had a board developed· by someone that is suppose to control relays.. the basic layout is:
bs2p> (over i2c bus) mcp23016 >· ULN2803A > relays
My first set of questions [noparse]:)[/noparse] is:
How do I find out the address of my mcp23016 (there are 2 on the bus)
I have seen this code in trying to access mcp23016s before:
DevType········ CON···· %0100 << 4············· ' Device type
DevAddr········ CON···· %000 << 1·············· ' address = %000 -> %111
Wr23016········ CON···· DevType | DevAddr······ ' write to MCP23016
I guess I just do not understand the constant values in this case...
2nd question:
When using:
I2COUT SDA, Wr23016, IODIR0, [noparse][[/noparse]%00000000]
what determines the value of IODIR0, and how do I determine the value of· [noparse][[/noparse]%00000000] ?
3rdly..
After· I setup all the ports as outputs, how do I toggle what ports should be high or low?
and my 2nd set of questions is only 1 question...
What is the purpose of my ULN2803A? just to increase the voltage of the line? so I will not program anything differently because of it
thanks for the help! I am slowly getting all this [noparse]:)[/noparse]
bs2p> (over i2c bus) mcp23016 >· ULN2803A > relays
My first set of questions [noparse]:)[/noparse] is:
How do I find out the address of my mcp23016 (there are 2 on the bus)
I have seen this code in trying to access mcp23016s before:
DevType········ CON···· %0100 << 4············· ' Device type
DevAddr········ CON···· %000 << 1·············· ' address = %000 -> %111
Wr23016········ CON···· DevType | DevAddr······ ' write to MCP23016
I guess I just do not understand the constant values in this case...
2nd question:
When using:
I2COUT SDA, Wr23016, IODIR0, [noparse][[/noparse]%00000000]
what determines the value of IODIR0, and how do I determine the value of· [noparse][[/noparse]%00000000] ?
3rdly..
After· I setup all the ports as outputs, how do I toggle what ports should be high or low?
and my 2nd set of questions is only 1 question...
What is the purpose of my ULN2803A? just to increase the voltage of the line? so I will not program anything differently because of it
thanks for the help! I am slowly getting all this [noparse]:)[/noparse]
Comments
slave = (%0100 <<4) | (devAddr << 1)
... where devAddr is a nibble variable that holds the device number you want to talk to.·
The rest of the constant definitions and inner workings of the program will become evident when you read through the documentation of the part (as one should ALWAYS DO).· I've attached it so you don't have to do a web hunt.
This N&V article may help as well: http://www.parallax.com/dl/docs/cols/nv/vol5/col/nv109.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
I have been on this project all day.. I think I am finally getting it.. Thanks for the link, I am currently reading:
http://www.parallaxinc.com/dl/docs/cols/nv/vol3/col/nv79.pdf·(for my future reference [noparse]:)[/noparse]
I will try to reread the documentation on the chip.. The first read through was very brief, because I thought this was way over my head.. Hopefully at days end I will understand it.
thanks Jon! Your great
Post Edited (trend) : 10/31/2004 4:47:04 AM GMT
This is what I got so far (I don't really understand your code use for multiple slaves, so can I use the below?)
MCP1· Con· %0100011
MCP2· Con· %0100001
I2COUT SDA, MCP1, $06, [noparse][[/noparse]%00000000]
I2COUT SDA, MCP1, $07, [noparse][[/noparse]%00000000]
I2COUT SDA, MCP2, $06, [noparse][[/noparse]%00000000]
I2COUT SDA, MCP2, $07, [noparse][[/noparse]%00000000]
/edit/
Looks like I can do it this way.. I think:
MCP1· Con· %0100011
MCP2· Con· %0100001
I2COUT SDA, MCP1, $06, [noparse][[/noparse]%00000000, %00000000]
I2COUT SDA, MCP2, $06, [noparse][[/noparse]%00000000, %00000000]
/end of edit/
And this will set all the I/O to outputs.. but not output anything yet, right?
1)I am stumped on how to make an output output (I will only need to output one at a time).
2)Also, This project will be communicating from my computer.· Can I do something like:
···X = input from computer··· 'yeah I know this isn't the correct syntax, but you get the idea [noparse];)[/noparse]
·· I2COUT SDA, MCP1, $06, X
/edit
Looks like I can do 2).. but what type variable should I store the input from the computer as? Int ?
/end of edit/
Post Edited (trend) : 10/31/2004 5:43:45 AM GMT
·· ·MCP1 Con %01000110
·· ·MCP2 Con %01000010
You don't need to worry about the final bit being 0 (write) or 1 (read) -- the BS2p takes care of this bit with I2COUT and I2CIN.
1) Set the bit in the IODIR resiter to 0 to make the MCP23106 pin an output.
··· I2COUT SDA, MCP1, IODIR0, [noparse][[/noparse]%00000000, %00000000]
2) You'll need to do this with SERIN to take all 16 bits:
··· SERIN Sio, Baud, [noparse][[/noparse]ctrlBits.BYTE0, ctrlBits.BYTE1]
··· I2COUT SDA, MCP1, GP0, [noparse][[/noparse]ctrlBits.BYTE0, ctrlBits.BYTE1]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
··· I2COUT SDA, MCP1, IODIR0, [noparse][[/noparse]%00000000, %00000000]
I would only do this if IODIR0 is already definited as $06, right? So I cannot just do:
I2COUT SDA, MCP1, $06, [noparse][[/noparse]%00000000, %00000000] to cut down on coding size?
2) You'll need to do this with SERIN to take all 16 bits:
··· SERIN Sio, Baud, [noparse][[/noparse]ctrlBits.BYTE0, ctrlBits.BYTE1]
··· I2COUT SDA, MCP1, GP0, [noparse][[/noparse]ctrlBits.BYTE0, ctrlBits.BYTE1]
I am totally stumped here.. Throwing in SERIN blows my mind ...
Then the 2nd line.This will output 5v on all the defined outputs? or just specific outputs.
Sorry to keep asking all these questions, I have looked over the manual, looked over a couple code snips, but still am lost on how to do 100% of this stuff.
thanks Lee
Post Edited (trend) : 10/31/2004 6:36:32 PM GMT
Is the only reason I would use the:
SERIN Sio, Baud, [noparse][[/noparse]ctrlBits.BYTE0, ctrlBits.BYTE1]
line because I am using:
I2COUT SDA, MCP1, IODIR0, [noparse][[/noparse]%00000000, %00000000]
If I just had I2COUT SDA, MCP1, IODIR0, [noparse][[/noparse]%00000000]
If I just had I2COUT SDA, MCP1, IODIR1, [noparse][[/noparse]%00000000]
I would not need the
SERIN Sio, Baud, [noparse][[/noparse]ctrlBits.BYTE0, ctrlBits.BYTE1]
command?
Yes, you must define IODIR0 before using it as I suggest; since you're starting with my MCP23016 demo code that's alread done, right?· Using named constants will make your like a whole lot easier -- listings become readable without having to refer back·to docs.
You said that the project will be communicating from your computer.· If that's the case, you need to use SERIN to accept data from the computer and then pass it along to your control outputs.· One way to do this is with VB.· Perhaps this article will help.
http://www.parallax.com/dl/docs/cols/nv/vol3/col/nv89.pdf
Or, a very simplistic approach is via the DEBUG terminal.· This StampWorks experiment may help:
http://www.parallax.com/dl/docs/books/sw/exp/sw31.pdf
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
So
SERIN Sio, Baud, [noparse][[/noparse]ctrlBits.BYTE0, ctrlBits.BYTE1]
Will accept (will it wait for data?) in a format like: "01000010, 01000010"
And then reversing the polerity makes an output actually output 5v..
I think I am getting it now [noparse]:)[/noparse]
SDA············ PIN···· 0······················ ' I2C data pin
SCL············ PIN···· 1······················ ' I2C clock pin
MCP1· Con· %01000110
MCP2· Con· %01000010
IODIR0 Con· $06
IODIR1 Con· $06
I2COUT SDA, MCP1, IODIR0, [noparse][[/noparse]%00000000, %00000000]
I2COUT SDA, MCP2, IODIR1, [noparse][[/noparse]%00000000, %00000000]
I2COUT SDA, MCP1, GP0, [noparse][[/noparse]%00001000, %00000000] 'this is suppose to turn on one relay
Post Edited (trend) : 10/31/2004 7:44:29 PM GMT
SERIN Sio, Baud, [noparse][[/noparse]BIN8 ctrlBits.BYTE0, BIN8 ctrlBits.BYTE1]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office
SCL············ PIN···· 1
declared In the mcp23016.bsp code I saw Jon Do? I don't see the SCL variable used in his code..
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas Office