I2C Slave with a PIC


Closed Thread
Results 1 to 40 of 130

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Location
    Southern California
    Posts
    17


    Did you find this post helpful? Yes | No

    Talking It works!

    Guys,

    This weekend I put together software nuggets from both DaveC3 and BigWumpus. In doing so, I could see the influence of most of you that have been working on this thread over the last few weeks. I went through and trimmed out the dead code, and moved a few things around to work for my uses. I'll post both the master and slave(s) in the next day or two so others can learn from our efforts! Thanks to everyone for taking on this tough problem.

    Thanks,
    rswain

  2. #2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by rswain View Post
    Guys,

    This weekend I put together software nuggets from both DaveC3 and BigWumpus. In doing so, I could see the influence of most of you that have been working on this thread over the last few weeks. I went through and trimmed out the dead code, and moved a few things around to work for my uses. I'll post both the master and slave(s) in the next day or two so others can learn from our efforts! Thanks to everyone for taking on this tough problem.
    Hey rswain!

    Any news about this?

    Thanks!

    Daniel.

  3. #3
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default I2C SLave in a 18F6722

    Hi all,
    wanted to come back earlier with my experiences, but had too much work.
    But :
    I use Al's i2cslave in an 18F6722 I in an interrupthandler, in Al's code i made a little correction:

    while STAT_BF = 1
    i = SSP1BUF ' Dummy Read inserted => clears BF Flag
    wend ' loop while buffer is full

    This seems to be neccessary for this PIC's, the original code from Al results in
    staying in this loop for ever.

    I read back eight variables and write two variables with no problems.
    The master and the slave have both the " DEFINE I2C_HOLD 1" at start up.

    Regards,
    Ralf

  4. #4
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default i2c slave with 18F14K22

    Hi again,
    did somebody test Al's code with a 18F14K22?
    Regards,
    Ralf

  5. #5
    Join Date
    Nov 2008
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    There is an other problem with the i2cslave:

    1. When the i2caddress is specifiead as constant (i2caddress CON $0F) it works perfect.

    2. When bulding the address via a variable, it doesnt work:
    ...
    i2caddress VAR byte
    ...
    i2caddress = $0F

    I need this because i build it from the status of four bits of Port A

    Any idea?

    Regards,
    Ralf

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


    Did you find this post helpful? Yes | No

    Default

    I need this because i build it from the status of four bits of Port A

    Any idea?

    Ralf, you can try this:

    Code:
    
    
    Select Case PortA
    
    Case 1
    i2caddress CON $01
    Case 2
    i2caddress CON $02
    case 3
    i2caddress CON $03
    .
    .
    .
    .
    Case x
    i2caddress CON $x
    End Select
    It should work.

    Edited:

    No! it doesn't work sorry.

    Al.
    Last edited by aratti; - 25th March 2010 at 13:19.
    All progress began with an idea

  7. #7
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    ralfmayr, Here is what I have been using for years. It uses the base address for the first of 3 PCF8574's. I then calculate the address depending on the one I need to gather or send data to.

    UNIT0 CON %01000000 'U5's CONTROL BYTE (PCF8574) I/O EXPANDER

    '**************** I2C I/O ROUTINE (PCF8574A) I/O EXPANDER ************
    READ_WRITE VAR BIT 'READ DATA or WRITE DATA FLAG
    EXPAND_UNIT VAR BYTE 'CONTROL BYTE FOR I2C
    DEVICE VAR BYTE 'SELECTED I/O EXPANDER DEVICE
    OUTPUTS VAR BYTE[3] 'RELAY OUTPUT BYTES
    SWITCHES VAR BYTE[3] 'SWITCH INPUTS BYTES

    '************************************************* *******************
    R_WI2CS:'READ DIGITAL INPUTS FROM or WRITE DIGITAL OUTPUTS TO PCF8574'S
    '************************************************* *******************
    EXPAND_UNIT = UNIT0 'COPY BASE ADDRESS OF PCF8574'S
    EXPAND_UNIT = (EXPAND_UNIT | (DEVICE << 1)) 'SELECT WHICH DEVICE
    IF READ_WRITE = 0 THEN 'READ INPUT STATUS FROM PCF8574'S
    I2CREAD SDA,SCL,EXPAND_UNIT,[SWITCHES(DEVICE)]
    ELSE 'SET OUTPUT STATES TO PCF8574'S
    I2CWRITE SDA,SCL,EXPAND_UNIT,[OUTPUTS(DEVICE)]
    ENDIF
    RETURN


    Then to use it first set the device index.
    Next set the read_write flag.
    Then finally call the routine.....

    Dave Purola,
    N8NTA

Similar Threads

  1. Problem with PICto PIC I2C MASTER-SLAVE
    By juanen19 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 11th June 2013, 02:58
  2. PIC as I2C Slave
    By Mainul in forum General
    Replies: 4
    Last Post: - 5th January 2013, 13:23
  3. I2C Slave, config Vref - + in pic with ADC
    By sebapostigo in forum PBP Wish List
    Replies: 4
    Last Post: - 5th March 2007, 03:21
  4. Pic as an i2c slave
    By Robert Soubie in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th January 2007, 21:11
  5. Use pic as slave in I2C
    By robert0 in forum General
    Replies: 2
    Last Post: - 3rd February 2006, 19:26

Members who have read this thread : 2

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