Shop OBEX P1 Docs P2 Docs Learn Events
Release Pin from Cog — Parallax Forums

Release Pin from Cog

SpillySpilly Posts: 26
edited 2014-06-22 07:28 in Propeller 1
I am trying to find a way to release control of a pin's output state from a cog. I am writing an SPI driver that has several different cogs needing to send SPI data at different times over the same SPI lines. I was able to make a work around and pass the in control cog the data needing to be sent, and have it in turn send the data. Is there some sort of command I can add to relinquish control of the SPI pins at the end of my SPI function? Tried a bit of searching and dug through the simpletools library but didn't have any luck.

Edit: I am using simpleIDE and C#

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-06-22 06:48
    Spilly wrote: »
    I am trying to find a way to release control of a pin's output state from a cog. I am writing an SPI driver that has several different cogs needing to send SPI data at different times over the same SPI lines. I was able to make a work around and pass the in control cog the data needing to be sent, and have it in turn send the data. Is there some sort of command I can add to relinquish control of the SPI pins at the end of my SPI function? Tried a bit of searching and dug through the simpletools library but didn't have any luck.

    Edit: I am using simpleIDE and C#

    Each cog has it's own direction register and output register so they operate independently of each other but the outputs from each cog are OR'd together to drive the pin. This means that if any cog has been using an output that it should leave it's output low afterwards so that any other cog can drive the pin high. This is not always possible to do as for instance the chip enable line can't be left low so what you need to do is add pull-ups on the lines so that when a cog has finished with a pin it can either leave it low or else release the output (DIRA) so that it will float high but can still be driven by another cog. I have similar problems with multiple cogs and SPI as well.

    So:
    1. Add pullups on outputs that need to idle high
    2. After a cog has finished with the pin it should float the output for it to idle high or else just drive it low. In the latter case any other cog can drive the pin high because all cog outputs are OR'd.
  • SpillySpilly Posts: 26
    edited 2014-06-22 07:28
    So:
    1. Add pullups on outputs that need to idle high
    2. After a cog has finished with the pin it should float the output for it to idle high or else just drive it low. In the latter case any other cog can drive the pin high because all cog outputs are OR'd.

    Thank you for the quick and thorough response. That information is very useful and certainly makes sense.

    To verify that I follow:
    !CS! connected to pull-up resistor that limits current to less than the I/O pin's sink ability.
    When finished with SPI function use DIRA = mask to change !CS! pin to high impedance input mode.
    Set all other SPI pins to low.

    Edit: Or to simplify things, just use DIRA = 0x0
Sign In or Register to comment.