Propeller as SPI/SSP Slave
bsilvereagle
Posts: 6
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.
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
Welcome to the forum!
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
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 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?