Name:
hspiin
Syntax:

HSPIIN (variable, {,variable,...}) HSHIN (variable, {,variable,...})

Variable - receives the data.

Description:

The hspiin (hshin also accepted by the compiler) command shifts in a data byte using the SPI hardware pins.

This command receives SPI data via the microcontroller's SPI hardware pins. This method is faster and more code efficient than using the 'bit-banged' spiin 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.

Applies To:
20X2, 28X1, 28X2, 40X1, 40X2
See Also:
Related Create:
Share:
Print:

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.

Comments

  • Login to leave a comment.