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

    The configs look OK.

    The PORTB.0 read looks OK.

    In my test, I did not have an MCP23016 connected, I was just testing the clk frequency with I2CWRITE at 48mhz. The MCP23016 is a 400khz device, so 250khz should not be a problem.

    The i2cdevice and I2Creg variables weren't shown. Are they both BYTEs?
    I assume they are, just asking.

    The only other possibility I can see is that the registers are configured as "Pairs", and all examples in the datasheet show reading or writing 2-bytes of data at a time. I don't see anything that says you can't read only 1-byte at a time, but then there's nothing that says you can either.

    So this is my last best guess...
    Try doing everything with 2 data bytes.
    Code:
    I2CWrite SDA,SCL,i2cdevice,I2Creg,[i2cbyte1, i2cbyte2],error
    If the address is for GP0 ($0), then i2cbyte1 should have GP0 and i2cbyte2 should have GP1.

    If the address is for GP1 ($1), then they will be reversed. GP1 in i2cbyte1 and GP0 in i2cbyte2.

    Both write and reads would need 2-bytes.
    And be sure to cycle power after changing it, in case it's still locked up.

    hth
    DT

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    The configs look OK.

    The PORTB.0 read looks OK.

    In my test, I did not have an MCP23016 connected, I was just testing the clk frequency with I2CWRITE at 48mhz. The MCP23016 is a 400khz device, so 250khz should not be a problem.

    The i2cdevice and I2Creg variables weren't shown. Are they both BYTEs?
    I assume they are, just asking.

    The only other possibility I can see is that the registers are configured as "Pairs", and all examples in the datasheet show reading or writing 2-bytes of data at a time. I don't see anything that says you can't read only 1-byte at a time, but then there's nothing that says you can either.

    So this is my last best guess...
    Try doing everything with 2 data bytes.
    Code:
    I2CWrite SDA,SCL,i2cdevice,I2Creg,[i2cbyte1, i2cbyte2],error
    If the address is for GP0 ($0), then i2cbyte1 should have GP0 and i2cbyte2 should have GP1.

    If the address is for GP1 ($1), then they will be reversed. GP1 in i2cbyte1 and GP0 in i2cbyte2.

    Both write and reads would need 2-bytes.
    And be sure to cycle power after changing it, in case it's still locked up.

    hth
    Thank you Darrel, thank you indeed
    You are a real and great PIC wizard!

    You have made me extremely happy...

    ...have been struggling with this problem too long, I'm very happy that it is solved "so easily", meaning that the error here was almost close to a syntax error.

    Who could have guessed in the first place that you need to read/write both data registers to get it working. Is this said somewhere in the data sheet? If so, it has not caught my eye.

    This does slightly complicate the code for me, it would have been very handy if one could read the ports separately, but no big deal, not a real problem...

    THANK YOU again for helping me out of my desperate situation with this "strange" MCP23016 behavior...

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


    Did you find this post helpful? Yes | No

    Thumbs up

    WooHoo!

    Pulled one out of my asparagus that time.

    Thanks for sticking with it keymuu!

    CYA round,
    DT

Similar Threads

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