Shop OBEX P1 Docs P2 Docs Learn Events
Why won't this assignment work? — Parallax Forums

Why won't this assignment work?

RichardFRichardF Posts: 168
edited 2007-07-01 14:16 in Propeller 1
I can do this:
· number := 234
· outa := number

but not this:
· number := 234
· outa.byte[noparse][[/noparse]1] := number

I want to pass a byte at a time to 8 pins of the outa register. Then read that byte in 8 ina pins of another prop chip. I thought any register could be treated as a variable, including addressing specific byte, word or long segments.

Thanks,
Richard

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-30 21:21
    The notation is different for the input/output/direction registers since they're not really byte addressable. Try

    outa[noparse][[/noparse] msb..lsb ] := value

    msb is the number of the most significant bit to be used and lsb is the number of the least significant bit. In your case use:

    outa[noparse][[/noparse] 15..8 ] := value

    Note that you can have an msb with a lower number than the lsb. The bits are reversed in that case.

    Similarly, you can read with:

    value := ina[noparse][[/noparse] 15..8 ]
  • RichardFRichardF Posts: 168
    edited 2007-06-30 22:04
    Thanks MIke.

    It isn't always clear as to addressibility (is this a word?smile.gif ) of registers and variables. I would think that anything that·is saved in a contiguous area of ram should be byte, word and long adressable. Apparently not. Is it true that dira·:= 4 means that·pin·2·will be ·set to·output? I can certainly do this: dira[noparse][[/noparse]2] := 1, it seems odd that I can't use dira.byte[noparse][[/noparse]0] := 4. No logic here, just a rule, right?

    In any event, to pass a byte between two Prop chips I should be able to send a byte to outa[noparse][[/noparse]7..0] in chip 1 and read it in ina[noparse][[/noparse]7..0] in chip 2, or just use outa := value_passed, ina := value_received, making sure that bits 0..7 are reserved for passing data.

    Richard
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-30 22:25
    Richard,
    There is a logic to this "rule". OUTA, INA, and DIRA are not memory locations (at least not in the hub or main memory). They are special cog memory locations that are not accessible as memory to Spin programs. The same thing is true for the other 13 long words located in the last 16 long words of cog memory. They're not byte or word addressable. Of these, only the I/O registers have this bit addressability notation that's allowed for convenience. The others are usable only as long words.
  • RichardFRichardF Posts: 168
    edited 2007-07-01 11:51
    Thanks for the explanation, Mike
  • Fred HawkinsFred Hawkins Posts: 997
    edited 2007-07-01 14:16
    Wouldn't outa[noparse][[/noparse]8] := 234 be evaluated as·first as %11101010, then %0·and therefore outa[noparse][[/noparse]8] := 0? (In other words, you only get least significant bit of the input number.)
Sign In or Register to comment.