Shop OBEX P1 Docs P2 Docs Learn Events
SPI with SHIFTIN/SHIFTOUT? — Parallax Forums

SPI with SHIFTIN/SHIFTOUT?

ArchiverArchiver Posts: 46,084
edited 2003-06-26 18:47 in General Discussion
I need to simulate Motorola's SPI for communication between Basic
Stamp 2 and MAX3111 (SPI UART).

Does anyone know if it is possible to communicate with a SPI device
using Shiftin/Shiftout (or any other BS2 commands)?

MAX3111 send out 16 bit data while expecting to receive 16 bit data
simultaneously.

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-06-26 16:02
    SHIFTOUT sends data, SHIFTIN retrieves it -- you can't do both at the
    same time with either of those functions. It is possible in PBASIC code
    though -- I just did this for use with the Sony PlayStation game
    controller. Your code may look something like this:

    Shift_IO16:
    LOW CS
    FOR idx = 15 TO 0
    DOut = outWord.LOWBIT(idx)
    HIGH SClk
    inWord.LOWBIT(idx) = DIn
    LOW SClk
    NEXT
    HIGH CS
    RETURN

    Please understand that I wrote this very quickly after a *brief* look at
    the spec sheet -- please confirm my logic and test before using it.
    Also note that this code will run significantly slower that SHIFTOUT and
    SHIFTIN, but does give you full-duplex capability.

    -- Jon Williams
    -- Parallax




    Original Message
    From: yellowniter [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=-aIQ37tVjnBszfugeg-7T-0Ln0tZ5e1Qw5s5kXzdK8Oew2aPiXX6iP7BT0XMb7cvVVvUtZ_hPbqSvCsDXp6uyA]yellowniter@y...[/url
    Sent: Thursday, June 26, 2003 8:59 AM
    To: basicstamps@yahoogroups.com
    Subject: [noparse][[/noparse]basicstamps] SPI with SHIFTIN/SHIFTOUT?


    I need to simulate Motorola's SPI for communication between Basic
    Stamp 2 and MAX3111 (SPI UART).

    Does anyone know if it is possible to communicate with a SPI device
    using Shiftin/Shiftout (or any other BS2 commands)?

    MAX3111 send out 16 bit data while expecting to receive 16 bit data
    simultaneously.







    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject
    and Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/




    This message has been scanned by WebShield. Please report SPAM to
    abuse@p....
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-26 16:42
    Yes, it's entirely possible.
    I wrote a library to interface the SPI Max3110.
    (the 3111 is a 3.3 volt part -- is that what you
    want?)

    There are 4 major commands you need to implement.
    1. WriteConfig -- you can safely ignore the bits
    coming back, so can write this with 'SHIFTOUT'.
    2. ReadConfig -- You need the return values, so
    you'll have to implement this one in 'bit-bang'
    mode.
    3. WriteData -- can ignore the return, use
    SHIFOUT:
    T1 = (P1_3100Var | $8000) & $BFFF ' Clear bit 14/0
    LOW P1_3100_SEL
    SHIFTOUT P1_3100_DO, P1_3100_CLK, MSBFIRST, [noparse][[/noparse]T1\16]
    HIGH P1_3100_SEL
    RETURN
    (note P1_3100Var was set with the data out value first)
    4. ReadData -- Set DataOut (Chip's 'DIN') LOW. This
    tells the chip we're doing a 'readdata'. We can then
    use 'SHIFTIN' to get the data.

    P1_3100_ReadData: ' P1_3100_DO MUST be low during this...
    T1 = $0000 ' Clear ALL Bits
    LOW P1_3100_Sel ' Select it. FIRST RxBit becomes VALID
    SHIFTIN P1_3100_DI, P1_3100_CLK, MSBPRE, [noparse][[/noparse]T1\16] ' on /CS drop, DI
    becomes Valid.
    ' DI ONLY valid when Clock LOW.
    HIGH P1_3100_SEL ' Deselect chip...
    P1_3100Var = T1
    RETURN

    In 'bit-bang' mode, you'll write a subroutine to properly
    raise and lower the 'clock' line, and write the 'DataOut'
    and read the 'DataIn' lines as appropriate.

    I originally wrote my library using a 'ShiftOut' subroutine,
    which sent one 16-bit word while reading in the other
    16-bit word. Then I found I only had to do that for
    'ReadConfig'. Using SHIFTIN/SHIFTOUT for read-data and
    write-data speeds things up a lot (16 KBits/Sec on BS2,
    more on BS2sx).

    --- In basicstamps@yahoogroups.com, "yellowniter" <yellowniter@y...>
    wrote:
    > I need to simulate Motorola's SPI for communication between Basic
    > Stamp 2 and MAX3111 (SPI UART).
    >
    > Does anyone know if it is possible to communicate with a SPI device
    > using Shiftin/Shiftout (or any other BS2 commands)?
    >
    > MAX3111 send out 16 bit data while expecting to receive 16 bit data
    > simultaneously.
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-26 16:59
    Have a look at:

    http://www.wd5gnr.com/suart.htm

    This is for a 3110 which should be about the same.

    Al Williams
    AWC
    * 8 channels of PWM
    http://www.al-williams.com/awce/pak5.htm


    >
    Original Message
    > From: yellowniter [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=OxrQPq0z4UX6pdVI-fiNCumCLVNzJjGYkC0y2sBSIcfS9meDB3horLof1SGRYL8o4qC0aXq142IfblCCAe8]yellowniter@y...[/url
    > Sent: Thursday, June 26, 2003 8:59 AM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] SPI with SHIFTIN/SHIFTOUT?
    >
    >
    > I need to simulate Motorola's SPI for communication between Basic
    > Stamp 2 and MAX3111 (SPI UART).
    >
    > Does anyone know if it is possible to communicate with a SPI device
    > using Shiftin/Shiftout (or any other BS2 commands)?
    >
    > MAX3111 send out 16 bit data while expecting to receive 16 bit data
    > simultaneously.
    >
    >
    >
    >
    >
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2003-06-26 18:47
    The MAX3100 family is popular. Here is another URL:

    http://www.emesystems.com/BS2IrDA.htm

    While the article focuses on the IrDA capability, the code is the
    same for hardwired except for a configuration change.

    -- Tracy



    >I need to simulate Motorola's SPI for communication between Basic
    >Stamp 2 and MAX3111 (SPI UART).
    >
    >Does anyone know if it is possible to communicate with a SPI device
    >using Shiftin/Shiftout (or any other BS2 commands)?
    >
    >MAX3111 send out 16 bit data while expecting to receive 16 bit data
    >simultaneously.
Sign In or Register to comment.