How do I figure out hspisetup for LTC1298?

Pongo

Senior Member
How do I figure out hspisetup for LTC1298? - Resolved

I've been bit banging LTC1298's but now I'm going to use one with a 20x2 so I thought I would use hspi. Seemed a good idea until I had to figure out the hspisetup command. Can someone point me to an idiot's guide to doing that? The LTC1298 datasheet can be found here.
 
Last edited:

Goeytex

Senior Member
Hi Pongo,

Seems no one here has any experience with the LTC1298, me included. However, if I were trying to use HSPI with this device, I would probably write a short program that tests each mode until I find the one that works. My guess is that mode 00 should work.
 

Pongo

Senior Member
Thanks for your reply Goeytex :) I guess I'll just have to give that a try. I was hoping there was some hidden document somewhere that interprets this:

spimode00 (CKP=0, CKE=1, SMP=0) Mode (0,0)
spimode01 (CKP=0, CKE=0, SMP=0) Mode (0,1)
spimode10 (CKP=1, CKE=1, SMP=0) Mode (1,0)
spimode11 (CKP=1, CKE=0, SMP=0) Mode (1,1)
spimode00e (CKP=0, CKE=1, SMP=1)
spimode01e (CKP=0, CKE=0, SMP=1)
spimode10e (CKP=1, CKE=1, SMP=1)
spimode11e (CKP=1, CKE=0, SMP=1)

Even the screenshots are too fuzzy to read in my .pdf reader :(
 

srnet

Senior Member
I have used a few SPI devices on a PICAXE, it never occured me to look at the screenshots of the Logic Anaylzer.

The explanation is just underneath the HSPISETUP command itself, for instance;

spimode00 (mode 0,0 - input sampled at middle of data time).

So the (data) input is sampled at the middle of the data time (in the middle of the clock)

If your bitbanging works OK, you should be able to tell from your code which mode matches.

And spimode00 works on quite a few devices, so maybe just experiment ?
 

srnet

Senior Member
You might want to take a look at this;

http://www.picaxeforum.co.uk/showthread.php?25837-High-Altitude-Balloon-Tracker-and-using-the-SST25VF032B-4Mbyte-Flash-memory

It looks at the various ways of driving an SPI device on a PICAXE.

The purpose was to see if you could get acceptable performance driving SPI devices on the second hardware interface thats fitted to the 28X2 and 40X2. The peeksfr and pokesfr method works well enough. Once you know which registers to set, you would expect this approach to work on a M2 as well, and is around 30 times faster than bit banging.
 

Pongo

Senior Member
Thanks for the extra info srnet. I'm working on it, a DSO would help but Christmas is a long way off :(
 

srnet

Senior Member
I have a DSO here, but only used it to check the clock pulses were going out to be sure the pokes to the registers on the PIC were actually working.

For the rest I just compared what the effect of the various HSPIsetup options had on the actual PIC registers and then looked at what that meant in the PIC data sheet versus the requirements in the device datasheet.

And experimented of course.
 
Last edited:

hippy

Ex-Staff (retired)
Here's the waveform diagram from the Microchip datatasheets which show the waveform for each of the various modes ....
 

Attachments

Pongo

Senior Member
Thanks Hippy! That's just what I was looking for.

Hi Pongo,

Seems no one here has any experience with the LTC1298, me included. However, if I were trying to use HSPI with this device, I would probably write a short program that tests each mode until I find the one that works. My guess is that mode 00 should work.
Your guess is correct, in fact it doesn't seem to care much and appears to work equally well in any mode except 01 and 10.

Here's my code (helpful comments welcomed) for anyone who wants to try this nice 12 bit A/D chip.

Code:
#picaxe 20x2
#Terminal 9600
#No_Table
#No_Data

symbol sel = B.1 'chip select pin
symbol led = B.0 'obligatory blinking led
symbol setup = b0 'LTC1298 setup byte
symbol hibyte = b7 '1st byte from a/d
symbol lobyte = b6 '2nd byte from a/d
symbol adval = w3 'b6 + b7 combined as word

high sel

doit:

let setup = 13 'channel 0, non-diff mode, MSB first
for bit1 = 0 to 1 'bit1 is the channel select bit in b0
low sel
hspisetup spimode00, spislow 'spimode does not appear to be critical, 01 and 10 don't work
let adval = 0
hspiout (setup) 'set up LTC1298
hspiin (hibyte,lobyte) 'get 2 bytes
high sel
adval = adval << 1 'dump the first bit
adval = adval >> 4 'reduce result to 12 bits
sertxd("Channel ",#bit1," a/d count: ",#adval," ")

high led 
pause 100
low led

next bit1

sertxd(cr,lf)

goto doit:
 
Top