Shop OBEX P1 Docs P2 Docs Learn Events
Propeller as SPI/SSP Slave — Parallax Forums

Propeller as SPI/SSP Slave

bsilvereaglebsilvereagle Posts: 6
edited 2012-11-23 06:25 in Propeller 1
Hello,

I am trying to use the Propeller chip as a "module" for the Netduino Go. Go modules communicate with the Netduino via SPI, so I am trying to bit-bang SPI slave code on the Propeller.

Currently my code is a Spin and I do not think it is running fast enough. The Go communicates at ~160KHz and I am dropping bits as far as I can tell.

Ideally the below code should print out 10101010101010, the clock signal.

Instead I get 1011000100110010 (a sampling taking from the terminal, it appears to be truly random). If I replace the INA reads with the hardcoded values for the desired input (1 for clock high, 0 for clock low) I do get 10101010101 as the printed output.

Is there a way to optimize my loop so I am not missing clock cycles? I figured I would ask before undertaking PASM :)

The Propeller is functioning as a logic analyzer of sorts in the circuit; the pins between the Netduino Go and a valid module are exposed. The Propeller is not putting data on the MISO line, the valid module is. The Propeller is just reading the SPI Clock line at the moment.

Thanks for any and all input.
CON
  _clkmode = xtal1 + pll16x         'Standard clock mode * crystal frequency = 80 MHz
  _xinfreq = 5_000_000
  SPI_CS   = 3   'SPI chip select
  SPI_MOSI = 1   'SPI Master Output Slave Input
  SPI_MISO = 2   'SPI Master Input Slave Output
  SPI_SCK  = 0   'SPI clock (read from master)


VAR
  long clock   ' 32 bit variable for holding clock signals

OBJ
  serial   :       "FullDuplexSerial"
  
PUB main

  serial.Start(15,14,00,115200)
  serial.tx($0A)
  serial.tx($0D)
  serial.str(string("Ready for flight",10,13))


'SPI TIME


'SPI_MOSI - What the slave reads from
'SPI_MISO - What the slaw writes to
'SPI_SCK  - When I should expect a byte
'SPI_CS   - Start reading


'SPI INIT
DIRA[SPI_MISO]     := 1 'output
DIRA[SPI_MOSI]     := 0 'input
DIRA[SPI_CS]   := 0 'input
DIRA[SPI_SCK]   := 0 'input 

data_out := $FF

repeat
  waitpeq(00, 00, 0)  'Wait for the Chip Select to drop
  waitpeq(01, 01,0)  'Wait for clock to go high
  clock := (clock << 1) + INA[SPI_SCK]   'Read clock, ideally 1
  waitpeq(00, 01,0)  'Wait for clcok to go low
  clock := (clock << 1) + INA[SPI_SCK] 'Read, ideally 0
  waitpeq(01, 01,0) 'Wait high
  clock := (clock << 1) + INA[SPI_SCK] "ideally read 1
  waitpeq(00, 01,0) 'Wait low
  clock := (clock << 1) + INA[SPI_SCK] 'Ideally read 0
  waitpeq(01, 01,0)
  clock := (clock << 1) + INA[SPI_SCK]
  waitpeq(00, 01,0)
  clock := (clock << 1) + INA[SPI_SCK]
  .....repeated until 32 bits are read
  serial.bin(clock,32)

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2012-11-22 20:30
    Hi bsilvereagle,

    Welcome to the forum!
    Currently my code is a Spin and I do not think it is running fast enough. The Go communicates at ~160KHz and I am dropping bits as far as I can tell.

    You are correct, Spin is not fast enough to implement an SPI slave at 160Khz

    A SPI slave could be written in PASM and could run at up to 1.2MBps or so, or using SpinLMM you could write it in-line and still run at about 200Mbps
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-11-22 20:35
    Hello,

    I am trying to use the Propeller chip as a "module" for the Netduino Go. Go modules communicate with the Netduino via SPI, so I am trying to bit-bang SPI slave code on the Propeller.

    Currently my code is a Spin and I do not think it is running fast enough. The Go communicates at ~160KHz and I am dropping bits as far as I can tell.

    Ideally the below code should print out 10101010101010, the clock signal.

    Instead I get 1011000100110010 (a sampling taking from the terminal, it appears to be truly random). If I replace the INA reads with the hardcoded values for the desired input (1 for clock high, 0 for clock low) I do get 10101010101 as the printed output.

    Is there a way to optimize my loop so I am not missing clock cycles? I figured I would
    Ideally the below code should print out 10101010101010, the clock signal.

    Instead I get 1011000100110010 (a sampling taking from the terminal, it appears to be truly random). If I replace the INA reads with the hardcoded values for the desired input (1 for clock high, 0 for clock low) I do get 10101010101 as the printed output.

    Is there a way to optimize my loop so I am not missing clock cycles? I figured I would ask before undertaking PASM :smile:
    You could check to see if there is an SPI Slave object available (not sure) in the obex. In Tachyon Forth my standard SPI instruction can handle data at 2.85MHz in master mode so it would have no problem with your SPI in slave mode. BTW, I think Bill means up to 20Mbps (not 200) in PASM for a master but slave software always runs much slower because it has to synchronize to the clock from the master.
  • bsilvereaglebsilvereagle Posts: 6
    edited 2012-11-22 20:36
    Thanks for the quick reply Bill.

    Looks like PASM it is then.

    Does code already exist for using the Propeller as a SPI slave? I've searched through the Object Exchange but didn't find anything

    I read through some PASM guides linked to on the forums yesterday and they seem fine as a very generic launching point. However, none of the examples seemed all to practical. Are there sets of PASM example code similar to O'Reilly "Cookbooks"?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2012-11-22 20:46
    Thanks for the quick reply Bill.

    Looks like PASM it is then.

    Does code already exist for using the Propeller as a SPI slave? I've searched through the Object Exchange but didn't find anything

    I read through some PASM guides linked to on the forums yesterday and they seem fine as a very generic launching point. However, none of the examples seemed all to practical. Are there sets of PASM example code similar to O'Reilly "Cookbooks"?
    I can tweak my SPI module in Tachyon Forth to handle slave mode. That way you get the speed, the interactivity, without delving into PASM.
  • bsilvereaglebsilvereagle Posts: 6
    edited 2012-11-23 06:25
    Thanks for the offer Peter, I would really appreciate it.

    I couldn't quite tell from the the links in your signature, can Tachyon be encapsulated on one cog or is it more of a firmware for the Propeller?
Sign In or Register to comment.