Jump to content
  • 0

Trouble reading SPI response


Chris Pouzou

Question

Hello,

I am building an SPI proof of concept for the Analog Discovery 2 in LabVIEW and I am unable to get the entire thing working, despite other successful LabVIEW projects that use the Analog Discovery 2.  The issue I am having is that I am capable of generating an SPI message output where the AD2 is the master, but I am unable to get the expected response in the Rx array.

The pinout is the clock is on pin 2, the chip select is on pin 1, the MOSI_SISO is on pin 4 and these three outputs are connected to an oscilloscope for observation.  The MISO is on pin 7 and is connected to a pullup resistor to 3.3V on a supply separate from the AD2.

I perform the following function calls in the following order after opening the AD2 and enabling the internal AD2 power supplies: DigitalSpiReset(hdwf), DigitalSpiClockSet(hdwf, 2), DigitalSpiDataSet(hdwf, 0, 4), DigitalSpiDataSet(hdwf, 1, 7), DigitalSpiSelect(hdwf, 1, 1), DigitalSpiFrequencySet(hdwf, 1000000), DigitalSpiModeSet(hdwf, 1), DigitalSpiOrderSet(hdwf, 1).

I perform the following function calls in a while loop to continually send and receive a SPI message: DigitalSpiSelect(hdwf, 1, 0), DigitalSpiWriteRead(hdwf, 1, 8, Tx array, 2, RXarray, 2), DigitalSpiSelect(hdwf, 1, 1).

If these functions worked as expected, I should get an Rx array back that has the values 0xFF for elements 0 and 1.  Instead I get an Rx array back with 0 for elements 0 and 1.

If I perform the exact same setup in waveforms, I can get the expected response with the exact same wiring setup.  Please see the screenshot attached to this post.

582178252_waveformsscreenshot.png.072dffdeb71ec874fdd84fe33c93b498.png

I am scratching my head on this one.  I can achieve the expected results in Waveforms, so I know my hardware is working properly, but I cannot get them working in my own program.  I don't know if I am missing an important SPI function call or what.

Edit: I applied a scope probe to the MISO pin as well and the MISO pin is pulling down the input voltage as if it were an output.  So my problem seems to be that the MISO line is not being correctly set as an input.

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

Hi @Chris Pouzou

I have repeated your test using Python and it is working. I have modified the SDK/ samples/ py/ Digital_Spi.py Digital_Spi2.py

I don't know which WF version are you using, try the latest one:
https://forum.digilentinc.com/topic/8908-waveforms-beta-download/

 

# continue running, driving output signals after device close
dwf.FDwfParamSet(c_int(4), c_int(0)) # DwfParamOnClose; 0 = run, 1 = stop, 2 = shutdown
....

dwf.FDwfDigitalSpiReset(hdwf)
dwf.FDwfDigitalSpiClockSet(hdwf, c_int(1))
dwf.FDwfDigitalSpiDataSet(hdwf, c_int(0), c_int(4))
dwf.FDwfDigitalSpiDataSet(hdwf, c_int(1), c_int(7))
dwf.FDwfDigitalSpiSelect(hdwf, c_int(0), c_int(1))
dwf.FDwfDigitalSpiFrequencySet(hdwf, c_double(1e6))

rgbTX = (c_ubyte*2)(0xAA, 0x55)
rgbRX = (c_ubyte*2)()

dwf.FDwfDigitalSpiSelect(hdwf, c_int(0), c_int(0))
dwf.FDwfDigitalSpiWriteRead(hdwf, c_int(1), c_int(8), rgbTX, c_int(len(rgbTX)), rgbRX, c_int(len(rgbRX))) # write to MOSI and read from MISO
print("TX: "+str(numpy.fromiter(rgbTX, dtype = numpy.uint8)))
print("RX: "+str(numpy.fromiter(rgbRX, dtype = numpy.uint8)))

dwf.FDwfDigitalSpiSelect(hdwf, c_int(0), c_int(1))

 

Link to comment
Share on other sites

59 minutes ago, attila said:

I don't know which WF version are you using, try the latest one:
https://forum.digilentinc.com/topic/8908-waveforms-beta-download/

Hello Attila,

Thank you for your response.  When you say I should update Waveforms, do these updates changes the dwf.dll file or just the waveforms application?  Because if it is just the application, then I don't think I need to worry about that.  The SPI in Waveforms works, it just doesn't work in LabVIEW when I call those functions that I listed.  I will inspect my function calls to make sure that I did not make a mistake on one of those.

Thanks Again!

Chris

Link to comment
Share on other sites

25 minutes ago, attila said:

The installer contains update for WF app as well for dwf.dll
It has separate sections for WF app (app+libs+help...) and WF runtime (dwf.dll+device files) and WF SDK (help+examples)

Thank you Atilla!  I think we have solved my issue.  After updating to 3.13.20 32 bit edition, the exact same function calls in LabVIEW now work and I am now reading 0xFF when the power supply is on.  Thanks again for all your support on these forums!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...