MCP23016 I/O expander


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 43
  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154

    Question MCP23016 I/O expander

    I am trying to wire an MCP23016 as output; driving LEDs. No matter what I try, no LEDs light up. Any idea what I am missing?

    ---------------------------------------------------------------
    'define LOADER_USED 1
    ADCON1 = 7 ' A/D off, all digital

    ASM
    @ DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
    ENDASM

    define OSC 20

    DEFINE LCD_DREG PORTA ' Set LCD data port
    DEFINE LCD_DBIT 0 ' Set starting data bit
    DEFINE LCD_RSREG PORTA ' Set LCD register select port
    DEFINE LCD_RSBIT 4 ' Set LCD register select bit
    DEFINE LCD_EREG PORTB ' Set LCD enable port
    DEFINE LCD_EBIT 3 ' Set LCD enable bit
    DEFINE LCD_BITS 4 ' Set LCD bus size
    DEFINE LCD_LINES 4 ' Set number of lines on LCD
    define LCD_COMMANDUS 2000 ' Set command delay time in microseconds
    DEFINE LCD_DATAUS 50 ' Set data delay time in microseconds

    DEFINE I2C_SLOW 1 ' Access I2C device above 8MHz
    'DEFINE I2C_SCLOUT 1 ' Set I2C clock line as bipolar
    DEFINE I2C_HOLD 1 ' Permit I2C device to hold clock line low

    I2CSDA VAR PortC.4 ' Data line
    I2CSCL VAR PortC.3 ' Clock line
    I2CCTRL VAR BYTE ' I2C chip address
    I2CLOC VAR BYTE ' I2C location byte
    I2CBYTE1 VAR BYTE ' I2C 8 bit data string
    I2CBYTE2 VAR BYTE ' I2C 8 bit data string

    GOTO START

    ERRORIO:
    LCDOUT $FE,$94,"No ACK from I2C device"
    RETURN

    START: PAUSE 2000 ' Wait for LCD to initalize
    LCDOUT $FE,1,"Program start"

    ' I2C device address: ID A2 A1 A0 R/W
    ' ---- -- -- -- ---
    ' 0100 0 0 0 0

    I2CCTRL = %01000000
    I2CLOC = $06 ' Set location to IODIR register pair
    I2CBYTE1 = %00000000 ' Set pins 0-7 as output
    I2CBYTE2 = %00000000 ' Set pins 8-15 as output
    I2CWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOC,[I2CBYTE1,I2CBYTE2],ERRORIO
    PAUSE 2000

    I2CCTRL = %01000000
    I2CLOC = $00 ' Set location to GPIO register pair
    I2CBYTE1 = %00101010
    I2CBYTE2 = %00000000
    I2CWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOC,[I2CBYTE1,I2CBYTE2],ERRORIO

    Finish:
    LCDOUT $FE,$D4,"Process complete"
    end
    ---------------------------------------------------------------


    Yeah, I just noticed an error in my I2CWRITE comment. I meant pins in the sense of logical pins(GP0.0-GP0.7 and GP1.0-1.7).

    I also did some trial & error with the I2C DEFINES, but no luck there. I even increased the PAUSE in case. The program terminates properly, so it seems as if I do get some sort of acknowledgement from the device.

    I've triple-checked the wiring a zillion times. I followed the datasheet and placed the RC as specified.

    I'm stumped...

    Thanks!

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I don't see you initialising this chip. Last I checked it had twelve registers... let's set them up the way you'd like to see them.... then and only then you can perform I/O.

    Have you remembered to GROUND A2, A1 and A0 to match your IOCCTRL Byte?

    Have you remembered to leave TP floating?

    Have you remembered to GROUND all THREE Vss pins?

    Have you remembered Rext and Cext for your external Clock, or alternatively cross-connected it to Fosc of your PIC?

  3. #3
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    "I don't see you initialising this chip. Last I checked it had twelve registers... let's set them up the way you'd like to see them.... then and only then you can perform I/O."

    The default values for all the registers seem to be what I want except for the IODIR register pair. According to the datasheet, we are able to write to both registers in a single write operation. The 1st I2CWRITE is supposed to write all ZEROES to both registers (IODIR0 and IODIR1):

    I2CCTRL = %01000000
    I2CLOC = $06 ' Set location to IODIR register pair
    I2CBYTE1 = %00000000 ' Set pins 0-7 as output
    I2CBYTE2 = %00000000 ' Set pins 8-15 as output
    I2CWRITE I2CSDA,I2CSCL,I2CCTRL,I2CLOC,[I2CBYTE1,I2CBYTE2],ERRORIO

    ----------------------------------------------------------------------

    "Have you remembered to GROUND A2, A1 and A0 to match your IOCCTRL Byte?"

    Yup.

    ----------------------------------------------------------------------

    "Have you remembered to leave TP floating?"

    Yup.

    ----------------------------------------------------------------------

    "Have you remembered to GROUND all THREE Vss pins?"

    Yup.

    ----------------------------------------------------------------------

    "Have you remembered Rext and Cext for your external Clock, or alternatively cross-connected it to Fosc of your PIC?"

    Yup, on the RC connection. I wanted to try your 2nd suggestion, but I can't see an Fosc pin on the 16F877.

    ----------------------------------------------------------------------

    I've even connected all 16 I/O pins to LEDs, so I can easily see what is happening.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  4. #4
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Is there any particular reason why MicroChip would NOT include in the datasheet for the MCP23016 a little diagram of pull-up resistors on the data and clock lines?

    Who knows how long this has been working...

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  5. #5
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Hmm, I have a feeling the pull-up resistor is more a requirement for the PIC 16F877 than for the MCP23016...

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    4K7 pull-up's ARE required on the I2C lines.

  7. #7
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Hmm, ok. I've gone through the datasheet more times than I can remember, but I never saw any mention of PU resistors on the clock/data lines. Is there any mention in it? Or are we 'expected' to know better?

    The only reason I thought of them is from reading the PBP Pro manual.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  9. #9
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    If you put a scope on your I2C Bus, you would have realised the waveform didn't meet the specification of Table 2-5 in the Datasheet. Some devices do not require PU Resistors, PICs do... the clue could also have been found in the PBP manual I2C commands where an example schematic is given connecting to an external EEPROM. 4K7 is a good value when connecting one or two slave devices with a relatively short track between them. You need to drop this value for more devices or greater track capacitance. Refer to Raph's pointer to the I2C Bus Spec.

  10. #10
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Yup, like I said, that's exactly where I found the answer.

    Things worked great, until I got cocky.

    Yeah, I also noticed that more devices screws up stuff. At least I have Ralph's link to help me out to figure the correct resistance value.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  11. #11
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Hmm, still getting unreliable results.

    Sorry, but the oscilloscope readings are still just a tad over my head. I was hoping to be able to diagnose this problem with more conventional techniques (if I can).

    I placed my multimeter on 2000pF, the only pF setting I have, plugged 2 wires in the built-in holes (for capacitors) and then tested from SDA pin on PIC up to SDA pin on MCP.

    I get 30pF, but now I realize that the wires I'm using could very well affect the reading. The probes only test A, V, Ohms and Hz, so I can't use those.

    I had used 1.5K pull-up resistors and that had helped a lot. But it still has a way to go for reliable performance. I'll do as mentionned above and lower the resistor slowly and see if things improve.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  12. #12
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    One note about this circuit:

    - PIC 16F877 mcu
    - triple MCT6 opto-couplers
    - 24AA512 eeprom
    - dual MCP23016 (one used as input, one as output)

    I use the MCT6 to switch between the SDA lines on the I2C devices. I used both sides of the MCT6 per device to permit bidirectional transfer.

    The SCL line is shared amongst all the I2C devices.

    I separated the input and output MCP23016 because I plan to have 8 of each later. I am only using one now to test the system.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  13. #13
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    A picture is better and easier to spot the mistakes.

    Robert
    Attached Images Attached Images  
    Last edited by Demon; - 23rd October 2005 at 03:14.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  14. #14
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Ok, I went down to 1K and things seemed worse. So I went the other way and tried 2.2K with perfect results.

    The part that sucks about this is that the breadboard and PCB and NOT going to have identical capacitance. I may not know what I'm talking about, but I know that much.

    It sure is nice to see the circuit act as it should though. At least now I have an idea of where to look if things act up when I print this circuit. Some trial&error with resistors at worse, if I'm lucky I'll learn how to use an oscilloscope properly by then.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  15. #15
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Robert,

    you should really read the I2C Specs.

    Your schematic will never work.
    The SDA Line is Bidirectional!

    I2C is a BUS, so why separating the SDA lines
    if there are no more than 8 devices of the same type on the same bus?

    If (for what reason ever) you want to isolate the bus use THIS schematic.

    Attached is a schematic that should work for you.
    Attached Images Attached Images  
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  16. #16
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Heille salope, mon e-mail vidéotron ma chié dans les mains alors si tu essaie de me contacter c peine perdue.. j'attends encore après eux... HouHou service a la clientele

    Anyways. That's a strange design you have. What do you expect from your Opto-Coupler? A short-long history will be appreciated... at least for me the slow single brain cell.

    Usually all SDA & SCL lines are connected together without anything else and use 2 pull-up resistors. that's it, that's all, no preservative, no aspartame, fat free. As usual, 0.1uF ceramice close to each I2C device is highly recommended.

    On a design i'm working on NOW, i have 1 X PCF8574, 4 X 24LC64 on the same I2C bus and i use 4.7K without problems... as now

    It appear in some case, on certain board design, that some I/O on certain PORT react weird depending the speed you mess with. Sometime reducing speed help. I can't remember on wich PIC i had a weird issue but i choose 2 I/O that are not one next to the oher (B.0, B1..) and it cure the problem. Seems to be another Read-Modify-Write issue.


    __________________________________________________ ___________________________
    EDIT: Sorry Ralph, didn't notice your post... as you know, i'm still trying to deal with my emotions since you know why
    Last edited by mister_e; - 23rd October 2005 at 12:33.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  17. #17
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default mmm..

    Ralph,
    maybe i'm the ony one or my computer miss some internet plug-in, but i can't see your schematic... are you using P82B96 or any other Philips in the PCA951X family?

    I ask you that because my next design (on wich i'll probably spend ... few months maybe a year on), i'll have to deal with around 100 (maybe more) of those hot-swap I2C buffer to protect the main frame while the user change/add/swap control slots/modules.

    Sorry Robert to be off topic
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  18. #18
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by NavMicroSystems
    Robert,
    Hi Ralph.

    Quote Originally Posted by NavMicroSystems
    you should really read the I2C Specs.
    I did, that's where I got the idea to go down to 1.5K for the pull-up resistors. Page 40somethings had interesting values.

    Quote Originally Posted by NavMicroSystems
    Your schematic will never work.
    Wanna bet? :lol: It's working perfectly.

    - I pull the MCT6 for the eeprom high.
    - I can read data from memory and display it on an LCD.
    - I pull the MCT6 back low.
    - I pull the MCT6 for the output MCP23016 high (the first one).
    - I can turn on whichever LEDs are identified on the eeprom data.

    I am now in the process of activating the 2nd MCP23016 which will be used as input.

    Quote Originally Posted by NavMicroSystems
    The SDA Line is Bidirectional!
    I know, I said that on post #12.

    Quote Originally Posted by NavMicroSystems
    I2C is a BUS, so why separating the SDA lines
    if there are no more than 8 devices of the same type on the same bus?
    I know. I gave notes on my circuit on post #12 to explain my reasoning. Right now I'm testing with one input and one output MCP23016, but I plan on having 8 input and 8 output later. Actually, I'm going to have even more than that. I'm going to add an MCT6 for each additionnal 'network' of 8 MCP23016 devices.

    Quote Originally Posted by NavMicroSystems
    If (for what reason ever) you want to isolate the bus use THIS schematic.
    Link no workie, red X.

    Quote Originally Posted by NavMicroSystems
    Attached is a schematic that should work for you.
    No workie either.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  19. #19
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Ralph,

    A little more on using the MCT6 as a bidirectional switch in this circuit.

    Note how the wiring to the eeprom is connected to the MCT6. A single wire from the eeprom is wired twice in opposite manner on a single MCT6.

    Here, the best way to explain myself is to make a drawing.

    Robert
    Attached Images Attached Images  
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  20. #20
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Heille Steve, ouais, je t'ai envoye plusieurs emails sur Videotron. C'etait pas mal la meme chose que j'ai demande icitte, avec un peu de bla-bla.

    (maudit clavier anglais, pas d'accents sur ce PC)

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  21. #21
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Talking

    Mr Demon,
    Even if i don't see any advantage and/or need for the Optos, it also introduce, at least, a voltage drop between The PIC and the I2C device. No matter why it's working so so.

    Schematic provided by Ralph will work. You just need to modify your I2CWRITE/I2CREAD statement to fit with the A0, A1, A2 jumpers.

    On your SCL and SDA line, you should be able to fit all your I2C devices. As i remind MCPXXX don't have the same control word than your EEPROM so it shouldn't provide any conflict.

    Qu'a Pitch?
    Last edited by Demon; - 4th October 2016 at 18:10.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  22. #22
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Demon
    Link no workie, red X.

    No workie either.

    Robert
    Rightclick --> Save Target As . . . .
    Last edited by Demon; - 4th October 2016 at 18:10.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  23. #23
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Demon
    I separated the input and output MCP23016 because I plan to have 8 of each later. I am only using one now to test the system.

    Robert
    Since the MCP (like most other I2C Devices) has 3 address bits you can have up to 8 devices of the same type sharing one bus.

    For more than 8 (up to 16) devices of the same type share SCL for all of them and have separate SDA for each set of 8.
    So to communicate with 16 Devices of the same type you need three Ports on the PIC.

    I don't use the MCP, I prefer the PCF8574.
    There is an "A" version available that has a control-byte different from the "non A" version, so you can have up to 16 (8x"A" & 8x"non A") devices sharing one pair of SDA cnd SCL lines.
    Last edited by Demon; - 4th October 2016 at 18:10.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  24. #24
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Ralph,
    maybe i'm the ony one or my computer miss some internet plug-in, but i can't see your schematic... are you using P82B96 or any other Philips in the PCA951X family?

    I ask you that because my next design (on wich i'll probably spend ... few months maybe a year on), i'll have to deal with around 100 (maybe more) of those hot-swap I2C buffer to protect the main frame while the user change/add/swap control slots/modules.

    Sorry Robert to be off topic
    Steve,

    the schematic is tested and working fine,
    the only thing a have changed in my final design are the opto's, the 6N139 was too slow for "High-Speed" I2C
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  25. #25
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Demon

    Here, the best way to explain myself is to make a drawing.

    Robert
    Robert,

    I'm sorry, this still doesn't make any sense to me.
    Why use opto's when you aren't isolating anything?

    Steve,

    this would be an application for the 4066's we still have on the shelf ;-)
    Last edited by Demon; - 4th October 2016 at 18:11.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  26. #26
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e
    Mr Demon,
    What is this Mister talk? I hope you're not doing the "vous" thing, 'cause if you are and you're just doing this to respect your elders, then I'm going to have to stroll over and hit you about the shoulders with my cane.

    :P

    Quote Originally Posted by mister_e
    Even if i don't see any advantage and/or need for the Optos, it also introduce, at least, a voltage drop between The PIC and the I2C device. No matter why it's working so so.
    I forgot about that.

    Quote Originally Posted by mister_e
    Schematic provided by Ralph will work. You just need to modify your I2CWRITE/I2CREAD statement to fit with the A0, A1, A2 jumpers.
    I don't have those arts on hand at the moment.



    Quote Originally Posted by mister_e
    On your SCL and SDA line, you should be able to fit all your I2C devices. As i remind MCPXXX don't have the same control word than your EEPROM so it shouldn't provide any conflict.
    Steve, I want to be able to have 8 MCP23016 for input, and another 8 for output, all on a single PIC. That's why I tried the MCT6 switch idea.

    Quote Originally Posted by NavMicroSystems
    For more than 8 (up to 16) devices of the same type share SCL for all of them and have separate SDA for each set of 8.
    Yeah, but the PIC 16F877 only has one SDA/SCL pair of pins. Is there another PIC that has multiple SDA lines (I didn't notice this feature on the MicroChip product list)?

    Robert
    Last edited by Demon; - 4th October 2016 at 18:11.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  27. #27
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by NavMicroSystems
    Robert,

    I'm sorry, this still doesn't make any sense to me.
    Why use opto's when you aren't isolating anything?
    Ralph,

    The optos were used only as a means of being able to switch between more than 8 MCP23016. I can easily activate the MCT6 I wish with a single pin from the PIC. Don't look for any fancy reasons, there aren't any.

    It was the only idea I could come up with the have more than 8 MCP23016 share a common SDA line (since I don't know how to have more than 1 SDA line per PIC).

    Robert
    Last edited by Demon; - 23rd October 2005 at 18:00.
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  28. #28
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Demon
    Yeah, but the PIC 16F877 only has one SDA/SCL pair of pins. Is there another PIC that has multiple SDA lines (I didn't notice this feature on the MicroChip product list)?

    Robert
    Robert,

    PBP's I2CWRITE / I2CREAD is "Software I2C" (not using the MSSP-Module), so you can use ANY I/O Pin.

    See PBP Manual Section 5.34 & 5.35
    Last edited by Demon; - 4th October 2016 at 18:13.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  29. #29
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Awe ben tabarnoune!

    Ralph, one of your comments made it seem like all I had to do was to use another pin as an SDA and just go on from there. So that's what I just tried and the darned thing works!

    Ok, that's great. But why is the SDA line listed on a particular pin on the 16F877 datasheet?

    I thought that since it was listed on RC4 that THAT was the only place it would work. Hence why I tried all these acrobatics to work with this limitation.

    This brings up another question; will SDA work on all pins?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  30. #30
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Ok, just saw your post come up.

    Thanks very much Ralph and Melanie.

    I was going to say thanks to that Mister_E comedian, but he's ignoring my emails. :P

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  31. #31
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Dear vieux debris
    Glad to see that there's some light up your head now. I2CWRITE/I2CREAD/SHIFTOUT.... SERIN/SEROUT... will work on any I/O since it's a software solution as Ralph said. It isn't the same as HSEROUT and HPWM wich use the specific PIC i/o.

    The beauty of PBP against another Basic compiler is that you can use/do as many I2C bus as you have free I/O. Hey, even if we still heard here and there that PBP is a dead/dummy/..../...../..../ language, it's still usefull

    Usually i don't share SCL line between I2C buss... kind of personnal safety feeling i guess... but it's working.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  32. #32
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by NavMicroSystems
    Steve,

    this would be an application for the 4066's we still have on the shelf ;-)
    Hehe CMOS blast from the past but still handy to have on-hand ...4051,4053,4066,4067 if my memory is still good. You know Ralph how i feel since that evenement... snif snif
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  33. #33
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Talking

    Hi Steve

    just forgotten 4016, 4052, 4097 , 4519 , 4554 ,and 4555...

    due to age ????

    Hi,hi

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  34. #34
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Oh at least caused by the age!!!

    When you'll have my age, if you leave long enough, you'll understand

    Of course nobody can't expect to be as old as Robert, but it's better like that after all.

    O.K. not a chat room here!
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  35. #35
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Steve, no money for you when I win the 6/49. Of course that means I have to buy a ticket first...

    Ralph, can I ask why you are using those chips? Can you give a very brief description what is happening please?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  36. #36
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Ok, I'm trying to read from the 2nd MCP23016 and it's not working smoothly. I display the word on an LCD, and bits seem to flicker sometimes. When I press a button, the corresponding bit turns on, but there are some 'free games' here and there.

    Taken from page 15 of MCP23016 datasheet:

    To read an MCP23016 register, the Master needs to follow the requirements shown in Figure 1-6. First, the
    device is selected by sending the slave address and
    setting the R/W bit to logic ‘0’. The command byte is
    sent after the address and determines which register
    will be read. A restart condition is generated and the
    device address is sent again with the R/W bit set to
    logic ‘1’. The data register defined by the command
    byte will be sent first, followed by the other register in
    the register pair.


    This is what I am doing, a simple loop:

    CYCLE:
    ' Set R/W bit to 0.
    I2CCTRL = %01000000
    I2CLOCB = $00
    I2CWORD = %0000000000000000
    I2CREAD I2CSDA,I2CSCL,I2CCTRL,I2CLOCB,[I2CWORD]
    ' Set R/W bit to 1.
    I2CCTRL = %01000001
    I2CREAD I2CSDA,I2CSCL,I2CCTRL,I2CLOCB,[I2CWORD]
    LCDOUT $FE,$94,BIN16 I2CWORD
    GOTO CYCLE

    I've removed the MCT6 and use a separate SDA line pulled up with 4.7K for each I2C device.

    Did I misunderstand the instructions?

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  37. #37
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Demon
    Ralph, can I ask why you are using those chips?
    Robert
    There are several reasons,
    - more flexibility due to one interrupt per 8bits
    - more flexibility in PCB Layout
    - Price and availibility over here
    ...

    Image of one of my universal 16bit I2C I/O boards
    Last edited by Demon; - 4th October 2016 at 18:14.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  38. #38
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Demon
    Ok, I'm trying to read from the 2nd MCP23016 and it's not working smoothly. I display the word on an LCD, and bits seem to flicker sometimes. When I press a button, the corresponding bit turns on, but there are some 'free games' here and there.
    Robert,

    we don't want to guess anymore, please post your full code and schematic.
    Last edited by Demon; - 4th October 2016 at 18:14.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



  39. #39
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    'define LOADER_USED 1
    ADCON1 = 7 ' A/D off, all digital

    ASM
    @ DEVICE PIC16F877, HS_OSC, WDT_OFF, PWRT_ON, BOD_ON, LVP_OFF, CPD_OFF, WRT_OFF, DEBUG_OFF, PROTECT_OFF
    ENDASM

    define OSC 20

    DEFINE LCD_DREG PORTA
    DEFINE LCD_DBIT 0
    DEFINE LCD_RSREG PORTA
    DEFINE LCD_RSBIT 4
    DEFINE LCD_EREG PORTB
    DEFINE LCD_EBIT 3
    DEFINE LCD_BITS 4
    DEFINE LCD_LINES 4
    define LCD_COMMANDUS 2000
    DEFINE LCD_DATAUS 50

    DEFINE I2C_SLOW 1
    DEFINE I2C_HOLD 1
    I2CSCL VAR PortD.1
    SDAISW1 VAR PortC.2

    LOCGPIO CON $00
    LOWWORD CON %0000000000000000

    I2CCTRL VAR BYTE
    I2CLOCB VAR BYTE
    I2CWORD VAR WORD
    CTRLIOW CON %01000000
    CTRLIOR CON %01000001

    GOTO START ' Bypass subroutines

    '--------------------------- SUB-ROUTINES ----------------------------

    RDISW1:
    I2CREAD SDAISW1,I2CSCL,I2CCTRL,I2CLOCB,[I2CWORD]
    PAUSE 12
    RETURN

    '-------------------------- MAIN PROGRAM -----------------------------

    START:
    PAUSE 2000
    LCDOUT $FE,1,"Program start"

    CYCLE:
    I2CCTRL = CTRLIOW
    I2CLOCB = LOCGPIO
    I2CWORD = LOWWORD
    GOSUB RDISW1
    I2CCTRL = CTRLIOR
    GOSUB RDISW1
    LCDOUT $FE,$94,BIN16 I2CWORD
    GOTO CYCLE

    END


    Circuit coming up.

    Robert
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

  40. #40
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default

    Circuit:

    Robert
    Attached Images Attached Images  
    My Creality Ender 3 S1 Plus is a giant paperweight that can't even be used as a boat anchor, cause I'd be fined for polluting our waterways with electronic devices.

    Not as dumb as yesterday, but stupider than tomorrow!

Similar Threads

  1. I/O extender
    By mychangl in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 20th November 2008, 14:56
  2. MCP23016 I2C serial I/O expander chip
    By GeoJoe in forum Serial
    Replies: 7
    Last Post: - 31st October 2007, 15:39
  3. MCP23016 I/O expander with PBP?
    By Jon Chandler in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd August 2005, 09:32
  4. I2C I/O Expander PCF8574 hanging?
    By NavMicroSystems in forum Serial
    Replies: 12
    Last Post: - 4th August 2005, 02:26
  5. managing the I/O ports of the 16F84A
    By skyler_91600 in forum mel PIC BASIC
    Replies: 7
    Last Post: - 28th April 2005, 03:52

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts