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:
# Importsfrom ctypes import*from dwfconstants import*import sys
import time
# Load dwf libraryif 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:
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.
Question
Nico G
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:
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:
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
Archived
This topic is now archived and is closed to further replies.