Is there code for a high speed SPI Slave?
blittled
Posts: 695
I'm working on a project that needs a SPI slave that works at approx. 1MHz. I have the Chameleon PIC and that SPI Slave driver runs at 100KHz. Is there one I missed in the OBEX or has someone worked on one? Thanks!

Comments
It's a pity the Prop lacks a WAIT_Pedge opcode, (to allow avoid of WAITPEQ WAITPNE pairs) for the lowest overhead sync-to-edge.
The classic pseudo minimal code for Serial RX, is
Ctr_Shift = 0000000001 ; use shifter also as bit counter LOOP WAIT_For_Clock_Edge ; Sync to external clock CY = SPI_DI_Pin ; receive mode RLC Ctr_Shift ; Shift and count JC LOOP ; The preloaded 1 Bit appears in CY, when Required bits 1..32 are done. but the Prop needs a pair of WAITPEQ WAITPNE, so min is 5 lines, 2 waits ~ 3MHz ( say <= 3.20MHz with a 1 clk wait adder ~ 4% clock margin )I think there is a way to synth a WaitEdge, if you do not mind using some resource :
Config a COG counter in feedback mode, and now we have two pins to mask.
PinA= SPI CLK, and PinB = !PinA
This true edge approach could also be used for i2c, and might allow a prop to hit the 3.4MHz i2c speed bin ?
I can find this, re Ardunio SPI speeds : ["It's possible to set the SPI clock to 8, 4, 2, 1MHz, 500, 250, 125kHz (Assuming a 16MHz system clock). "]
In Pseudo code, Duplex is along the lines of
IO_Data = TxData BitCtr = 32 LOOP WAIT_For_Clock_Rise ; Sync to external clock CY = SPI_DI_Pin ; Capture data receive mode RLC IO_Data ; Shift In RX,and out TX WAIT_For_Clock_Fall ; Sync to external clock SPI_DO_Pin = CY ; Send Data on opposite edge DJNZ BitCtr,LOOP ; Count Bits in-outWhich should be good for ~ 2.75MHz, so should cover the 2MHz speed choice above.
As always, start with the lowest speed for testing, and then increase.
Thanks,
David
Edit: I guess this is a dumb question. I realized after posting it that you can surely use MPLAB X on the Mac to develop code for this board and also their own modification of the Arduino IDE.