Shop OBEX P1 Docs P2 Docs Learn Events
Spi engine — Parallax Forums

Spi engine

superhector2000superhector2000 Posts: 1
edited 2010-02-02 16:09 in Propeller 1
Hello all,

I need help with configuring my propeller Stick to be able to read from a IMU in SPI protocol. I need to write to this sensor 6 bytes and at the same time read 6 bytes but I'm not able to do this simultaneously. The reason to do it like this is the SPI protocol.

Thanks,

Hector.

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-02-02 16:09
    You should be able to do something like this:

    pub spi(bOut) | bIn 
    
      bIn~
      repeat 8
        outa[noparse][[/noparse]MOSI] := bOut & %1                     ' output bit, LSBFIRST
        bOut >>= 1                                  ' prep for next cycle
        outa[noparse][[/noparse]CLK]~~                                 ' CLK high
        bIn := (bIn >> 1) | (ina[noparse][[/noparse]MISO] << 7)        ' get bit, LSBFIRST
        outa[noparse][[/noparse]CLK]~                                  ' CLK low
    
      return bIn
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA
Sign In or Register to comment.