I2C Slave with a PIC


Closed Thread
Results 1 to 40 of 130

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: I2C Salve with a PIC

    Excuse me for my English.
    How can I send data from a PIC 16F876 to four slaves
    using the I2C bus protocol, with the same address?
    Could you help me, a piece of code would be welcome!
    mimie64.

  2. #2
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: I2C Salve with a PIC

    I2C bus protocol requires unique addresses for each slave. Just code the address into each slave if you are building the slaves yourself of course.

  3. #3
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: I2C Salve with a PIC

    Thanks to all of you for your greath wok!

    ... just to avoid to have trouble in future and have a clear view of a new project, I have in plan to use the slave routine on almost 12 PIC of 18F2550 and one Master with 18F4550.

    The idea is that:
    I shall have the Master far from the first slaves at about two to three meters and the second slave is far from the first slave around 50 cm, and all other slaves are distanced 50 cm between them.

    At the end the total length shall be more than 10 meters. but less that 12 meters.

    Also, I would use the RJ45 connectors to make interconnection between the PCBs and use the preassembled CAT5 Ethernet patch cable to carry the supply voltage from the Master to the slaves.

    I have thinked to put on pin 1, 2 and 3 the VCC, on pin 4 the Clk, on pin 5 the Dat and on pin 6. 7 and 8 the GND?

    The lenght of the cables can be a problem?

    The idea to use the RJ45 with the CAT5 patch cable is good?

    Leo
    Last edited by Wirecut; - 27th March 2016 at 13:19. Reason: typo error
    Leo

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,696


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    WIKI I2C
    The maximum number of nodes is limited by the address space, and also by the total bus capacitance of 400 pF, which restricts practical communication distances to a few meters.
    CAT5 CAPACITANCE
    52pF / metre

    cat5 balanced cable / i2c unbalanced signal.
    cat5 characteristic impedence of 100 ohms is probably a big load for the i2c pins also.
    its not a good match , and won't go far

  5. #5
    Join Date
    Aug 2011
    Posts
    459


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    A regular CAT5 RJ45 has 4 twisted pairs, but they're not "in order"

    1,2 orange,orange/wht
    3,6 green,green/wht
    4,5 blue,blue/wht
    7,8 brown,brown/wht

    I'd pair the SDA and SCL signals each with a GND (ie 1=GND, 2=SDA, and 7=SCL, 8=GND) and use the others for PWR/GND.

    10 meters is a long way for a single-ended TTL level signal. They make I2C bus extenders for this sort of thing.

  6. #6
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    If I have correctly understand, the maximum length from the capacitance point of view is around 8 meters, but what shall be the maximum distance for the single ended TTL?

    Leo
    Leo

  7. #7
    Join Date
    Aug 2011
    Posts
    459


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    I don't think there's any good single answer to that... it's dependent on so many different things it's hard to make a general statement.

    Personally, I start getting nervous as soon as a signal leaves a board!

  8. #8
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    SDA and SCL are not good combination in one pair. Because of cross talk.
    Much better is to combine GND and SDA on ona pair, GND and SCL on second pair. But capacitance play big roll. Probably CLK must be driven, not with pull up. SDA should have strong pull up.
    But do not connect multiple GND on both sides, as that will create long loop antenna, probably...
    I thing, but maybe i'm wrong, best chanse to get it to work is:
    1. Pair GND and signal on 2 pairs for SDA and SCL, connect that ground only on output port of module.
    2. Use third pair for power
    3. Ground unused pair master, as GND for signals.
    Generally not good idea to run TTL signals out of boards.
    If you design master and slave's why not to go with RS485, half duplex or duplex?

  9. #9
    Join Date
    May 2013
    Location
    australia
    Posts
    2,696


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    Personally, I start getting nervous as soon as a signal leaves a board!
    me too

    spi can get that sort of distance but you need a cs signal for each slave

    I wonder if you used a pair of those 3v-5v level shifters back to back if they could act like a repeater ?
    could be a cheap solution

    wireless may be an option
    rfm69 modules and the like can get 300k bps over that range and a master slave setup is no too difficult

  10. #10
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    It will work fine - as long as the PICs are the only I2C devices on the bus. The I2C specification was written to deal with low-power devices that have no more than 2 mA drive. As a result, all the pull ups (in parallel) could be no smaller than 2.5K. Since a PIC pin will sink more than 20mA, you can use much smaller pull ups. If there are only two PICs on the bus, I regularly use a 1K pull up at each end, with 10 ohms in series (one at each end) to reduce ringing. Since your CAT-5 will be twisted pairs, use one wire of each pair as GND (and the other as SDA or SCL). You should have no trouble at distance of at least 50'. But if you do get errors, you can slow the I2C bus down to lower data rates.

    Be aware, however that any other non-PIC devices on the bus will probably not be able to drive such small pullups properly.
    Charles Linquist

  11. #11
    Join Date
    Feb 2007
    Posts
    37


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    Your tips are pushing me towards the RS485.
    The only trouble and not've never used before.

    I am somewhat concerned about the protocol to use.

    You have to give me a hint where to look to select the protocol that I could use?

    Leo
    Leo

  12. #12
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,170


    Did you find this post helpful? Yes | No

    Default Re: I2C Slave with a PIC

    If you have used serial RS232, then the RS485 is just the same. Only drivers (chips) are different. And the signal is TTL level from your controller to the RS485 driver.

    The RS485 is not a protocol, rather a low level electric specs of the medium. It does not care about how the data will be sent.

    So you really have not many concerns on this. Almost Plug and play.

    Ioannis

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, 03:58
  2. PIC as I2C Slave
    By Mainul in forum General
    Replies: 4
    Last Post: - 5th January 2013, 14:23
  3. I2C Slave, config Vref - + in pic with ADC
    By sebapostigo in forum PBP Wish List
    Replies: 4
    Last Post: - 5th March 2007, 04:21
  4. Pic as an i2c slave
    By Robert Soubie in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th January 2007, 22:11
  5. Use pic as slave in I2C
    By robert0 in forum General
    Replies: 2
    Last Post: - 3rd February 2006, 20: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