- Name:
-
shiftin
- Syntax:
-
SPIIN sclk,sdata,mode,(variable {/ bits} {, variable {/ bits}, ...})
SHIFTIN sclk,sdata,mode,(variable {/ bits} {, variable {/ bits}, ...})
Sclk - is a variable/constant which specifies the i/o pin to use as clock.
Sdata - is a variable/constant which specifies the i/o pin to use as data.
Mode - is a variable/constant (0-7) which specifies the mode:
| 0 |
MSBPre_L |
(MSB first, sample before clock, idles low) |
| 1 |
LSBPre_L |
(LSB first, sample before clock, idles low) |
| 2 |
MSBPost_L |
(MSB first, sample after clock, idles low) |
| 3 |
LSBPost_L |
(LSB first, sample after clock, idles low) |
| 4 |
MSBPre_H |
(MSB first, sample before clock, idles high) |
| 5 |
LSBPre_H |
(LSB first, sample before clock, idles high) |
| 6 |
MSBPost_H |
(MSB first, sample after clock, idles high) |
| 7 |
LSBPost_H |
(LSB first, sample after clock, idles high) |
Variable - receives the data.
Bits - is the optional number of bits to transmit. If omitted the default is 8.
- Description:
-
The spiin (shiftin also accepted by the compiler) command is a 'bit-bang' method of SPI communication on the X1 and X2 parts ONLY.
All other parts must use the sample program included below to duplicate this behaviour. For a hardware solution for X1/X2 parts see the 'hshin' command.
By default 8 bits are shifted into the variable. A different number of bits (1 to 8) can be defined via the optional / bits. Therefore, for instance, if you require to shift in 12 bits, do this as two bytes, one byte shifting 8 bits and the second byte shifting 4 bits. Note that if you are using the LSB first method, the bits are shifted right (in from the left) and so shifting just 4 bits would leave them located in bits 7-4 (not 3-0). With the MSB method the bits are shifted left (in from the right).
When connected SPI devices (e.g. EEPROM) remember that the data-in of the EEPROM connects to the data-out of the PICAXE, and vice versa.
Other PICAXE microcontrollers do not have a direct spiin (shiftin) command. However the same functionality found in other products can be achieved by using the sub procedures listed below.
Effect of increased clock speed
Increasing the clock speed increases the SPI clock frequency.