I2C CONFUSION, Help needed please


Closed Thread
Results 1 to 40 of 43

Hybrid View

  1. #1

    Exclamation I2C CONFUSION, Help needed please

    I am trying to communicate with an I2C device. I have done almost everything I could think of but it is not working. The manual mentions stuff but not exactly matching with the datasheet of the device. The device datasheet mentions something about ACK/NACK which the pbp manual does not mention even once. On top my lack of understanding of I2C has left me with no other option to ask here about what I am doing wrong.

    What I have done:
    I have tried the following commands:
    Value var byte
    I2CREAD SDA,SCL,%000110100,0,[Value] ' Tried this
    I2CREAD SDA,SCL,$1B0,0,[Value] ' Tried this
    I2CREAD SDA,SCL,$1B,0,0,[Value] ' Tried this

    Then When I do this:
    debug HEX Value ' I am expecting '2E' on my screen. But I am not getting it.
    (Location Zero will read 2E in the device)

    I attach the section explaining the I2C from the datasheet. The device address is $1B.
    Many thanks in advance

    (Using 16F688 @ 4 MHz)
    Attached Images Attached Images  
    Last edited by FromTheCockpit; - 27th July 2013 at 01:19. Reason: INFO

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Did you put the two pull-up 4.7k resistors in the SDA and SCL lines?

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Also, you don't need to worry about anything that you highlighted in red. The I2CREAD and I2CWRITE commands take care of that for you.

    Robert
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Quote Originally Posted by rsocor01 View Post
    Did you put the two pull-up 4.7k resistors in the SDA and SCL lines?

    Robert
    Yes, pull ups are there @ 3.2k.
    I tried the statement : I2CREAD SDA,SCL,$1B,0,[VALUE] (is it correct? because I don't had any luck)

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    My Code is this:
    Include "modedefs.bas"
    DEFINE OSC 4

    #CONFIG
    ifdef PM_USED
    device pic16F688, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
    else
    __config _XT_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_ON & _CP_ON & _CPD_ON & _BOD_ON & _IESO_ON & _FCMEN_ON
    endif
    #ENDCONFIG

    DEFINE DEBUG_REG PORTC
    DEFINE DEBUG_BIT 3
    DEFINE DEBUG_BAUD 2400
    DEFINE DEBUG_MODE 1

    DEFINE I2C_SLOW 1
    'DEFINE I2C_HOLD 1
    '-----------------------------------------------------
    PORTA=0
    PORTC=0
    TRISA = %000100
    TRISC = %110000
    CMCON0 = 7
    ANSEL = 0
    OPTION_REG = 128
    INTCON=128
    '-----------------------------------------------------
    Value Var word
    '------------------------------------------------------------
    SCL Var PortC.5
    SDA Var PortC.4
    Change Var PortA.2
    LED Var PortC.0
    '---------------------------------------------------------
    Pause 500
    DEBUG "Start......",13,10
    value=0

    Main:
    High Led : Pause 1000: Low Led : PAUSE 1000

    I2CREAD SDA,SCL,$1B,0,[VALUE],Fail
    PAUSE 25
    DEBUG HEX Value,13,10
    PAUSE 250
    DEBUG "Done....",13,10
    Goto Main

    Fail:
    toggle portc.2
    goto main
    PortC.2 keeps toggling along with normal LED.

    I have also attached the device datasheet. I really appreciate the help in this.
    Attached Images Attached Images

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

    From PBP manual about I2CREAD:

    "Constants should not be used for address..."

    Don't know if this can help.

    Robert
    Last edited by Demon; - 27th July 2013 at 13:46.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    Quote Originally Posted by Demon View Post
    From PBP manual about I2CREAD:

    "Constants should not be used for address..."

    Don't know if this can help.

    Robert
    I added two bytes - Addr & Loc
    Addr=$1B
    Loc=0

    Sent - I2CREAD SDA,SCL,Addr,Loc,[Value],Fail

    No Luck

    '-----------
    What is also confusing me is the control byte in the manual, the device datasheet does not mention any control byte.
    I have an address $1B which I am sending as control and location in the device is being sent as Address according to the manual.
    Last edited by FromTheCockpit; - 27th July 2013 at 16:18. Reason: More info

  8. #8
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default Re: I2C CONFUSION, Help needed please

    The device you are using is a fast mode device (400 khz) so you have to remove the "DEFINE I2C_SLOW 1" and very likely you have to increase your clock speed (4 MHz could be too slow). Also change the variable into byte (you are using word).

    Good luck

    Al.
    All progress began with an idea

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