Shop OBEX P1 Docs P2 Docs Learn Events
Propeller with SPI for NRF24L01 — Parallax Forums

Propeller with SPI for NRF24L01

samuraisamurai Posts: 2
edited 2010-04-23 07:28 in Propeller 1
I use propeller with NRF24L01 but i don't know about SPI for configure module NRF24L01
Can I should
PUB SpiReadWrite(byte_out) : byte_in | bit
{{
  SPI read-write procedure (8-bit SPI mode 0)
  Read and write are synced, i.e. for each byte in it is one byte out
  For deatails see: [url=http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus]http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus[/url]
}}
  byte_in := byte_out
  repeat bit from 0 to 7
    'Write MOSI on trailing edge of previous clock
    if (byte_in & $80)
      High(SPI_Mosi)
    else
      Low(SPI_Mosi)
    byte_in <<= 1
 
    'Half a clock cycle before leading/rising edge
    TIME.PauseUSec(1)
    High(SPI_Sck)
 
    'Half a clock cycle before trailing/falling edge
    TIME.PauseUSec(1)
 
    'Read MISO on trailing edge
    byte_in |= Read(SPI_Miso)
    Low(SPI_Sck)
  return byte_in
  

or
PUB SHIFTOUT(Dpin, Cpin, Mode, Bits, Value)
    dira[noparse][[/noparse]Dpin]~~                                         ' make Data pin output
    outa[noparse][[/noparse]Cpin] := ClockState                             ' set initial clock state
    dira[noparse][[/noparse]Cpin]~~                                         ' make Clock pin output
                       
    
    if Mode == 4                'LSBFIRST
       Value <-= 1                                       ' pre-align lsb
       repeat Bits
         outa[noparse][[/noparse]Dpin] := (Value ->= 1) & 1                 ' output data bit
         PostClock(Cpin)         
    if Mode == 5                'MSBFIRST
       Value <<= (32 - Bits)                             ' pre-align msb
       repeat Bits
         outa[noparse][[/noparse]Dpin] := (Value <-= 1) & 1                 ' output data bit
         PostClock(Cpin)
 
PUB SHIFTIN(Dpin, Cpin, Mode, Bits)|Value
    dira[noparse][[/noparse]Dpin]~                                           ' make dpin input
    outa[noparse][[/noparse]Cpin] := ClockState                              ' set initial clock state
    dira[noparse][[/noparse]Cpin]~~                                          ' make cpin output
    
    Value~                                               ' clear output 

    if Mode == 0                'MSBPRE
       repeat Bits
         value := (Value << 1) | ina[noparse][[/noparse]Dpin]
         PostClock(Cpin)
          
    if Mode == 1                'LSBPRE
       repeat Bits +1
         Value := (Value >> 1) | (ina[noparse][[/noparse]Dpin] << 31)
         PostClock(Cpin)
       value >>= (32 - Bits)
    if Mode == 2                'MSBPOST
       repeat Bits
         PreClock(Cpin)
         Value := (Value << 1) | ina[noparse][[/noparse]Dpin]
 
    if Mode == 3                'LSBPOST
      repeat Bits + 1
        PreClock(Cpin)
        Value := (Value >> 1) | (ina[noparse][[/noparse]Dpin] << 31) 
      Value >>= (32 - Bits)

    return Value




Post Edited (samurai) : 4/22/2010 11:40:01 AM GMT

Comments

  • LeonLeon Posts: 7,620
    edited 2010-04-22 13:07
    When I wrote some PIC software for the nRF24L01 I tested the SPI code by writing values to the nRF24L01 registers, reading them back, and checking that the data were the same.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Leon Heller
    Amateur radio callsign: G1HSM
  • samuraisamurai Posts: 2
    edited 2010-04-23 07:28
    Thank you very much
Sign In or Register to comment.