Skip to main content

SHIFTIN

Syntax

SHIFTIN Dpin, Cpin, Mode, [Variable{\ Bits} {, Variable{\ Bits}...}]

Description

SHIFTIN has been kept as a compatable function with PBASIC.  It can be used for devices that are not covered by SPI, I2C or 1-Wire.

While most other hardware functions use bytes, SHIFTIN is oriented for bit control.  The length of each variable defines the number of bits that will be shifted out (2 - 32).  If a Bit value is not specified it is assumed to be 8.

  • Mode = 0   data is shifted in MSB first, and sampling starts before the first clock pulse
  • Mode = 1   data is shifted in LSB first, and sampling starts before the first clock pulse
  • Mode = 2   data is shifted in MSB first, and sampling starts before the second clock pulse
  • Mode = 3   data is shifted in LSB first, and sampling starts before the second clock pulse

SHIFTIN does not allow arrays or strings to be part of the InputList.   Values shifted in will be positive values, unless a full 32 bit value is shifted in, and then if the MSB is 1 it will be negative. Data is shifted in at 1.1 Mbits/sec.

Example

' use SHIFTIN/OUT to control an SPI EN28J60

rw=2

reg = $1b

io(6)=0

shiftout 3,4,1,[rw\3, reg\5, y] ' set reg $1B

io(6)=1

io(6)=0

shiftout 3,4,1,[reg]
'select the register

shiftin 5,4,0,[x]
'and
read it back

io(6)=1

Differences from other BASICs

  • no equivalent in Visual BASIC
  • similar to PBASIC

See also