On Wed, 21 Jun 2017 01:05:18 -0700 (PDT),
zvonimir...@gmail.com declaimed the
following:
>This code is not working. First problem is that line
>
>id = spi.xfer2([128,0])
>
>returns 0xf2. If 128 is replaced with 64 I get 0x79. If 128 is replaced
>with 0 I get 0xe5. I cannot debug this because I don't know what exactly
>this line does. By answering questions above, you would help me a lot.
>
Per the data sheet (page 16, figure 38 -- presuming you wired for
4-wire mode) that defines a single byte read operation at address 0, with
dummy output data of 0 (as the input has to be clocked from it).
|1|0|00000 00000000
| | | |data
| | |address (register)
| |single byte (1 = multiple byte)
|read (ignore sent data) (0 = write data to register)
Also (page 23 table 19) address 0 is DEVID, which is read-only and has
the value 11100101 (0xe5)
0xf2 => 11110010
0x79 => 01111001
0xe5 => 11100101
I'd say there is some sort of timing problem somewhere in that system (0x64
should be a multibyte WRITE operation, 0x00 is a single byte write). Note
that the other values you see are bit-shifted to the right with an
additional leading 1 bit (one bit shift, and two bit shift).
I've not encountered "spidev" module before. Have you tried the
Adafruit_BBIO module?
># Setup SPI
>spi = spidev.SpiDev()
>#spi.mode = 3 <-- Important: Do not do this! Or SPI won't work as intended, or even at all.
Interesting -- this line is commented out, yet...
>spi.open(2,0)
>spi.mode = 3
... after opening the device, they then set the same mode that was just
warned against.
Page 4890 of the TRM describes the four values for mode, and it does
seem to match page 15 of the data sheet...
Given the apparent bit-shifts described above, you might try reducing
the clock speed from 3.5MHz... And making sure you have similar wire runs
for clock, data-out, data-in, with similar capacitances -- since the data
shift described above could be a matter of being out of sync with the clock
vs data lines.
--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/