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

    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

  2. #2


    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?

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

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Then it must be 1).

    Put this line at the top of your program.

    ADCON1 = $F ; set all pins to digital
    <br>
    Copy-Pasted that ADCON1... and that could have helped but unfortunately it did not help, nothing changed
    The problem is somewhere else, but where?

    Does that 65KHz sound correct? On what frequency should the clock run under those two I2C routines (I2CREAD I2CWRITE), where could one find any info on that. Tried also DEFINE I2C_SLOW, but again without success... What can I do? The expander is kind of alive because it does not throw you to the error label....

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


    Did you find this post helpful? Yes | No

    Default

    No 65khz does not sound right, and ...
    It doesn't throw you to the error label because it always reads 0's on the pin.

    An ack from the device is a low pulse. As long as it sees a low when it expects an ack, it will never jump to the label.

    OK, it's time for you to pony up some of the info you've been leaving out.

    What are your CONFIGs?
    What cyrstal are you using?
    What DEFINE OSC are you using?
    What pins are the SCL and SDA on?

    And the rest of the code.
    <br>
    DT

  6. #6


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    No 65khz does not sound right, and ...
    It doesn't throw you to the error label because it always reads 0's on the pin.

    An ack from the device is a low pulse. As long as it sees a low when it expects an ack, it will never jump to the label.

    OK, it's time for you to pony up some of the info you've been leaving out.

    What are your CONFIGs?
    What cyrstal are you using?
    What DEFINE OSC are you using?
    What pins are the SCL and SDA on?

    And the rest of the code.
    <br>
    So, back to the basics.
    If not 65kHz is correct, then what should it be?

    If I change the device address from $40 to something else for ex. $45 it will throw the program to the error label. That behavior sounds "healthy", doesn't it?

    By CONFIGs you mean? See post #1
    The crystal is 12MHz
    DEFINE OSC 48
    The SDA,SCL pins are connected correctly to pins 33,34 + 2x 2k2 pull-ups
    Using also Microchip USB HID bootloader v2.2

    I2Creg = OLAT1 : I2Cbyte = $ff : gosub writeioextender: pause 20
    I2Creg = IODIR1 : I2Cbyte = $ff : gosub writeioextender: pause 20
    The current test loop is here:
    Loop:
    gosub getbattery
    if onoffpressed = 1 then powerout = 0

    I2Creg = GP1 : gosub readioextender' to IOEbyte
    pause 20

    lcdout cmd,home3, dec battery/10, ".",dec battery//10,"V ", dec w/100," ", _
    dec onoffpressed,cmd,home4, hex2 IOEbyte," "
    goto Loop

  7. #7
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by keymuu View Post

    By CONFIGs you mean? See post #1
    No look at this thread.
    http://www.picbasic.co.uk/forum/showthread.php?t=543
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

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


    Did you find this post helpful? Yes | No

    Default

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