Shop OBEX P1 Docs P2 Docs Learn Events
Using the SX as a slave w/ I2C — Parallax Forums

Using the SX as a slave w/ I2C

echotaechota Posts: 3
edited 2009-03-02 20:35 in General Discussion
I am working on a project where I need to establish a master controller that can issue commands
or pass data to slave controllers when needed. I am new to the SX platform, but have worked with
BS2 and Propeller. I was hoping to write my application in SX/B without having to resort to Asm.
After reading over the stock I2C commands in the SX/B reference, I determined that this sets the
SX chip up to be the master. This is problematic since I need some of my SX controllers to simply
sit and wait for a command from the master chip. Perhaps some of you have worked with a similar
configuration and any insight would be greatly appreciated.

Thanks

Miles

Comments

  • UghaUgha Posts: 543
    edited 2009-02-27 21:29
    I am attempting a project something like this myself... purely in SX/B.
    Could you use serial to communicate with the SX and then have the SX relay the data where it needs to go via I2C?
  • echotaechota Posts: 3
    edited 2009-02-27 22:19
    Ugha said...

    "I am attempting a project something like this myself... purely in SX/B.
    Could you use serial to communicate with the SX and then have the SX relay the data where it needs to go via I2C?"

    It looks like I will wind up doing something like that and building a tree rather than using a common bus. I was just wondering if someone had been able to use I2C to link together SX chips.
  • ZootZoot Posts: 2,227
    edited 2009-02-27 22:27
    If you really want to set up the SX as an I2C slave, there is already code available to do that, but it is assembly. I've messed around on and off with setting up the SX as an I2C slave, both in asm and SX/B. Personally, my feeling the latter is too inefficient (code space wise) for this purpose -- as you would obviously want to keep the slave code as compact as possible to leave room for the app's main purposes (esp. on an SX28). I'm a bit biased, though, because my general coding style is that all complex subs/funcs/ISR code is *always* in ASM with the "main" part of my program in SX/B (and then often "translated" to ASM as code-space gets tighter and tighter).

    The code is not simple, but is not spectacularly complex either, though it may *look* that way. If you have any familiarity with finite state machines, you'll see that basically the authors just ground through the all the possible states involved in slave I2C transactions and bit-banged 'em. Pretty clever, really.

    sxlist.com/techref/scenix/lib/io/osi2/i2c/i2c_sx.htm and you are looking for the second and third items in the list (I2C slave). The .src code for a straight-forward I2C slave is here: sxlist.com/techref/scenix/lib/io/osi2/i2c/i2c_slave.src

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • echotaechota Posts: 3
    edited 2009-03-02 20:33
    Hey guys thanks for the feedback, I was able to take the code and run with it.
  • ZootZoot Posts: 2,227
    edited 2009-03-02 20:35
    Cool. Post it if you can smile.gif a lot of folks have expressed interest over the last few years in using the SX as an I2C slave but there aren't too many actual working applications floating around.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
Sign In or Register to comment.