Electronic – Understanding a SPI command sheet

raspberry pispi

I am interested in learning more about how SPI works in general, but with the raspberry pi and py-spidev library in mind. I am very technically savvy, although not so much on the EE side of things.

I am attempting to communicate to a piece of equipment via SPI and have been given only a spreadsheet with some information regarding the byte commands and timing. I have already determined that the SPI mode is 1, clock speed should be 300kHz, and word length is 8 bits. A snapshot of the command sheet is seen below. They should be joined end-on-end.

Part 1
Part 2

I have attempted to communicate using the py-spidev library and have seen some hopeful numbers (I think). Example:

import spidev
spi = spidev.SpiDev()
spi.open(0, 0)
spi.mode = 1
spi.max_speed_hz = 500000

spi.xfer2([0x03, 0x00])

I am under the impression that this should turn ON the digital pot, which it does not. However, I do see the values [3, 0] returned, which leads me to believe that something is happening.

What is the difference between Bytes(s) out and Byte(s) in? I am under the assumption that if I send the command xfer2([0x03, 0x00], 500000, 9000) I should receive the bytes 0xF3 and 0x03. Is that correct?

I am really at a loss for how to proceed and would love references to good tutorials/descriptions.

After finally receiving my Saleae Logic Analyzer, I have an update. It appears the chip select pin isn't working? Does anyone have tips for debugging this on a Pi specifically?
enter image description here

Best Answer

With spi devices, you need to shift something out in order to get something back.

Normally that means sending a command, then shifting some zeros to all the device to respond. If you are sending a command, the device doesn't know how to react until it has received it.

So here is a possible solution, shift the command byte, then the 'bytes out' then some zeroes equal to the number of bytes you want back. Here is the example array to send:

0x03 0x03 0x00 0x00 0x00

Try that, and try it also without the first one. After the transfer the array should have 0xf3 and 0x03 in the last two bytes

Related Topic