Shop OBEX P1 Docs P2 Docs Learn Events
Using Propeller as I2C Slave of Lego NXT — Parallax Forums

Using Propeller as I2C Slave of Lego NXT

GaneshGanesh Posts: 2
edited 2009-05-03 06:23 in Propeller 1
Hi all,

After about 2 weeks of struggle I managed to get the Propeller to work as I2C slave to Lego NXT running Lejos program. I used the i2c slave code from Hippy (http://forums.parallax.com/showthread.php?p=721563).

The key things are: 1. device address to be specified in the lejos program should be 7 bit form. For example if the device ID on the propeller program is set to 0x20 then on the lejos program it should be bit shifted right and specified as 0x10. 2. Lejos does i2cSensor's sendData supports only one byte as internal address. What I did was to comment out the·part of propeller code which expects second byte.

Write·················· call··· #Ack··················· ' Acknowledge the write command
······················· call··· #GetByte··············· ' Get address high byte
······················· mov···· adr,byt
······················· call··· #Ack··················· ' ACknowledge we got the byte
·······················
······················· 'Comment out reading of second address·byte.
······················· 'call··· #GetByte··············· ' Get address low byte
······················· 'shl···· adr,#8
······················· 'or····· adr,byt
······················· 'call··· #Ack··················· ' Acknowledge we got the byte
·······················
:Loop·················· call··· #GetByte··············· ' Get the data byte ( aborts on stop bit )
······················· Call··· #SaveByte·············· ' Save it
······················· call··· #Ack··················· ' Acknowledge we saved it
··················································
······················· jmp···· #:Loop················· ' Get next byte ( will abort on a stop bit )
After this everything works smoothly!

Cheers

Ganesh
·

Comments

  • EricGarlicEricGarlic Posts: 41
    edited 2009-05-02 12:28
    Hi - I'm interested to hear how you used Hippy's code. I struggled (I only get a few hours a weekend and my brain isn't quick enough).

    My lad can get I2C in NXT working but I couldn't get the prop to act as an I2C slave (I got lost with where the data went).

    Anything you can share would be appreciated.

    Eric
  • GaneshGanesh Posts: 2
    edited 2009-05-02 18:56
    Hi,

    Few questions..

    1. On NXT what is the programming platform? (NXT-G, Lejos, RobotC, NXC..)
    2. Have you put pull-up resistors on the SDA and SCL lines? NXT does not pull it up.
    3. The device ID in Hippy's code is 8 bit (i.e. includes the last r/w bit). On Lejos I2C library, you need to consider 7 bit address.
    4. What is the device ID being used? What is the register address you are trying to read/write?
    5. Are you attempting single byte or multi-byte read/write from NXt?

    After having gone through the struggle, I am sure that in your case too it will work. In between, I considered ditching the idea. But eventually when it worked I found there is nothing more elegant than NXT treating Propeller as an I2C sensor.

    Cheers!
  • EricGarlicEricGarlic Posts: 41
    edited 2009-05-02 20:14
    Let me have a go tomorrow morning and I will post back. Cheers Eric
  • MightorMightor Posts: 338
    edited 2009-05-03 06:23
    FYI: Lego specifies that the pull-ups should be very high, 82K for both SDA and SCL.

    Regards,
    Xander

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    | To know recursion, you must first know recursion.
    | Current projects and ramblings: I'd Rather Be Building Robots
    | RobotC 3rd Party Driver Suite: [noparse]/noparse][url=https://sourceforge.net/projects/rdpartyrobotcdr/]Project Page[/url / [noparse]/noparse][url=http://rdpartyrobotcdr.sourceforge.net/documentation/index.html]API Documentation[/url
Sign In or Register to comment.