Shop OBEX P1 Docs P2 Docs Learn Events
SPI engine and cog questions — Parallax Forums

SPI engine and cog questions

JonathanJonathan Posts: 1,023
edited 2007-07-10 20:42 in Propeller 1
Hi All,

Just a·few quick question about the SPI engine and cogs.

If I have two cogs each accessing a device using the SPI engine, do I have 4 cogs running (2X shiftin, 2x shiftout)?

Does one stop call, like spi.stop kill both cogs (shiftin and shiftout)? Or do I need to call both shiftin/out with a -1 param?

Is there an easy way to see how many cogs you have running at any particular time? Or do I need to flag each cog?

Thanks!

Jonathan

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-07-10 18:06
    The SPI engine starts one cog that handles both shiftin and shiftout. If you read the comments in the source file, you'll see that SHIFTIN and SHIFTOUT automatically start the cog if it's not running already. If you supply a Bits value of zero, the cog will stop itself. As a result, you don't need to call the start or stop routines (although you can if you want to control the cog explicitly).

    Each instance of the SPI engine can control one device and you can change from one device (set of pins) to another with each call to SHIFTIN and SHIFTOUT. If you need to control two devices simultaneously, you can declare two instances of the SPI engine like: OBJ spi1, spi2 : "SPI Engine"

    You could alternatively declare an array of SPI engines like: OBJ spi : "SPI Engine"

    Each name or array element is a separate instance, has its own VAR data storage, and will start its own cog to do the work independently.

    There is no easy way to see how many cogs you have running. There is a small utility program in the Object Exchange that attempts to start new cogs until the COGNEW fails, then stops the ones it started and reports the number of cogs it was able to start.
  • JonathanJonathan Posts: 1,023
    edited 2007-07-10 18:14
    Mike,

    Thanks for the help, that answers my questions very nicely. Appreciate your time as always!

    Jonathan

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2007-07-10 20:42
    Thanks Mike

    Excellent explanation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.