Shop OBEX P1 Docs P2 Docs Learn Events
Ok....I'm sort of confused....about getting bit value. — Parallax Forums

Ok....I'm sort of confused....about getting bit value.

James LongJames Long Posts: 1,181
edited 2007-02-17 22:06 in Propeller 1
Ok....so I'm working with a chip that places a 1 into bit #2 of a word.

I have included the code I'm trying to look at this bit with....but I'm concerned it not actually working the way I need it to.

It is in spin.....so you asm guys cut me some slack.
· outa[noparse][[/noparse]CH1]~
· goodch1 := (bs2.shiftin(SDI, SCL, bs2#MSBPRE, 16))
· outa[noparse][[/noparse]CH1]~~
· if goodch1.byte[noparse][[/noparse]0] & |<2
··· serial.tx(set_colorh)
··· serial.tx(greenh)
··· serial.tx(greenl)
· else
··· serial.tx(set_colorh)
··· serial.tx(redh)
··· serial.tx(redl)
I'm wondering if I'm even close.....maybe I should have stuck with stamps.

James L

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-17 18:49
    It's a little confusing because of the byte/word order thing. The Propeller stores information in "little-endian" order where the "little end" of the word or long comes first. BYTE[noparse][[/noparse] 0] is the low order byte of the word while BYTE[noparse][[/noparse] 1] is the high order byte. This may not be what you're trying to do (in fact, I think it's backwards for you). It's actually easier to just leave things as words. Use "goodch1 & |< 2" in the IF statement and I think things will work better and possibly be clearer.
    Mike
  • James LongJames Long Posts: 1,181
    edited 2007-02-17 18:52
    Mike,

    Wouldn't bit #2 be on the lower end of the word?

    Also....since this data is coming in MSB.....would that make it backwards.....

    I'm tried the suggested way first.....but didn't seem to work....but this is not the only part that is confusing.

    Just to make sure....the bits are numbered· 0 - 15 ....right?

    I want to ensure I'm getting all the terminology right.

    James L

    Post Edited (James Long) : 2/17/2007 6:58:13 PM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-17 19:44
    Most people number the bits from least significant (2^0) to most signficant, but that's not always true. Based on your documentation, you'll have to figure out how your device numbers them. The Propeller and its software assumes that bit #0 is the least significant.
  • James LongJames Long Posts: 1,181
    edited 2007-02-17 22:06
    Mike,

    I checked the datasheet....and the word is numbered from MSB to LSB (D15 to D0)

    So I figure the least significate would be on the bottom end....or the last recieved by the Propeller. Which I would calculate would be the lower end of byte[noparse][[/noparse]0].

    But I seem to not be recieving any 1's from the chip. Seems to only give zero's by the few tests I have run, which all may be wrong.

    The shiftin method should put the bits in order with the MSB being to the left. That is why I calculate the LSB being to the farthest to the right. (Which I assume is the byte[noparse][[/noparse]0]).

    I have to get an oscope to insure the chip is outputing data.

    James L
Sign In or Register to comment.