I2C and MCP23016


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Since you are using an 18F4550, it means you are using MPASM as the assembler.
    So, DEFINE i2c_hold 1 needs to be Uppercase.

    You can read back every register except one (INTCAP). I do not know what fails, read or write
    Not sure what you mean here. The INTCAP? registers are read-only.

    Also not sure what you are trying to do with the port.
    You write all 1's to the output latch OLAT1, then set all but 1 pin to input IODIR1, then write to GP1 which actually writes to OLAT1 again. Doesn't make sense.

    What is it you're trying to do, and what's not working.
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Since you are using an 18F4550, it means you are using MPASM as the assembler.
    So, DEFINE i2c_hold 1 needs to be Uppercase.

    Not sure what you mean here. The INTCAP? registers are read-only.

    Also not sure what you are trying to do with the port.
    You write all 1's to the output latch OLAT1, then set all but 1 pin to input IODIR1, then write to GP1 which actually writes to OLAT1 again. Doesn't make sense.

    What is it you're trying to do, and what's not working.
    Thank you Darrel!

    I changed it, so now I have DEFINE I2C_HOLD 1...
    but that did not change anything.

    With INTCAP I just wanted to say that it is the only register that is read-only, besides it was kind of irrelevant from me to mention that in the first place

    The final goal is to use the device as an input extender, that is only inputs. However, one should also be able to read and write all registers, except one. Nothing seems to work, as earlier told, I can't tell if it is the write or read that fails. I have tried all kind of values and also changing the sequence of those three initializing lines but without any sign of life. Well, of course maybe some kind of quiet life when not the error label is activated.

    What values would you suggest to use in the initialization section and what sequence would you use for those three init lines?

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    I think it's probably working, but you don't realize it.

    In your code, the only thing you're reading is GP1, and prior to that it writes to GP1, so you're thinking you should read the same value back.

    But when you write to GP1, the value is actually written to OLAT1.
    Reading GP1 reads the state of the pins, not what was written to GP1.
    <br>
    DT

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    I think it's probably working, but you don't realize it.

    In your code, the only thing you're reading is GP1, and prior to that it writes to GP1, so you're thinking you should read the same value back.

    But when you write to GP1, the value is actually written to OLAT1.
    Reading GP1 reads the state of the pins, not what was written to GP1.
    <br>
    Thanks, I really hoped you were right, but sorry...
    I tested it with the following code:
    Loop:
    I2Creg = OLAT1 : I2Cbyte = $ff : gosub writeioextender: pause 20
    I2Creg = IODIR1 : I2Cbyte = $ff : gosub writeioextender: pause 20

    I2Creg = olat1 : gosub readioextender: pause 20
    LCDOUT hex2 ioebyte, " "
    I2Creg = gp1 : gosub readioextender: pause 20
    LCDOUT hex2 ioebyte, cmd,home1
    if onoffpressed = 1 then powerout = 0
    goto Loop

    I have a button on GP1.0 (pin 2) that is pressed or not, on the LCD one can only see 00 00, nothing else. I think this demonstrates that you can not write OLAT1 or read it, it also shows that a button press does not come through, or perhaps the GP1 is not initialized correctly. Tested also to write IODIR1 first but with the same result...

    How should one initialize the chip with all pins as inputs?

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    When you get all 0's, it usually means one of two things.

    1) The SDA,SCL pins still have the analog mode enabled.

    2) There aren't any pull-ups, or they pull-down.

    If you have a voltmeter, check the voltage on the SDA,SCL pins.
    They should be above 4V when no data is being transfered.

    But I'm betting on analog mode.
    <br>
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    When you get all 0's, it usually means one of two things.

    1) The SDA,SCL pins still have the analog mode enabled.

    2) There aren't any pull-ups, or they pull-down.

    If you have a voltmeter, check the voltage on the SDA,SCL pins.
    They should be above 4V when no data is being transfered.

    But I'm betting on analog mode.
    <br>
    As said in post 1#, both (SCL and SDA) are pulled up with 2 2k2 resistors, one for each. So when the lines are inactive you can measure 4,98V there, so that suggest also that the problem has to be somewhere else. I have also looked with an oscilloscope on the active signals, but being not so familiar with the inner live of the I2C protocol, can't tell if there would be something wrong, to me they look "normal". From the clock line I could calculate a clock frequency of something around 65kHz +/-20%. Is that OK?

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Then it must be 1).

    Put this line at the top of your program.

    ADCON1 = $F ; set all pins to digital
    <br>
    DT

Similar Threads

  1. MCP23016 I2C serial I/O expander chip
    By GeoJoe in forum Serial
    Replies: 7
    Last Post: - 31st October 2007, 15:39
  2. MCP23016 missing D7 on I2CRead
    By TWSK in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th June 2007, 18:37
  3. Using I2C with FullSpeed USB
    By Demon in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 8th July 2006, 04:52
  4. MCP23016 I/O expander
    By Demon in forum mel PIC BASIC Pro
    Replies: 42
    Last Post: - 24th October 2005, 01:01
  5. MCP23016 I/O expander with PBP?
    By Jon Chandler in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 22nd August 2005, 09:32

Members who have read this thread : 0

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