2
\$\begingroup\$

I am working with someone else's code, and I have a question about several of the SPI transactions that are performed. The hardware configuration consists of a Raspberry Pi (master) and a motor driver board (slave). They are using the spidev Python library. The code to initialize and configure the SPI connection proceeds as follows:

import spidev

bus = 0 # SPI bus (channel 0 for Pi)
device = 0 # Device / chip select

spi = spidev.SpiDev() # Enable SPI
spi.open(bus,device) # Open connection on bus to device

# Set SPI speed and mode
spi.max_speed_hz = SPI_freq
spi.mode = 1

Then, they use xfer2() to perform the SPI transactions.

spi.xfer2((0x28, 0x00, 0x01)) #0x280001
spi.xfer2((0x38, 0x00, 0x01)) #0x380001
spi.xfer2((0x20, 0x00, 0x0F)) #0x20000F
spi.xfer2((0x30, 0x00, 0x00)) #0x300000

My question is this: 1.) What is actually happening in this SPI transaction? and 2.) What is the purpose of splitting, say, 0x280001 into a tuple of three, like (0x28, 0x00, 0x01)?

\$\endgroup\$
1

1 Answer 1

0
\$\begingroup\$
  1. What is happening is that the bytes are sent out as single SPI transaction on each line. The four lines send four transactions. What those transactions mean is up to the slave chip.

  2. The SPI bus usually sends out bytes so it makes sense to define the sequence of bytes you want to send.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.