- Name:
-
shiftout
- Syntax:
-
SPIOUT sclk,sdata,mode,(data{/ bits}, {data{/ bits},...})
SHIFTOUT sclk,sdata,mode,(data{/ bits}, {data{/ 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-3) which specifies the mode:
| 0 |
LSBFirst_L |
(LSB first, idles low) |
| 1 |
MSBFirst_L |
(MSB first, idles low) |
| 4 |
LSBFirst_H |
(LSB first, idles high) |
| 5 |
MSBFirst_H |
(MSB first, idles high) |
Data - is a variable/constant that contains the data to send.
Bits - (optional) is the number of bits to transmit. If omitted the default number of bits is automatically set to 8.
- Description:
-
The spiout (shiftout is also accepted by the compiler) command is a bit-bang 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 'hspiout' command.
By default 8 bits are shifted out. A different number of bits (1 to 8) can be defined via the optional / bits. Therefore, for instance, if you require to shift out 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 MSB first method, the bits are shifted left (out from the left) and so when shifting just 4 bits they must be located in bits 7-4 (not 3-0). With the LSB method the bits are shifted out 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.
Some PICAXE microcontrollers do not have a shiftout 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.