Jump to content
  • 0

Trouble with SPI in Digital Discovery - DigitalSpiReadOne returns 0 and blue LED turns on


Nico G

Question

I am programming a Digital Discovery with WaveForms SDK (in Python) to communicate via SPI with an FPGA.

The SPI comunication has 16 bit words. First, I have to send the address to read or write (the first bit of the 16 bit word indicates whether it is a read 0 or a write 1). Then, in the second 16 bit word, I read the data if it was a read operation, or I send the data if it was a write operation.

I have the following code:

# Imports
from ctypes import *
from dwfconstants import *
import sys
import time

# Load dwf library
if sys.platform.startswith("win"):
  dwf = cdll.LoadLibrary("dwf.dll")
elif sys.platform.startswith("darwin"):
  dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
  dwf = cdll.LoadLibrary("libdwf.so")

# Open the Digital Discovery device
hdwfDD = c_int()
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwfDD))

# Configure digital voltage to 1.8 V and system frequency to 100 MHz
dwf.FDwfAnalogIOChannelNodeSet(hdwfDD, c_int(0), c_int(0), c_double(1.8))
dwf.FDwfAnalogIOChannelNodeSet(hdwfDD, c_int(0), c_int(6), c_double(100e6))
dwf.FDwfAnalogIOEnableSet(hdwfDD, c_int(True))

# Configure SPI
dwf.FDwfDigitalSpiFrequencySet(hdwfDD, c_double(1e6)) # 1 MHz
dwf.FDwfDigitalSpiClockSet(hdwfDD, c_int(4))
dwf.FDwfDigitalSpiDataSet(hdwfDD, c_int(0), c_int(6)) # MOSI
dwf.FDwfDigitalSpiDataSet(hdwfDD, c_int(1), c_int(15)) # MISO
dwf.FDwfDigitalSpiModeSet(hdwfDD, c_int(0 | (0 << 1))) # Polarity 0; Phase 0
dwf.FDwfDigitalSpiOrderSet(hdwfDD, c_int(0)) # LSB

# Configure the address 1 to value 5000
time.sleep(200e-6)
dwf.FDwfDigitalSpiWriteOne(hdwfDD, c_int(1), c_int(16), c_int(0x8000 | 1))
time.sleep(200e-6)
dwf.FDwfDigitalSpiWriteOne(hdwfDD, c_int(1), c_int(16), c_int(5000))
# Read the value in address 1 to check if data has been set correctly
time.sleep(200e-6)
dwf.FDwfDigitalSpiWriteOne(hdwfDD, c_int(1), c_int(16), c_int(1))
time.sleep(200e-6)
rxData = c_int()
dwf.FDwfDigitalSpiReadOne(hdwfDD, c_int(1), c_int(16), byref(rxData))

 

All the dwf functions return 1 (including dwf.FDwfDigitalSpiWriteOne). I have also checked that the SPI writes are working with an oscilloscope.

The problem is with the function dwf.FDwfDigitalSpiReadOne, that returns 0.
What does this mean?

Besides, when this function is executed, the Digital Discovery turns on a blue LED.
What is the meaning of this blue LED?

I have run the following code after the unsuccessful DigitalSpiReadOne trying to obtain an error message:

szerr = create_string_buffer(512)
dwf.FDwfGetLastErrorMsg(szerr)
print(str(szerr.value))

# Prints: b''

But nothing is printed.

I want to add that the same SPI configuration works perfectly in an Analog Discovery 2. The problem is I want the SPI to work at 1.8 V, and as far as I know, the Analog Discovery 2 only works at 3.3 V.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Hi @Nicolas Gammarano

Instead of the FDwfDigitalSpiWriteReadOne please use its equivalent function:
txData = c_int(0)
rxData = c_int()
dwf.FDwfDigitalSpiWriteRead16(hdwfDD, c_int(1), c_int(16), byref(txData), c_int(1), byref(rxData), c_int(1))

The WriteOne with DD is fixed for the next software release. Thank you for the observation.

The left LED indicates triggering:

image.png.f26be19025c52bb34aeba49dc52b68e9.png

Link to comment
Share on other sites

Thank you for the quick reply @attila.

Was the FDwfDigitalSpiWriteOne or FDwfDigitalSpiReadOne function that I should replace with FDwfDigitalSpiWriteRead16? Or both?
I ask this because the function that did not work for me was FDwfDigitalSpiReadOne (always returns 0), and you said

Quote

Instead of the FDwfDigitalSpiWriteOne please use its equivalent function:

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...