Shop OBEX P1 Docs P2 Docs Learn Events
I2C Slave support in SX/B — Parallax Forums

I2C Slave support in SX/B

Tony LeylandTony Leyland Posts: 71
edited 2005-10-22 22:03 in General Discussion
Hi,

I like I2C support in SX/B. Does anyone know if commands will be developed for a I2C Slave environment ? I ask this
as several of my projects involve connecting SXs together on a common I2C bus and having one as the Master with
others as Slaves.

Many thanks in advance,
Tony

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-10-20 21:59
    Considering that SX/B is a subset of PBASIC and PBASIC does not have I2C slave commands, I would not hold my breath hoping for thier inclusion. But unlike PBASIC, you can easily incorporate your own I2C slave code. Also I2C slave code would best be placed in the interrupt routine, meaning it doesn't fit in the command model of PBASIC.

    Take a look at http://www.parallax.com/dl/src/prod/sx/i2cs.zip·for code·for a virtual peripheral·I2C slave (its written in assembly).


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-20 22:03
    Probably not -- and yet there's nothing stopping you from doing it. When we were first developing SX/B I wrote I2C and 1-Wire commands as subroutines, and then our engineer folded them into the compiler.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • BeanBean Posts: 8,129
    edited 2005-10-20 23:57
    Tony,
    · A I2C slave device must be "listening" at all times. So you can't really make a "command" to do I2C slave. It's something that has to be written into your program. And as Paul has stated, an interrupt would be the easiest way to to it.

    · If it's just for SX to SX communication, I would think serial would be much easier to implement.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "SX-Video·Module" Now available from Parallax for only $28.95

    http://www.parallax.com/detail.asp?product_id=30012
    Product web site: www.sxvm.com
    Available now... SX-Video OSD module $59.95 www.sxvm.com

    "Save your money. Pay with cash."
    ·
  • John CoutureJohn Couture Posts: 370
    edited 2005-10-21 01:02
    Tony,

    Serial would be a protocol for one SX to one SX. If however, you need some serious DISTANCE, and want to communicate with multiple SX mcu's (as in one master, many slaves), consider RS-485. I'm experimenting with some SN75176 chips (about $0.60 ea) and they seem simple enough to get a signal down a very long wire (spec says you can go up to over 4000 feet in some conditions and over 400Mbit/sec on shorter runs).

    I'd highly recommend Jan Axelson's "Serial Complete" book. She presents the topic very well and my copy is well worn from referencing it often.

    Ditto on making it an interrupt. That's why I'm spending so much time learning how to use interrupts (see my dumb questions in other posts) as they are the secret to getting mcu's to communicate efficiently.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • pjvpjv Posts: 1,903
    edited 2005-10-21 04:08
    Whoaaaaa..

    Did you say RS-485 at 400 Mbits/Sec with a 75176?

    That's unbelievably fast. Please point us to where THAT can be found.

    My experience confirms a limit of about 10 Mbits/Sec., and at that rate for not many feet; a few hundred over twisted pair.

    Cheers,

    Peter (pjv)
  • John CoutureJohn Couture Posts: 370
    edited 2005-10-21 14:59
    Wow!· Boy I messed up that post didn't I.· That's what I get for answering a post away from my reference desk.·

    PJV is quite correct in that 10Mbits/sec is the TIA/EIA-485 limit.

    As atonement for my sins (grin), I offer the following datasheets:

    ·· http://www.maxim-ic.com/appnotes.cfm/appnote_number/643
    ····· which shows the the 10M rate good for short distances (chart)

    ···http://focus.ti.com/lit/ds/symlink/sn75176b.pdf
    ····· which is the chip I use.

    ·· http://www.arcelect.com/RS485_info_Tutorial.htm
    ····· a tutorial on RS-485

    ·· http://ckp.made-it.com/rs485.html
    ······a quick chart that shows
    ········· 100Kbps @ 4000' and
    ·········· 10Mbps @ 50'

    And finally, the home page of RS-485
    ·· http://www.rs485.com
    ·· with its quick reference guide: http://www.rs485.com/rs485spec.html

    I apologize for the·previously incorrect info before (grovel, grovel, grovel)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • pjvpjv Posts: 1,903
    edited 2005-10-21 15:22
    Hi John;

    I'm disappointed; here I thought we were going to have some really good new technology inexpensively available, although I would not know how to drive an SX to bit-bang at 400 Mbits/Sec. I believe we can bit-bang the Ubicom IP3000 at 100 Mbits/sec so will need to give that a try.

    Oh, well....I guess, there "ain't no free lunch", and thanks for the links.

    Regarding the distances at 10 Mbit/Sec, my experience is that rate is reliably attainable over 200 feet, and that with standard asynchronous coding. I expect Manchester will beahve a little better with it's "no-DC-component", but alas at half the bit rate. Someday when more time is available, I'll try to see what the actual non theoretical limits are.

    Cheers,

    Peter (pjv)

    Post Edited (pjv) : 10/21/2005 3:25:55 PM GMT
  • Tony LeylandTony Leyland Posts: 71
    edited 2005-10-21 20:40
    Hi All,

    Thanks for pointing me in the right direction, I now understand why 'Slave' commands do not exist in SX/B.

    I'll have to make sure not to use any time-sensitive commands while I have the ISR running. Mind you, I
    will be using RS232, so I'll need to add a VP for that as well.

    With this project I have 1 master SX, 2 other slave SXs an EEPROM and an LCD module. They will all be
    connected to either 1 or 2 I2C buses. The 2 slave SXs will behave like an EEPROM, so that the master
    can write to or read from locations within each SX via I2C and thus control the slave SX in question.

    Tony
  • John CoutureJohn Couture Posts: 370
    edited 2005-10-21 21:13
    Tony,

    Another chip I use is a PCF8583 Real Time Clock. This I2C device has 2K of RAM (yes I checked the datasheet this time, grin). The only external parts needed are a 32K crystal and a tiny 10pf capacitor.

    They communicate over I2C and they seem to keep excellent time. I supply them with a battery backup power supply of 3volts (2 AAA's which means the batteries will die of old age) and run the clock off of the 5v most of the time.

    The RAM part is interesting too. The RTC uses the first 16 bytes of ram but the rest is available to the programmer. Thus, I keep it supplied with 3 volts and, once set, it provides an excellent resource. I bought mine a while back for about $0.60 and I assume they are still available. These would be less expensive than an SX?? and have quite a bit more RAM. Or you could use your SX?? to gather the data and store the data in the RAM chip for all MCU's to use. Now you have a NETWORK! Fun stuff!

    Datasheet:
    http://www.semiconductors.philips.com/acrobat_download/datasheets/PCF8583_5.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-10-21 23:15
    Actually, 2kbit of ram (240 bytes).

    regards peter
  • Paul BakerPaul Baker Posts: 6,351
    edited 2005-10-22 00:32
    john, take a look at the FM31 series here http://www.ramtron.com/doc/Products/processor.asp they have much more memory and the memory is nonvolatile so the batteries for the rtc last longer.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • Tony LeylandTony Leyland Posts: 71
    edited 2005-10-22 20:13
    Many thanks for advice about the real-time clock IC, I may well use it as my project my need a
    real-time clock function and I can utilise the extra storage space.

    Tony
  • John CoutureJohn Couture Posts: 370
    edited 2005-10-22 22:03
    Thank you Peter,

    It's not that I'm blind (grin), Its just that I'm not careful. Thank you for the catch. Next thing you know I'll be pluging my SX chip into 110Volts! Geez! I gotta slow down.

    Paul, I ordered some samples, thank you for the lead.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
Sign In or Register to comment.