I2C and MCP23016


Closed Thread
Results 1 to 20 of 20

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    A quick test here on a 4550 at 48mhz, shows ~250khz clk.

    For the configs, I didn't know you were using the USB bootloader. The configs will be whatever the bootloader was programmed with. You'd probably need to read back the chip to find out what configs are set.

    I was hoping for more of the program, there's a lot of stuff missing, and you never know, 1 statement could change everything.

    Since you are getting all 0's. Maybe you should just try to read the RB0 pin without I2C, as a test. There's a pull-up on it, if you only read a 0, then something's still not right.
    <br>
    I'm note anymore sure about anything...

    When I use the following code to show things:

    LCDOUT cmd,home3, dec battery/10, ".",dec battery//10,"V ",dec w/100," ", dec onoffpressed, _
    cmd,home4, hex2 portb.0, " ", hex2 IOEbyte," ",cmd,home1

    I can see on row 4 = 01 00, RB0=1 !! IOEbyte should show the button press on P1.0 but NO it does not come through
    Took PIC of the PCB and read it with meProg and attached it here.

    By the way, the ~250kHz that you got, are you absolutely sure that you communicated with the MPC23016 device? I'm just wondering because I have an impression from the datasheet of MCP23016 that it couldn't run that fast... Is my impression wrong?
    Attached Images Attached Images  

  2. #2
    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

  3. #3


    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...

  4. #4
    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, 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