I2C CONFUSION, Help needed please


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1


    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

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

  3. #3


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Checked it. It fails on the first write statement.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Fails on the second statement if I swap the values of Addr. i.e. First $37, second Addr $36. First one goes fine.

  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

    Checked it. It fails on the first write statement.
    Okay let's fix that first.
    Put brackets around the Loc as shown in the PBP manual to see if that helps.
    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
    Last edited by LinkMTech; - 27th July 2013 at 19:56. Reason: Reply timing!
    Louie

  6. #6


    Did you find this post helpful? Yes | No

    Default Reaching there

    I did exactly the same as above and the sequence completed fine. BUT the values are not consistent with the datasheet, I should get '$2E' from location 0, but WHATEVER location I try to read, I am getting '$FF'

  7. #7


    Did you find this post helpful? Yes | No

    Default Update

    Have a look at my real term serial monitor. I am actually getting a lot of unexpected data which I don't understand how is getting stored in just one byte. Though among all this, I can see '2E' (but it is swapped around so 'E2'). Note sure if I am trying to convince myself or the data is rubbish.
    Attached Images Attached Images  

  8. #8


    Did you find this post helpful? Yes | No

    Default Re: Update

    Better in nibble setting. I can see '2E' repeated a few times.
    Attached Images Attached Images  

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