I2C CONFUSION, Help needed please


Closed Thread
Results 1 to 40 of 43

Hybrid View

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

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Picked up from the datasheet of the device. That is what I understood, am I wrong?
    Though I did tried $3B & $5B.

  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

    Not sure if you're wrong or not. I'm still trying to decipher that part in the datasheet because they don't make it easy. I've found that some information has to be gleaned from other devices of the same manufacturer to put the whole story together, kinda sucks!

    I also noticed the address stays at $1B after the first loop in your test program and if it works you might miss it.

    Note: I just found one of my programs on another I2C device that has bit 1=0 as the Write bit.
    $1B = $00011011 used for Read
    $1A = $00011010 used for Write
    Last edited by LinkMTech; - 27th July 2013 at 17:37.
    Louie

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    I read it again to confirm this, the attachment is my source. It also mentions 9 bits long address. Not sure who sends an ack. I see that in read statement the device send ack, so why add it to the address PIC is sending. Very confusing.
    Attached Images Attached Images  

  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

    Ahhhh... okay
    Let's use this info then. Looks like the address is using bits 1~7 and the Read/Write control bit is 0.
    If control bit is set (=1) then Read, if bit cleared (=0) then Write

    So:
    %00110111 = $37 ' Read function
    %00110110 = $36 ' Write function

    Try that.

    By the way, the device sends the ACK, or acknowledges, by holding the Data line LOW on the 9th clock cycle. The PIC will see this and continue to send data.
    Louie

  6. #6


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Quote Originally Posted by LinkMTech View Post
    By the way, the device sends the ACK, or acknowledges, by holding the Data line LOW on the 9th clock cycle. The PIC will see this and continue to send data.
    How do I implement this, like this below?
    Code:
    Main:
    High Led : Pause 500: Low Led : PAUSE 500
    	Addr=$36
    	I2CWRITE SDA,SCL,ADDR,LOC
    	Addr=$37 : pause 10                    ' OR If SDA=1 then main 
    	I2CREAD SDA,SCL,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

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

    Just notice the address missing on the Read function.
    Moved the Fail label after Write to test this part first. This will let you know if the Write address was recognized so the Pause 10 is not needed.


    Code:
    Main:
    High Led : Pause 500: Low Led : PAUSE 500
    	Addr=$36
    	I2CWRITE SDA,SCL,ADDR,LOC, Fail  ' Test here first
    	Addr=$37 ': pause 10                    ' OR If SDA=1 then main 
    	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
    Louie

  8. #8
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Quote Originally Posted by LinkMTech View Post
    ...
    %00110111 = $37 ' Read function
    %00110110 = $36 ' Write function
    ..
    I would have thought:
    %00000001 = $37 ' Read function
    %00000000 = $36 ' Write function

    I don't see in this datasheet where you get the rest.

    Robert

  9. #9


    Did you find this post helpful? Yes | No

    Default Soooooo Close

    I just discovered, that the I am actually receiving only 1 byte as expected. Rest are just "Start......"13,10 and "Done",13,10. Yesterday got too exhausted and missed this mistake of mine.

    Here is the current code with
    Code:
    Start:
    Loc=0
    
    Start_Again:
    	I2CWRITE SDA,SCL,$36,[LOC],Fail1
    
    Main:
    	Value=0
    	High Led : Pause 500: Low Led : PAUSE 500
    	I2CREAD SDA,SCL,$37,[VALUE] ,Fail2
    	PAUSE 250
    	DEBUG  Value
    	Loc=Loc+1
    	If Loc<4 then Start_Again		' Read first 4 locations
    	x=0
    
    WHILE !Change			' Stay here if Change Stays High
    		 Pause 500  : x=x+1
    		If x =10 then 
    			LOC=3 : Goto Main ' Do another read
    		Endif			
    WEND
    while Change : pause 100 : wend	' Stay here if change is Low
    Goto Start
    
    Fail1:					' Try Write again
    	For x=0 to 50
    		High Portc.2 : Pause 50 : Low PortC.2 : Pause 50
    	Next x
    Goto Start_again
    
    Fail2:					' Try read again
    	For x=0 to 5
    		High Portc.2 : Pause 250 : Low PortC.2 : Pause 250
    	Next x
    Goto Main
    Every time Change line goes low (detected something), I try to read first 4 memory locations. The communication fails a lot of times (both write and read (write more than read) )in this attempt but I do get the data on the screen finally. Secondly, the data which comes is wrong. For example, memory locations 0 does not read 2E for a start.

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