I2C CONFUSION, Help needed please


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    I thought I saw 9 bits used from control in the datasheet you linked.

    Maybe you're supposed to use a word and ignore the other 7 bits? Or that could be handled by PBP for I2C?

    Do you get only a byte back, word, multiple bytes?

    Your circuit does make address 0 right?

    (just throwing ideas at you)

    Robert

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Steps Taken:

    1) Configuration changed: _INTRC_OSC_NOCLKOUT
    2) Made 16f688 run at 8MHz : OSCCON=%01110001
    3) Commented DEFINE I2CSLOW 1
    4) Value changed to BYte (then to word again)

    I get a byte back from the device (from what I have understood). Yes there is an address 0 in the device. I should get back chip ID i.e-'2E' as per the datasheet.

    Still no Luck.

  3. #3
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    I couldn't find detailed info on the Write/Read bit of the device address. But I will guess it is bit 7.
    You need to Write to the device first using the address with the "Write" bit set.
    $1B or %00011011 becomes $9B or $10011011

    Without confirming the proper syntax of the commands, here's something off the top of my noodle:

    This will cover steps 1~4 of Section 4.3.2 of the datasheet
    Code:
    I2CWRITE SDA,SCL,[Addr,Loc,]  ' Addr plus Write bit = $9B

    This will cover steps 5~7 of Section 4.3.2 of the datasheet
    Code:
    I2CREAD SDA,SCL,[Addr,Loc]   ' Addr plus Read bit = $1B
    Putting it together should get you moving in the right direction.
    Code:
    I2CWRITE SDA,SCL,[Addr,Loc,]  ' Addr plus Write bit = $9B
    I2CREAD SDA,SCL,[Addr,Loc]   ' Addr plus Read bit = $1B
    Here's a note to myself that might come in handy too:
    Attached Images Attached Images
    Last edited by LinkMTech; - 27th July 2013 at 16:53. Reason: Added I2C screen shot notes
    Louie

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Tried this:

    Code:
    Pause 500
    	DEBUG "Start......",13,10
    Value=0
    Addr=$9B
    Loc=0
    
    Main:
    High Led : Pause 500: Low Led : PAUSE 500
    	I2CWRITE SDA,SCL,ADDR,LOC
    Addr=$1B : PAUSE 50
    	I2CREAD SDA,SCL,ADDR,LOC,[VALUE],Fail
    	PAUSE 25
    	DEBUG  HEX Value,13,10
    	PAUSE 250
    	DEBUG "Done....",13,10
    WHILE 1 : WEND
    Goto Main
    
    Fail:
    	toggle portc.2
    goto main
    Didn't worked. (Value/Addr/Loc = Byte size)

    '=======
    Can I not the Micro at 4MHz? The Datasheet says MAX speed is 400KHz, so I assume lower speeds are supported. Am I right?
    Last edited by FromTheCockpit; - 27th July 2013 at 17:00.

  5. #5
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Remove the PAUSE 50 after I2CWRITE because the device starts sending immediately if its happy.

    Then try bit 6 then 5 instead for the Write bit if the Write bit position was a wrong guess.
    Bit 6 = $5B
    Bit 5 = $3B
    Last edited by LinkMTech; - 27th July 2013 at 17:03. Reason: Remove Pause
    Louie

  6. #6
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Yeah, 400kHz is the max speed so at 4MHz it will run closer to 100kHz
    Louie

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    OSCCON changed to set 4MHz, internal oscillator.
    I2CSLOW 1 stays commented
    I2CHOLD 1 stays commented
    Code:
    LED 	Var PortC.0
    Value Var 	Byte
    Addr	Var	Byte
    Loc 	Var	Byte
    '---------------------------------------------------------
    Pause 500
    	DEBUG "Start......",13,10
    Value=0
    Addr=$9B 'Tried $3B,$5B
    Loc=0
    
    Main:
    High Led : Pause 500: Low Led : PAUSE 500
    	I2CWRITE SDA,SCL,ADDR,LOC
    	Addr=$1B
    	I2CREAD SDA,SCL,ADDR,LOC,[VALUE],Fail
    	PAUSE 25
    	DEBUG  HEX Value,13,10
    	PAUSE 250
    	DEBUG "Done....",13,10
    WHILE 1 : WEND
    Goto Main
    
    Fail:
    	toggle portc.2
    goto main
    No Luck

    > It is bit 7 for R/W (Slave address + write bit)
    Last edited by FromTheCockpit; - 27th July 2013 at 17:17.

  8. #8
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    > It is bit 7 for R/W (Slave address + write bit)

    How did you find that?
    Louie

Similar Threads

  1. Sample code for I2C text LCD needed
    By Alexey in forum Code Examples
    Replies: 4
    Last Post: - 15th September 2011, 01:29
  2. TMR0 Confusion
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th August 2011, 11:55
  3. HPWM confusion
    By lerameur in forum General
    Replies: 12
    Last Post: - 5th November 2006, 10:09
  4. HPWM confusion
    By rossfree in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd November 2005, 16:50
  5. DIV32 confusion
    By dmairspotter in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 7th October 2005, 21:24

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