Shop OBEX P1 Docs P2 Docs Learn Events
Mpc23016 - Page 2 — Parallax Forums

Mpc23016

2

Comments

  • K de JongK de Jong Posts: 154
    edited 2004-09-04 14:48
    Hi Sid and Chris,

    I checked my BS2p Demo board and it looks like it has connected pin 21 to the output of the regulator (LM2940).

    But if you fried your Stamp I would think only the regulator will be gone ?!?. So you should be able to get them running with 5 Volts on pin 21. So with a little luck you can still use them if repair gets too expensive.

    I would suggest to give them a try in you USB-board.

    Regards and condoleances for the great loss of two Stamps,

    Klaus
  • NewzedNewzed Posts: 2,503
    edited 2004-09-04 14:56
    Klaus, did you remove the Stamp, apply power, then check the voltage on Stamp pin 21 and on AppMod Vdd?

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2004-09-04 15:01
    Sorry - you said BS2P demo board - we are talking about the BOE Rev B.

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2004-09-04 15:24
    I just checked my Rev C BOE.· With the Stamp removed, there is no power on Stamp pin 21, but there is power on the AppMod Vdd pin.· This agrees with the schematic.·

    On both the Rev B and Rev C boards, this limits the current that can be drawn from Stamp Vdd to 60ma max.

    Sid
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-09-04 15:34
    Yes Sid,

    ·· But we can always tie our Vdd lines together.· Of course, this won't help if you have a project in production with higher current requirements, but perhaps having a wire that runs down to the BOE Vdd line above the breadboard?· It's a quick and dirty solution to a problem.· But it would work.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • NewzedNewzed Posts: 2,503
    edited 2004-09-04 15:39
    Right, Chris.· On my MCP23016 Piggyback I had to cut the trace going to Pin 21 of the Stamp, then run a Vdd line from the MCP23016 which I plug into Vdd on the header.· Not designed that way but it works.· Have the MCP up and running now.

    Sid
  • K de JongK de Jong Posts: 154
    edited 2004-09-04 16:22
    Hi Sid,

    Only to confirm, Yes my board behaves as I stated. +5Volt on pin 21 with the Stamp removed.

    To be honest, I have never thought it would be different from that. But that can be, as you have experienced.

    A seperate power supply line for the 'heavy duty' Piggy Backs could be a solution. An other way might be to build the heavier systems using the appmod connector.

    Klaus
  • NewzedNewzed Posts: 2,503
    edited 2004-09-04 17:17
    A seperate power supply line for the 'heavy duty' Piggy Backs could be a solution. An other way might be to build the heavier systems using the appmod connector

    That's the problem, Klaus.· The AppMod gets its power from Stamp pin 21 so total curent including the Stamp is still 60ma max.

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2004-09-04 21:33
    Well, will wonders never cease!

    I finally got my MCP23016 to work on my BS2jumpin.gif

    I used the Demp code Jon posted a couple of days ago and that ran fine, but it didn't do what I wanted to do.· My goal was to set the states of each GP0 pin and each GP1 pin, reading back the states·of each bank after it was set.

    Jon's program was a little complex for me and I didn't really understand what he was saying, but I saved it as Rev A and started modifying it one line at a time.· After two days I finally have what I want - after initialization the screen says "Input GP0 states", I input, then the screen reads back the GP0 states, which I confirm with LEDs.· Same for GP1.

    Your help is certainly appreciated, Jon.· I just wish I understood more of what you wrote.· But as I have said before, you really don't have to know how things work, just how to use them.

    I'll be posting the code here in a day or two.· I want to make a few cosmetic changes and pretty it up a little.

    I had to add a power wire from the MCP board which plugs into the Vdd header, and then cut the·trace on the board that went to Pin 21 of the Stamp.· (It's a Piggyback board).· All those LEDs would have sizzled my BS2 in a heartbeat.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    TWS/RWS RF Modules

    http://hometown.aol.com/newzed/index.html
    ·
  • Kenny GardnerKenny Gardner Posts: 169
    edited 2004-09-04 22:09
    On all my Rev B boards, I've cut the trace between pin 21 and the Appmod Vdd connector. I thought it strange that·Appmods without onboard regulators were being powered by the Stamp, and as a matter of course, I always cut the trace and wire pin 19 of the Appmode connector directly to the output of the regulator.

    Since this is fixed in newer revisions, I never gave it much thought since newer boards don't have to be modified.

    But, if you've got a power hungry Appmod, then it should draw its power from Vin and include its own Regulator.

    Kenny



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    --

    Kenny Gardner
    GAP Development Company
    http://www.gapdev.com/
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-04 23:53
    Well, Sid, I'm certainly not the sharpest knife in the drawer and don't like writing difficult code. My MCP23016 demo was written after spending a few minutes with the data sheet. At at rate, I'm glad you got yours working and all is well at your place -- now duck, Frances is almost there....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-05 00:07
    Verily, I ducketh.

    Sid
  • Steven TronSteven Tron Posts: 13
    edited 2004-09-05 08:39
    Hi,

    I've just finished reading May's Nuts & Volts 'Expansion made easy' column on the MCP23016 I2C I/O expander.
    And as I am currently working on a project which uses the PFC8574, I would like to replace the PFC8574 with the MCP23016.

    Does anybody know where I could source the MCP23016 in the UK or from a source that will ship to the UK

    Regards

    Steve
  • NewzedNewzed Posts: 2,503
    edited 2004-09-05 14:11
    Jon, I have a question when you have time.

    You wrote:

    slvAddr = MCP23016 | (devNum << 1)

    This translates to slvAddr = 01000100 (with my configuration)

    Then in the Write_Byte routine you wrote:

    i2cWork = slvAddr & %11111110··

    Again, this translates to slvAddr = 01000100, same as above.

    Why not just write:

    i2cwork = slvAddr

    I'm sure I'm missing something.

    Sid
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-05 15:06
    You're not missing anything, except perhaps considering that I attempt to write robust code that will work under less-that-optimal conditions. For example, I cannot control what people will pass as a slave address to the Write_Byte routine once they start modifying my programs. Sure, you and I will always pass a valid slave address, but someone who won't look at and attempt to understand I2C or device specs might not. By masking out bit 0 of the slave address byte I ensure that it's valid for a write. Notice that Read_Byte sets bit 0 to 1 making it valid for a read.

    BTW... the BS2p/pe IC2OUT and I2CIN routines do the same thing "under the hood."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-05 15:11
    Thanks, Jon.· Now I understand exactly what you are doing.· I thought perhaps that was it - trying to make the program as idiot-proof as possible.

    Sid
  • NewzedNewzed Posts: 2,503
    edited 2004-09-05 17:24
    I have attached my code for the MCP23016 using a BS2/BS2E/BS2SX.

    I made the following changes to Jon's original code:

    Both GP0 and GP1 have been made outputs.

    The DO..LOOP has been replaced by a menu which gives the user the option of setting the pin states of either bank, then reading back the pin states.



    A made the following additional changes which are based on personal preference.· In the original program, the desired pin states were entered
    7-6-5-4-3-2-1-0.· I found it much easier to enter the states in the format
    0-1-2-3-4-5-6-7 so I made the following changes:

    Write_Byte:
    · GOSUB I2C_Start······························ ' send Start
    · i2cWork = slvAddr & %11111110················ ' send slave ID
    · GOSUB I2C_TX_Byte
    · IF (i2cAck = Nak) THEN Write_Byte············ ' wait until not busy
    · i2cWork = devAddr.BYTE0···················· ' send word address (0)
    · GOSUB I2C_TX_Byte
    · i2cWork = i2cData···························· ' send data
    · GOSUB I2C_TX_Byte1·········· '***************special LSBFIRST routine
    · GOSUB I2C_Stop
    · RETURN

    ·I2C_TX_Byte1:
    · SHIFTOUT SDA, SCL, LSBFIRST, [noparse][[/noparse]i2cWork\8]····· ' send byte to device
    · SHIFTIN SDA, SCL, MSBPRE, [noparse][[/noparse]i2cAck\1]········· ' get acknowledge bit
    · RETURN


    These changes let me enter the pin states in the order 0-1-2-3, etc.

    In order to read back the states the way they were entered, I made one other change:

    I2C_RX:
    · SHIFTIN SDA, SCL, LSBPRE, [noparse][[/noparse]i2cWork\8]········ '·was MSBPRE
    · SHIFTOUT SDA, SCL, LSBFIRST, [noparse][[/noparse]i2cAck\1]······ ' send ack or nak
    · RETURN

    Now the states are read back exactly as they were entered

    Chris, I hope you are impressed.confused.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    TWS/RWS RF Modules

    http://hometown.aol.com/newzed/index.html
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2004-09-05 21:35
    Yeah Sid, looks like you've been busy!· Where'd you get your chip from?· I think I will order a few to have on hand to mess with.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-06 00:38
    Keep in mind, Sid, that my MCP23016 code uses routines that would work with any I2C device -- and your modification kind of squashes that.· If one of your customers wants to add another I2C device to your program they will have problems and you will be forced to write more custom code (or create a redundant Write_Byte routine that works properly).· It seems that if someone can enter a binary value for the outputs, they could do it in the 7-6-...0 order.· But that's just my opinion.

    Another thing you could do to keep the standard code in tact is use a temporay variable to take the inputs, then flip them around into GP0 or GP1 so that the value is compatible with the standard routine.· Like this:

    · FOR idx = 0 TO 7
    ··· i2cData.LOWBIT(idx) = temp.LOWBIT(7 - idx)
    · NEXT


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office


    Post Edited (Jon Williams) : 9/6/2004 12:55:01 AM GMT
  • NewzedNewzed Posts: 2,503
    edited 2004-09-06 12:37
    Jon, one thing I did not want to do·was to·destroy the functionality of your original code.· All I wanted to do was to be able to enter the states for GP0 and GP1 from the keyboard, then read them back.· My problem is that I just don't understand how the· program works that well.

    For instance, what is addrLen, and how could it be 0, 1, or 2?

    how would I address a second I2C device with your code?· Wouldn't I have to change devAddr and slvAddr?

    In your program, if I change GP1 to outputs and remove the GP1 inversion lines, then write this:

    Main:
    · DO
    ··· devAddr = GP1
    ····debugin bin8 i2cdata
    ··· gosub Write_Byte
    ··· pause 50
    ··· GOSUB Read_Byte·······························
    ··· DEBUG CRSRXY, 0, 2, ·"GP1: ", bin8 i2cdata
    ··· devAddr = GP0
    ····debugin bin8 i2cdata
    ··· GOSUB Write_Byte
    ··· PAUSE 50
    ··· gosub Read_Byte
    ··· debug "GP0:· ", bin8 i2cdata
    · LOOP
    · END


    Would this do what I want to do and still leave your program fully functional?

    Sorry to be such a pain in the glutinous maximus!



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-06 14:12
    It looks like you removed my original program comments without reading them. mad.gif· Shame on you! turn.gif

    The variable called addrLen tells the Write_Byte and Read_Byte routines how may bytes are in the register address being used by the device.· The PCF8574, for example, has an addrLen of 0 (no internal register addresses); the MCP23016 has an addrLen of one (one register address byte, that is), and the 24LC256 has an addrLen of two (register bytes, because it is a 32 kByte device).

    You can write to another device with the standard routines by changing the values of slvAddr, addrLen, and devAddr as required by the device -- that's why I made all these items variables, so that they could be changed during the course of a program.

    Your code looks like it would work, have you tried it.· Of course, you could fancy it up a bit with a subroutine that does your bit-flipping:


      DEBUG "GP0: " 
      GOSUB Get_Temp          ' returns bits in temp, flipped end-to-end 
      slvAddr = MCP23016      ' possibly redundant -- use just once if no other I2C devices in program 
      addrLen = 1             ' possibly redundant -- use just once if no other I2C devices in program 
      devAddr = GP0 
      GOSUB Write_Byte 
    
    ... <snip> ... 
    
    Get_Temp: 
      DEBUG "Enter pin states, 0 or 1 (Order is 1-2-3-4-5-6-7-8)... " 
      DEBUGIN BIN8 temp 
      FOR idx = 0 TO 7 
        i2cData.LOWBIT(idx) = temp.LOWBIT(7-idx) 
      NEXT 
      RETURN
    



    Let me suggest that you don't rush to get it done -- quality takes time.· Programming, like love and death, should not be rushed.

    With a little more time and programming you can make a nice interface for your module that takes advantage of I2C code that has been successfully tested on several devices.





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-06 14:38
    Jon, I would never, never, never remove your comments.· I left them off the post just for brevity.

    I modified the program as I indicated and it seems to work fine.· Now then I will try to add the Get_Temp routine and see how that works.



    If there were more that one device on the system, devAddr and slvAddr could probably be changed as required through a Menu, I would think.
    Something like:

    if com = 2 then
    slvAddr = MCP23016 | (devNum << 1)
    devAddr = IODIRO
    endif

    if com = 3 then
    slvAddr = something else
    devAddr = more else
    endif

    Barometer has risen to 965 from last night's 955 - 3.7 inches of rain since midnight.· Phone is out.· Wind is howling.· I need a cup of coffee.







    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • NewzedNewzed Posts: 2,503
    edited 2004-09-06 15:18
    I added the Get_Temp routine and the program is working great.· If fact, I wrote a Get_Temp0 and a Get_Temp1 so I could display the bank being set.· Just so everything would be absolutely clear.

    States are entered 0-1-2-3 and so on.

    I need to tidy up the program a bit and add some comments, then I will post it here.

    3.75 inches of rain, humidity 94%, gusts to 50mph.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-06 15:22
    Yes, it works fine in that specific context.· But if one of your customers attempts to modify your version (as you did with mine), it could create a problem as you've modified core routines.· I'm suggesting that you use the core routines as is, providing the information to them that they desire.· This will allow you and others to use the core routines without problems -- and perhaps save me some support time since MY routines are left in tact and working. smile.gif

    BTW ... I'm updating that code to make the comments even more verbose, and I will include this comment:

    ' DO NOT modify code below this line.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Fe2o3FishFe2o3Fish Posts: 170
    edited 2004-09-06 16:00
    For those of you wanting to get some MCP23016 chips, you can request samples
    directly from Microchip for free. I think you're limited to a max of 3 chips so, for
    something to tinker with this is probably more than enough. Be sure to get the
    MCP23106-I/SP version as it's the DIP package; everything else would be difficult to
    put onto a solderless breadboard. Alledgedly, M/C says mine are on their way.

    -Rusty-

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Rusty-
    --
    Rusty Haddock = KD4WLZ = rusty@fe2o3.lonestar.org
    **Out yonder in the Van Alstyne (TX) Metropolitan Area**
    Microsoft is to software what McDonalds is to gourmet cooking
  • NewzedNewzed Posts: 2,503
    edited 2004-09-06 16:17
    Jon, I only made the minimum (I thought) changes to your program that would let me enter the states of GP0 and GP1 from the keyboard, which is what I think most users would would to do.· I changed GP1 from inputs to outputs and wrote:

    devAddr = GP1······························ ' point to·outputs
    ··· gosub get_temp
    ··· gosub Write_Byte
    ··· GOSUB Read_Byte···························· ' read·GP1 pin states···
    DEBUG CRSRXY, 0, 2,
    ········· "GP1 states:· ", BIN8 i2cData··········· ' display

    and the same for GP0.

    How does that change the overall effectiveness of your code?· What other way could I have done it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-06 17:32
    My concern was that you modified standard I2C routines so that they were no-longer standard. The whole point of those routines and their design was to allow you to connect to more than one type of I2C device with your program. Change my code all you want -- just remove my name when you do so that I don't have to support errors that I don't create....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • NewzedNewzed Posts: 2,503
    edited 2004-09-06 22:26
    Chris, I can loan you an MCP23016 if you're in a hurry.· The only thing is - it's a 28-pin SOIC, not a DIP.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Visit the Piggyback Page

    http://hometown.aol.com/newzed/index.html
    ·
  • Fe2o3FishFe2o3Fish Posts: 170
    edited 2004-09-09 19:59
    FWIW, the 2 MCP23016 samples that I requested from Microchips this past Labor Day (US)
    weekend just arrived FedEx from Thailand. Sorta wish I had ordered some other parts to
    play er... tinker with just to make it a little more worth while.... Well, off to go
    scrounge up some resistors, caps, and a few LEDs.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Rusty-
    --
    Rusty Haddock = KD4WLZ = rusty@fe2o3.lonestar.org
    **Out yonder in the Van Alstyne (TX) Metropolitan Area**
    Microsoft is to software what McDonalds is to gourmet cooking
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-09 20:05
    For those that don't want to wait on samples, you can get the MCP23016 from Mouser (just down the road from me) for a couple bucks apiece.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.