Is there an SPI tutorial anywhere ?

womai

Senior Member
No there isn't any such tutorial for the Picaxe yet, but there has been a number of posts on this forum on that subject. Also, have a look at the shiftin/shiftout routines in the Basic manual, and at the timing diagrams in any data sheet of a device that uses SPI.

SPI is really a simple protocol. To write data to a device it's usually like this:

(1) pull chip select (CS) line and clock line (CLK) low
(2) apply data bit (high or low) to input (DIN)
(3) strobe clock, i.e. pull it high and then low again
(4) repeat (2) and (3) until all bits are shifted in
(5) pull CS high again

To read data from a device (e.g. ADC) is almost the same:

(1) pull chip select (CS) line and clock line (CLK) low
(2) strobe clock, i.e. pull it high and then low again
(3) read data bit (high or low) from the chip output (DOUT)
(4) repeat (2) and (3) until all bits are shifted out
(5) pull CS high again

The latest Picaxe chips (28X1, 40Z1) have built-in SPI commands that do just what above text describes automatically (only steps 2 to 4; you still have to take care of CS); on older you need to program it by hand.

Wolfgang
 
Top