SPI Documentation

nfk

Senior Member
Hi All,

Can anyone tell me if there is any documentation on the use of SPI with PICAXE? I have searched around this forum and the Rev Ed documentation with no luck. I have a project starting soon where I have to use it so I need to learn fast!

There is a tantalizing reference to some "excellent documentation" here...

http://www.picaxeforum.co.uk/showthread.php?t=3285&highlight=spi+documentation

...but unfortunately the link seems to be broken.

Any help/examples would be much appreciated.

Incidentally, the project is to control a DAC (the AD7390ANZ shown) with a PICAXE 20X2.

Cheers,
Nigel

 
Last edited:

hippy

Ex-Staff (retired)
There's very little to SPI in general; setting a data output line high or low while pulsing a clock line to transfer that data to the receiver, raising and lowering the clock line while reading from a data in line. There may be enable and reset signals as well but it all comes under the general heading of 'bit banging'; making sure the lines all change state in the right order and are held as they must be for however long required.

Some PICAXE offer HSPI capabilities, where the same is achieved by specifying the parameters for data output and input and leaving the hardware to do the actual bit-banging.

What sequence of data bits needs to be put out will depend on what device is being controlled by an SPI data bus and will often be specific to each.

Google turns up a number of "SPI tutorial" including ...

ww1.microchip.com/downloads/en/devicedoc/spi.pdf
 

nfk

Senior Member
Hi Hippy,

Thanks for that. I'm beginning to get my head around it now.

Cheers,
Nigel
 

hippy

Ex-Staff (retired)
I would personally recommend implementing any SPI interface in software as bit-banged code before going to HSPI, and to try bit-banging if starting with HSPI and it doesn't work. With the X2 PICAXE's ( and maybe others ) it's possible to use the same lines for bit-banging which the HSPI would use so the hardware will be the same in each case.

Looking at the SOMO 14D example code that doesn't appear to be compatible with HSPI as there's no clock pulse per se for the last bit sent. That may be a bug in the code or it may actually be what the device requires ( I haven't investigated ). By using bit-banged code first you will know the device can be controlled and can determine what HSPI mode should be used if HSPI compatible.

Bit-banging also means you can step through the code in the simulator and see what is happening on each signal line and check it matches with the device specification, whereas with HSPI you really need a scope or logic analyser.
 

nfk

Senior Member
Again, thanks everyone - this is most helpful.

<UPDATE> Got it working fine.

Cheers,
Nigel
 
Last edited:
Top