Shop OBEX P1 Docs P2 Docs Learn Events
I2C slave — Parallax Forums

I2C slave

FrasseFrasse Posts: 11
edited 2006-01-27 16:39 in General Discussion
Can SX/B be used to create an I2C slave? The example shown in the Online Help only indicates it's I2C commands usage in a master setup.
If it can be used in a slave setup, does anyone have an example?
I'm especially·confused about how to address the master when supplying data as a response to a·request for data by the master. What address do you give the master? Do you have to provide I2CSTART and I2CSTOP or do you just do I2CSEND?
Any information would be appreciated.

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-01-26 15:09
    I am a bit uncertain if the SX/B will provide a Slave I2c, but the SX-28 or SX-48 can do it in Assembly language.
    It is possible to take a portion of Assembly language and insert it within SX/B code.

    The idea of 'addressing the master' is a bit confusing. While I2C has a 2 wire bus [noparse][[/noparse]plus ground], there is often one or more 'address pins' that tell the I2C slave that the master is using that particlar device. Some devices have only one 'address pin' and others might have as many as three [noparse][[/noparse]usually ram or eeprom].

    The actual software communication [noparse][[/noparse]if that is what you mean by addressing] is done through having an active high data line and an active high clock line. If the slave wants to slow down or delay the master, the clock line is 'pulled low' by the slave and the master recognizes this signal to suspend transmission until high again.

    I am not sure, but I believe that in some cases an ACK [noparse][[/noparse]acknowledge] may be sent by the slave to confirm receipt of a message.

    Conceptually speaking, I2CStart and I2cStop are controling the begining and ending of the serial clock line. I2CSEND moves data through the serial data line. Of course, the devil is in the details and nothing beats thorough study of what is I2C protocol and how it differs from the other serial protocols [noparse][[/noparse]like SPI and Microwire]. But don't get too bogged down in concepts because you are likely to find a particular device has to be taylored to.

    So, if you have a device in mind and a project, just try to use that to build a sucessful use. You will come to grips with both the concepts and the reality.

    Also, don't get confused with ONE-WIRE which has device addresses and even a CRC function. It is a quite ambitions distraction that seems only suited for a few particular applications [noparse][[/noparse]like a network of temperature gauges in a grain elevator or a chemical process].

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-01-26 15:35
    Hi Frasse, you are misunderstanding the I2C protocol somewhat. The master never has an address, a master is always the originator of a message and therefore is never addressed. What you are thinking of is a special version of I2C called multi-master, where there are multiple masters capable generating I2C communications on the bus. A master on a multi-master system can also act as a slave (this is where addressing the "master" comes in) in order to recive commands initiated by other masters on the bus. This is the most complicated variety of I2C becuase you must implement Bus Arbitration on each master so that when more than one master is trying to start communications at the same time, one (or more) of them backs off and releases the bus to wait for another time to try again.

    SX/B's commands do not implement either slave I2C or multi-master I2C, you will have to program them in assembly yourself. Take a look at Parallax's application notes for the SX on thier downloads page, it should help you get started implementing the extra functionality. Also here is a site that provides a general overview of the way I2C does what I describe above: http://www.esacademy.com/faq/i2c/

    There is·the official documentation on·the I2C protocol, but it is fairly long and Id have to hunt for it abit.·

    Here is the Parallax pdf·and code·for I2C.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 1/26/2006 3:54:17 PM GMT
  • ellizardellizard Posts: 106
    edited 2006-01-26 19:09
    Hi everibody

    Just for knoledge,
    it striked my eyes today that in the help page for the I2C commands of SxB, there is a minor but potentially serious printing error:
    it say.....


    Pin defines the SDA pin of the I2C bus. Pin may any IO pin except RA.3 (RA.7 on the SX52), RB.7, RC.7, RD.6, or RE.6 (see below).

    should not it be something like this?

    Pin defines the SDA pin of the I2C bus. Pin may be any IO pin except RA.3 (RA.7 on the SX52), RB.7, RC.7, RD.7, or RE.7 (see below).

    Warmest regards
    Stefano

    post edited minor english sintax errors

    Post Edited (ellizard) : 1/26/2006 7:16:42 PM GMT
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-01-26 19:21
    post edited minor english sintax errors
    Sintax, isn't that what they put on alcohol and cigarette sales? tongue.gif (jk I know you mean syntax).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 1/26/2006 7:27:09 PM GMT
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-01-27 16:39
    The devil is in the details. Technical readers must be as sharp or shaper than technical writers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "When all think alike, no one is thinking very much.' - Walter Lippmann (1889-1974)

    ······································································ Warm regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
Sign In or Register to comment.