I'm using an 18F2520 with an AD7763 from Analog devices and trying to read the registers.
Some of the numbers I get back from it are fine.
But a couple seem a little odd, and these are from 24 bit registers.
Writing and reading are in whole bytes, so I decided to use SPI instead of Shift.
I couldn't find anything similar on-Forum or in-Help.
This is a simple routine I've been using to read 24 bits and put it into a LongWord.
Does it look roughly OK?
Code: Select all
Function Read24Bit(pAddress As Byte) As LongWord
Dim WBuffer As LongWord
wbuffer=0
CSR=0
SPI.WriteByte(pAddress) ' Note MSBit = 0 = a READ for AD7763
DelayUS(1)
Wbuffer.byte2 = SPI.ReadByte() ' MSByte first.
WBuffer.byte1 = SPI.ReadByte()
WBuffer.byte0 = SPI.ReadByte()
result = wbuffer
CSR=1
End Function
It's just that with the device's V & I diff amps shorted its still giving large numbers back.
I was expecting very low numbers heading towards zero.
Have I got the wrong 'end of the stick' concerning >1byte reads on SPI?
(Similar method but using WBuffer as Word for 16 bit seems OK).
Regards,
Francis.
Note1: The 'Delay' above was merely experimental as there were comments about small delays mentioned in Data Sheet. It makes no apparent difference with or without.
Note2: I have double-checked PCB continuity on my board.