Announcement

Collapse
No announcement yet.

I2C communication

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • I2C communication

    I'm using a PIC 16F616. I need to communicate with an I2C device (humidity sensor). How do I initiate a I2C start? or Stop? Does the processor do this autmatically?

    Does anyone have example code?

    Joe Rapoza

  • #2
    Hi Joe,

    The I2CREAD/I2CWRITE commands handle all the start/stop/ack bit's.
    You don't need to do it manually.
    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
    Never download a PIC datasheet from anywhere but microchip.com

    Comment


    • #3
      Thanks Darrel as always you have been a great help

      Comment


      • #4
        Originally posted by joerapoza View Post
        Thanks Darrel as always you have been a great help
        Darrel, I have run into more problems in my endeaver to code IsC commuications. ie in trying to compile I received syntax errors.. What I wrote:

        I2CWRITE PORTA.1 PORTC.1 $27, $AO, [$00, $00]

        Write, PortA.1 is SDA pin, Portc.1 is clock pin, $27 is the address of the device I'm writing to, AO is the command to set the device in command mode, and the 2 bytes $00 are to keep the ClockPin active to receive 2 bytes of data.

        The errors are in syntax (compiler response)

        Joe Rapoza

        Comment


        • #5
          Joe,

          You need some more commas in there.
          Code:
          I2CWRITE PORTA.1, PORTC.1, $27, $A0, [$00, $00]
          and the 2 bytes $00 are to keep the ClockPin active to receive 2 bytes of data.
          That's not going to work.
          I2CWRITE does not receive anything.
          You would need I2CREAD to receive data.
          PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
          Never download a PIC datasheet from anywhere but microchip.com

          Comment


          • #6
            Hi Darrel,

            I put in the commas a you suggested. The 2 bytes 0x00 are to keep the clock going so the humidity sensor I am communicating with can store the info in it's own EEPROM so it can be retrieved with a I2CREAD.

            Still getting a syntax error ie Syntax error 78

            Help!

            Comment


            • #7
              You have $AO, with the letter O.
              Change it to a 0 (zero).
              PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
              Never download a PIC datasheet from anywhere but microchip.com

              Comment


              • #8
                How could you see that? Change to 0(zero), it works!!!!

                Thanks very much.

                Joe Rapoza

                Comment

                Working...
                X