Positron Compiler Documentation

Shin

Positron16 · Revision 1.1.3.5 · PDF pages 206–207

Shin Data_Pin, Clock_Pin, Mode, [ result { \bits } { ,result { \bits }...} ]

or

Assignment Variable = Shin Data_Pin, Clock_Pin, Mode, Shifts

Shift data in from a synchronous-serial device.

Data_Pin is a Port.Pin constant that specifies the I/O pin that will be connected to the synchronous-serial device's data output. This pin's I/O direction will be changed to input and will remain in that state after the instruction is completed. Clock_Pin is a Port.Pin constant that specifies the I/O pin that will be connected to the synchronous-serial device's clock input. This pin's I/O direction will be changed to output. Mode is a constant that tells Shin the order in which data bits are to be arranged and the relationship of clock pulses to valid data. Below are the symbols, values, and their meanings: -

Original diagram or table from Positron16, PDF page 206
Original figure / layout · PDF page 206
Text in this figure or table
SymbolValueDescription
MsbPre0Shift data in highest bit first. Read data before
MsbPre_Lsending clock. Clock idles low
LsbPre1Shift data in lowest bit first. Read data before send-
LsbPre_Ling clock. Clock idles low
MsbPost2Shift data in highest bit first. Read data after send-
MsbPost_Ling clock. Clock idles low
LsbPost3Shift data in highest bit first. Read data after send-
LsbPost_Ling clock. Clock idles low
MsbPre_H4Shift data in highest bit first. Read data before

sending clock. Clock idles high

LsbPre_H 5 Shift data in lowest bit first. Read data before send-

ing clock. Clock idles high

MsbPost_H 6 Shift data in highest bit first. Read data after send-

ing clock. Clock idles high

LsbPost_H 7 Shift data in lowest bit first. Read data after sending

clock. Clock idles high

Result is a bit, byte, or word variable in which incoming data bits will be stored. Bits is an optional constant specifying how many bits (1-16) are to be input by Shin. If no bits entry is given, Shin defaults to 8 bits. Shifts informs the Shin command as to how many bit to shift in to the assignment variable, when used in the inline format.

Shin provides a method of acquiring data from synchronous-serial devices, without resorting to the hardware SPI modules resident on some devices. Data bits may be valid after the rising or falling edge of the clock line. This kind of serial protocol is commonly used by controller peripherals such as ADCs, DACs, clocks, memory devices, etc.

The Shin command causes the following sequence of events to occur: -

View original PDF page 206Open page in PDFOriginal PDF page 206

Makes the clock pin output low. Makes the data pin an input. Copies the state of the data bit into the msb (lsb-modes) or lsb (msb modes) either before (-pre modes) or after (-post modes) the clock pulse. Pulses the clock pin high. Shifts the bits of the result left (msb- modes) or right (lsb-modes). Repeats the appropriate sequence of getting data bits, pulsing the clock pin, and shifting the result until the specified number of bits is shifted into the variable.

Making Shin work with a particular device is a matter of matching the mode and number of bits to that device's protocol. Most manufacturers use a timing diagram to illustrate the relationship of clock and data.

Symbol Clock_Pin = PORTB.0
Symbol Data_Pin = PORTB.1
Shin Data_Pin, Clock_Pin, MsbPre, [Var1]   ' Shift in msb-first, pre-clock.

In the above example, both Shin instructions are set up for msb-first operation, so the first bit they acquire ends up in the msb (leftmost bit) of the variable.

The post-clock Shift in, acquires its bits after each clock pulse. The initial pulse changes the data line from 1 to 0, so the post-clock Shift in returns %01010101.

By default, Shin acquires eight bits, but you can set it to shift any number of bits from 1 to 16 with an optional entry following the variable name. In the example above, substitute this for the first Shin instruction: -

Shin Data_Pin, Clock_Pin, MsbPre, [Var1\4] ' Shift in 4 bits.

Some devices return more than 16 bits. For example, most 8-bit shift registers can be daisychained together to form any multiple of 8 bits; 16, 24, 32, 40... You can use a single Shin instruction with multiple variables.

Each variable can be assigned a particular number of bits with the backslash (\) option. Modify the previous example: -

' 5 bits into Var1; 8 bits into Var2.
  Shin Data_Pin, Clock_Pin, MsbPre, [Var1\5, Var2]
  Print "1st variable: ", Bin8 Var1
  Print "2nd variable: ", Bin8 Var2

Inline Shin Command.

The structure of the inline Shin command is: -

Var = Shin dpin, cpin, mode, shifts

DPin, CPin, and Mode have not changed in any way, however, the Inline structure has a new operand, namely Shifts. This informs the Shin command as to how many bit to shift in to the assignment variable. For example, to shift in an 8-bit value from a serial device, we would use:

Var1 = Shin Data_Pin, Clock_Pin, MsbPre, 8

To shift 16-bits into a Word variable: -

MyWord = Shin Data_Pin, Clock_Pin, MsbPre, 16
View original PDF page 207Open page in PDFOriginal PDF page 207