+ Reply to Thread
Results 1 to 7 of 7

Thread: Is there code for a high speed SPI Slave?

  1. #1

    Default Is there code for a high speed SPI Slave?

    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!

  2. #2

    Default Re: Is there code for a high speed SPI Slave?

    Full duplex or simplex ?

    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

    Code:
              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

    Code:
     PinA    PinB
      1          0          PinA is Stable high 
      0          1          PinA is Stable Low 
      0          0          PinA has =\_
      1          1          PinA has _/=
    
    and the WAITxx mask, is 2 bits wide, and applies to BOTH PinA and PinB
    Wait is now a true edge wait, so even if applied when HI or LO, it will wait for the edge, and only
    one wait is needed per loop to sync to an external clock
     Min is  4 lines, 1 waits   ~ 4MHz  ( < 4.444'MHz)
    ( say <= 4.21MHz with a 1 clk wait adder  ~ 5% clock margin )
    This true edge approach could also be used for i2c, and might allow a prop to hit the 3.4MHz i2c speed bin ?
    Last edited by jmg; 04-15-2012 at 02:13 AM.

  3. #3

    Default Re: Is there code for a high speed SPI Slave?

    jmg, Thanks for the suggestion.I was thinking of Full duplex operation but if that slows things down too much then I'll work around it. I'm trying to interface to an Arduino board via SPI and it's minimum speed is 1 MHz.

  4. #4

    Default Re: Is there code for a high speed SPI Slave?

    Quote Originally Posted by blittled View Post
    I'm trying to interface to an Arduino board via SPI and it's minimum speed is 1 MHz.
    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

    Code:
    		  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-out
    Which 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.

  5. #5

    Default Re: Is there code for a high speed SPI Slave?

    jmg Thank you again! I thought the divider for the Arduino SPI was only up to 16 and as you pointed out it goes to 128! I'm actually using a UNO32 which has a 80 MHz clock rather than a 16MHz and I was afraid of it being too fast for the 100 KHz slave I'm using. It turns out it has the same SPI frequencies as an Arduino and I believe 125KHz will be close enough since I want to use a known Propeller driver as a base so I know that any commuication problems are with the UNO32. After that I'll try speeding it up using your ideas. Thanks.

  6. #6

    Default Re: Is there code for a high speed SPI Slave?

    Quote Originally Posted by blittled View Post
    jmg Thank you again! I thought the divider for the Arduino SPI was only up to 16 and as you pointed out it goes to 128! I'm actually using a UNO32 which has a 80 MHz clock rather than a 16MHz and I was afraid of it being too fast for the 100 KHz slave I'm using. It turns out it has the same SPI frequencies as an Arduino and I believe 125KHz will be close enough since I want to use a known Propeller driver as a base so I know that any commuication problems are with the UNO32. After that I'll try speeding it up using your ideas. Thanks.
    You say you're using the UNO32. What tool chain are you using with it? I'm wondering if there is a Mac-based tool chain for that board.

    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.
    Last edited by David Betz; 04-16-2012 at 03:52 PM.

  7. #7

    Default Re: Is there code for a high speed SPI Slave?

    Dave, there is no such thing as a dumb question. I'm using MIDE on Widows 7 and yes you can use MPLAB X. I also believe there is a MIDE for MAC X called MIDEX at https://github.com/rei-vilo/mpideXcode.

+ Reply to Thread

Similar Threads

  1. High speed I2C?
    By KenBash in forum Propeller 1 Multicore Microcontroller
    Replies: 11
    Last Post: 06-27-2011, 08:54 PM
  2. SPI Slave code in SX/B
    By Bean in forum SX Chips and Programming Tools
    Replies: 2
    Last Post: 12-19-2008, 07:37 PM
  3. High Speed ADC and DAC
    By Scott Harris in forum Propeller 1 Multicore Microcontroller
    Replies: 3
    Last Post: 05-10-2008, 06:47 AM
  4. High Speed Cameras
    By ghost13 in forum General Discussion
    Replies: 2
    Last Post: 08-15-2007, 05:40 PM
  5. High speed, High accuracy compass?
    By Archiver in forum BASIC Stamps Archive
    Replies: 3
    Last Post: 04-12-2001, 02:24 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts