Shop OBEX P1 Docs P2 Docs Learn Events
PropBASIC - SHIFTOUT - is more than 8 bits ok? — Parallax Forums

PropBASIC - SHIFTOUT - is more than 8 bits ok?

phatallicaphatallica Posts: 64
edited 2013-07-29 07:00 in Propeller 1
Short version of the question ... is it legal to send more than 8 bits in the PropBASIC SHIFTOUT command?

From the manual:
----
SHIFTOUT datapin, clockpin, mode, value[\bits][,speed]

If the bits parameter is not specified, 8 bits are sent.
----

All of the examples that I find are for less than 8 bits.
I intend to write 3 bytes in a row to a device (MCP23S17), which I believe should look like this:

SHIFTOUT MOSI, CLOCK, MSBFIRST, data\24 ' data is LONG variable with information in lowest 3 bytes

This is part of an effort to convert some of my old BS2p code over to PropBASIC. Most of my peripherals used SPI, so if I can get MCP23S17 up-and-running, then the rest should be no problem.

I sincerely appreciate any feedback based on experience with or knowledge of PropBASIC.
~ph



Comments

  • phatallicaphatallica Posts: 64
    edited 2013-07-28 13:09
    http://forums.parallax.com/showthread.php/121914-Sample-code-for-MCP3204-ADC

    The link above shows SHIFTIN with 13 bits, so I am confident that I can do the same with SHIFTOUT. Besides, it is Bean's code - no better resource for getting stuff right in PropBASIC.
  • pmrobertpmrobert Posts: 675
    edited 2013-07-28 15:58
    Go ahead and try it - the worst that can happen is it doesn't work. Definitely report back on your experience, please...
  • phatallicaphatallica Posts: 64
    edited 2013-07-28 16:34
    pmrobert wrote: »
    Go ahead and try it - the worst that can happen is it doesn't work. Definitely report back on your experience, please...

    In process ... Converting - and cleaning up - my old BS2p code now. The subroutines below compile, which is a good sign.
    ' Use: MCP23S17_READ register
    ' --- fixed: MOSI, SERCLK, MSBFIRST,opcode=GPIO_READ, MSB_PRE
    ' --- input parameters: register
    ' --- output parameter: value
    FUNC MCP23S17_READ
      spi_in     VAR __param2
      spi_in = GPIO_WRITE << 8    ' opcode is high byte
      spi_in = spi_in + __param1  ' combine register as low byte
      SHIFTOUT MOSI, SERCLK, MSBFIRST, spi_in\16 ' GPIO_READ, register
      SHIFTIN MOSI, SERCLK, MSBPRE, spi_in\8 ' returned byte
      RETURN spi_in
    ENDFUNC
    
    ' Use: MCP23S17_WRITE register, value
    ' --- fixed: MOSI, SERCLK, MSBFIRST, opcode=GPIO_WRITE
    ' --- input parameters: register, value
    SUB MCP23S17_WRITE
      spi_out     VAR __param3
      spi_out = GPIO_WRITE << 16    ' opcode is high byte
      __param1 = __param1 << 8    ' register is middle byte
      spi_out = spi_out + __param1    ' combine opcode and register
      spi_out = spi_out + __param2    ' combine value as low byte
      SHIFTOUT MOSI, SERCLK, MSBFIRST, spi_out\24 ' GPIO_WRITE, register, value
    ENDSUB
    
  • phatallicaphatallica Posts: 64
    edited 2013-07-28 19:00
    Looks like a winner ...
    Once I remembered to pull the chip select low for each command ...
    And remembered to tie the /Reset pin high ...
    And remembered to set the address lines.

    The file attached is an extensive framework for MCP23S17, although the working code only sequences some LEDs on Port B. With that working, I feel a little better about diving into the code for each of the peripherals that will connect to it (LCD, switches, HT12D, etc.).
    PH_TEMPLATE_MCP23S17.pbas
  • pmrobertpmrobert Posts: 675
    edited 2013-07-29 05:20
    Nice bit of code; clear commenting makes it easy to follow the logic flow, etc.
  • BeanBean Posts: 8,129
    edited 2013-07-29 06:40
    You should be able to send up to 32 bits per instruction.

    Bean
  • phatallicaphatallica Posts: 64
    edited 2013-07-29 07:00
    Bean wrote: »
    You should be able to send up to 32 bits per instruction.

    Bean
    Thanks for the additional details, Bean.
    pmrobert wrote: »
    Nice bit of code; clear commenting makes it easy to follow the logic flow, etc.
    Thanks for the kind words, pmrobert.
Sign In or Register to comment.