Skip to main content
added 186 characters in body
Source Link

I have an application where I want to write to an external DAC and read from an external ADC using the pi's SPI interface continuously.

The data to the DAC could come from some arbitrary function, and the result from the ADC I want to put into a file for later post-processing.

schematic

simulate this circuit – Schematic created using CircuitLab

I have done this using the spidev module in python, and this works fine. However, the application requires the timing for both transactions to be consistent, i.e. happening exactly every 1 ms, so I can't just do a:

i = 0
while True:
    ADC = myADCfile.write(spi.readbytes(16))
    DAC = spi.writebytes(valuesarb_function(i))
    time.sleep(0.001)
    i += 1

Because then the timing will depend on the CPU's priorities..

According to the broadcom documentation [1], the pi has a DMA that can control the SPI. However, I can't figure out how to set this up, and I haven't found any examples.
[1] https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Can anyone point me to an example (preferably in python), or some resources on this?

I have an application where I want to write to an external DAC and read from an external ADC using the pi's SPI interface continuously.

schematic

simulate this circuit – Schematic created using CircuitLab

I have done this using the spidev module in python, and this works fine. However, the application requires the timing for both transactions to be consistent, i.e. happening exactly every 1 ms, so I can't just do a:

while True:
    ADC = spi.readbytes(16)
    DAC = spi.writebytes(values())
    time.sleep(0.001)

Because then the timing will depend on the CPU's priorities..

According to the broadcom documentation [1], the pi has a DMA that can control the SPI. However, I can't figure out how to set this up, and I haven't found any examples.
[1] https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Can anyone point me to an example (preferably in python), or some resources on this?

I have an application where I want to write to an external DAC and read from an external ADC using the pi's SPI interface continuously.

The data to the DAC could come from some arbitrary function, and the result from the ADC I want to put into a file for later post-processing.

schematic

simulate this circuit – Schematic created using CircuitLab

I have done this using the spidev module in python, and this works fine. However, the application requires the timing for both transactions to be consistent, i.e. happening exactly every 1 ms, so I can't just do a:

i = 0
while True:
    myADCfile.write(spi.readbytes(16))
    spi.writebytes(arb_function(i))
    time.sleep(0.001)
    i += 1

Because then the timing will depend on the CPU's priorities..

According to the broadcom documentation [1], the pi has a DMA that can control the SPI. However, I can't figure out how to set this up, and I haven't found any examples.
[1] https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Can anyone point me to an example (preferably in python), or some resources on this?

Source Link

RPi DMA transfer over SPI

I have an application where I want to write to an external DAC and read from an external ADC using the pi's SPI interface continuously.

schematic

simulate this circuit – Schematic created using CircuitLab

I have done this using the spidev module in python, and this works fine. However, the application requires the timing for both transactions to be consistent, i.e. happening exactly every 1 ms, so I can't just do a:

while True:
    ADC = spi.readbytes(16)
    DAC = spi.writebytes(values())
    time.sleep(0.001)

Because then the timing will depend on the CPU's priorities..

According to the broadcom documentation [1], the pi has a DMA that can control the SPI. However, I can't figure out how to set this up, and I haven't found any examples.
[1] https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf

Can anyone point me to an example (preferably in python), or some resources on this?