I2C Read/Write problems


Closed Thread
Results 1 to 24 of 24

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    I have tried just putting myvar instead of myvar.lowbyte and myvar.highbyte in there. So, I'm guessing I need to turn the comparators off?

    ANSEL = %00000000
    CMCON = %00000111

    ???

    Any suggestions on how to get the correct device address sent ($10), and read the address $22?

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


    Did you find this post helpful? Yes | No

    Default

    You already have a LCD attached to it... why not monitor the HEX value of the WORD variable using HEX4

    Not sure if the optional label jump work with I2CREAD and your external device...
    Last edited by mister_e; - 2nd April 2008 at 20:03.
    Steve

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

  3. #3
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Dispersion123 View Post
    Any suggestions on how to get the correct device address sent ($10), and read the address $22?
    If the device address is $10 then doesn't the address have to be left shifted one place?

    $10 = %00010000

    PBP handles the R/W bit (bit.0), so your sending out address %0001000R (Read or Write bit) and the address "seen" by the receiving device is %00001000

    Remember that I2C device addresses are shifted left one place to allow for the read/write bit. You'll never (edit: never say never - there are 10 bit addressing in some devices, though this is not part of the original I2C design data) see an I2C device address over $7F, or %01111111 or DEC127.

    So, I think you should be using the DEVICE ADDRESS of $20
    Last edited by JD123; - 2nd April 2008 at 23:10.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

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


    Did you find this post helpful? Yes | No

    Default

    Doesn't sounds right to me... how about most I2C EEPROM with $A0?
    Steve

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

  5. #5
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    Doesn't sounds right to me... how about most I2C EEPROM with $A0?

    Sorry, I overlooked your post. Are you seeing what I'm saying?
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

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


    Did you find this post helpful? Yes | No

    Default

    Not sure... sure i misunderstand what you said.
    Code:
            addr var word
            CTL CON $A0
            addr=$F0F0
    
    SendIt:
            I2CWRITE PORTD.6, PORTD.7,CTL,addr,[$F1F2]
            pause 50
            goto sendit
    will looks like...
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2461&stc=1&d=120717761 2">

    But yeah.. on some device, the Address can be mixed with the ControlByte. EEPROMs such as some 24C04, c08 and c16 work like that.
    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=2462&stc=1&d=120717799 9">

    They call it page select (sort of)... those Px bits...

    NOTE: well it's not a 24lc64screenshot but anyways.
    Attached Images Attached Images   
    Last edited by mister_e; - 3rd April 2008 at 00:30. Reason: Datasheet 24Cxx
    Steve

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

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JD123 View Post
    If the device address is $10 then doesn't the address have to be left shifted one place?
    I thought PBP handled that part for you. 'cause with a generic serial eeprom, the address is something like $a0, and that's how you address it...$a0, without the left shift, PBP handles the R/W bit.
    But then again, we don't know exactly what kind of secret magic device is being addressed here...

  8. #8
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I thought PBP handled that part for you. 'cause with a generic serial eeprom, the address is something like $a0, and that's how you address it...$a0, without the left shift, PBP handles the R/W bit.
    But then again, we don't know exactly what kind of secret magic device is being addressed here...
    $A0 is the LOWER 7 bit's of the address, shifted left one place. The DEVICE address being sent out and 'seen' by the reciever is %01010000, or $50. Check the specs of I2C, not just EEPROMS. The device address is specified as a 7 bit address, not 8. But since we are adding the R/W bit to the 8 bit address byte, we have to left shift the DEVICE address one place.

    The confusion comes in dealing with 2 different data "specs" or "types" combined into one 8 bit Byte being send. Then suming the two values to "use" one value. That "one" value is not the device address.

    You ever do this: (I know I have)
    Gang 8 64KBit EEproms and use the device address (bit 4:1) by just rolling the long address over directly into the device address. It won't work. Trust me, just shift the address left once to embed the address into the device address byte.
    Last edited by JD123; - 2nd April 2008 at 21:52.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  9. #9
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JD123 View Post
    The DEVICE address being sent out and 'seen' by the reciever is %01010000, or $50. Check the specs of I2C, not just EEPROMS. The device address is specified as a 7 bit address, not 8. But since we are adding the R/W bit to the 8 bit address byte, we have to left shift the DEVICE address one place........
    I guess that's what I'm saying here...is that PBP handles it for us.

    The confusion comes in dealing with 2 different data "specs" or "types" combined into one 8 bit Byte being send.
    Confusion say...Man who live in glass house...should dress in basement...

  10. #10
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    Confusion say...Man who live in glass house...should dress in basement...
    My spell checker wants another quarter and I'm too cheap to give it up!
    Last edited by JD123; - 2nd April 2008 at 22:04.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  11. #11
    Join Date
    Mar 2008
    Location
    Texas, USA
    Posts
    114


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I guess that's what I'm saying here...is that PBP handles it for us.
    No. it doesn't. PBP handles the R/W bit for us. We still have to give it the correct address, formated to the device address byte. That's why you send %10100000 and the reciever "sees" %01010000 as the device address.

    Now, if the receiving device specs say "send $xyz" then they have already formated the address for you. That still doesn't change the fact that the address is the upper 7 bits shifted right one place.
    Last edited by JD123; - 2nd April 2008 at 22:07.
    No, I'm not Superman, but I did stay at a Holiday Inn Express last night!

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by JD123 View Post
    No. it doesn't. PBP handles the R/W bit for us. We still have to give it the correct address, formated to the device address byte. That's why you send %10100000 and the reciever "sees" %01010000 as the device address.
    Ok, I'm smelling what your cooking... I'm pickin' up what you're layin' down...
    (what happens if we overclock that same PIC to 50Ghz to get really fast I2C? )

Similar Threads

  1. I2C Master/Slave 16F88/16F767 working code
    By DanPBP in forum Code Examples
    Replies: 2
    Last Post: - 23rd October 2012, 22:31
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. I2C Master Slave issues.
    By cpayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th March 2008, 19:33
  4. I2C slave
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th March 2008, 03:46
  5. Please help with i2cslave i2c slave
    By cycle_girl in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st December 2005, 13:55

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