i2C with PIC16F87, need help


Results 1 to 12 of 12

Threaded View

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


    Did you find this post helpful? Yes | No

    Default Re: i2C with PIC16F87, need help

    Quote Originally Posted by Lazuli View Post
    ...
    The problem I am having is during compilation which halt on the instruction:
    SSPCON2 = 0
    ...

    I have used I2C a lot, mainly on 16F628, 16F877, MCP23016 and external eeproms, and don't recall having to bother with that instruction.

    Here are I2C-related instructions from one of my 16F628 programs. It reads from an MCP23016 I/O Expander, but the concept remains the same for all reads.

    Code:
    ...
    DEFINE  OSC 16
     
    DEFINE  I2C_SLOW    1               ' Access I2C device above 8MHz
    DEFINE  I2C_HOLD    1               ' Permit I2C device to hold clock line low
     
    pinSCL      VAR PortA.2
    pinSDA      VAR PortA.3
     
    varAddressI2C   VAR BYTE
    varCommandI2C   VAR BYTE
    varButtonsLeft  VAR WORD      ' MCP23016 chips have 16 I/O pins
     
    conInLeftAddr       CON %01000010      ' MCP23016 at hardware address "010"
    conGenPurpRegI2C    CON $00
    ...
    Main:
        varAddressI2C = conInLeftAddr
        varCommandI2C = conGenPurpRegI2C 
        I2CREAD pinSDA,pinSCL,varAddressI2C,varCommandI2C,[varButtonsLeft]
    ...
    Hope there's something in there that will help you get going.

    EDIT: One last thing, I have 4K7 1/4W pull-up resistors on SCL and SDA.
    Last edited by Demon; - 16th May 2011 at 01:18.

Members who have read this thread : 1

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