- Name:
- hspiout
- Syntax:
-
HSPIOUT (data, {,data,...})
HSHOUT (data, {,data,...})
Data - is a constant/variable of the byte data to output
- Description:
-
The hspiout (hshout also accepted by the compiler) command shifts out data byte using the SPI hardware pins.
This command transmits SPI data via the microcontroller's SPI hardware pins. This method is faster and more code efficient than using the 'bit-banged' spiout command.
When connecting SPI devices (e.g. EEPROM) remember that the data-in of the EEPROM connects to the data-out of the PICAXE, and vice versa. Note that a hspisetup command must be issued before this command will function. Due to the internal operation of the microcontrollers SPI port, a hspiout command will only function when the hspiin 'input pin' is in the expected default state. If this pin is incorrect (e.g. high when it should be low), the hspiout byte cannot be sent (as the microcontroller automatically detects an SPI error condition). After 2.3 seconds of fault condition the PICAXE microcontroller will automatically reset.
- Applies To:
- 20X2, 28X1, 28X2, 40X1, 40X2
- See Also:
- Related Create:
This example shows how to read and write to a 25LC160 EEPROM.
Pin connection of the EEPROM is as follows:
1 | - CS picaxe output 7 (B.7) |
2 | - SO picaxe input 4 (C.4) |
3 | - WP +5V |
4 | - Vss 0V |
5 | - SI picaxe input 5 (C.5) |
6 | - SCK picaxe input 3 (C.3) |
7 | - HOLD +5V |
8 | - Vdd +5V |
- Code Example:
-
init: hspisetup spimode11e, spimedium ; spi mode 1,1 low cs ; enable chip select hspiout (6) ; send write enable high cs ; disable chip select low cs ; enable chip select hspiout (1,0) ; remove block protection high cs ; disable chip select pause 5 ; wait write time main: low cs ; enable chip select hspiout (6) ; send write enable high cs ; disable chip select low cs ; enable chip select hspiout (2,0,5,25) ; write 25 to address 5 high cs ; disable chip select pause 5 ; wait write time of 5ms low cs ; enable chip select hspiout (6) ; send write enable high cs ; disable chip select low cs ; enable chip select hspiout (3,0,5) ; send read command, address 5 hspiin (b1) ; shift in the data high cs ; disable chip select low cs ; enable chip select hspiout (4) ; send write disable high cs ; disable chip select debug pause 1000 goto main
Copy Code Submit an Example
Submit Your Own Code!
You must be logged in to submit code examples. Login now.