Hi all,
Newb here, having problems with a T7 using DAQfactory getting the SPI example to work on https://labjack.com/support/datasheets/t-series/digital-io/spi
When I try to run the code below:
1
2 using("device.labjackm")
3 global string id = "any"
4
5 LJM_eWriteName(id, "SPI_CS_DIONUM", 0) // Use DIO0 as chip select.
6 LJM_eWriteName(id, "SPI_CLK_DIONUM", 1) // Use DIO1 as Clock
7 LJM_eWriteName(id, "SPI_MISO_DIONUM", 2) // Use DIO2 as MISO
8 LJM_eWriteName(id, "SPI_MOSI_DIONUM", 3) // Use DIO3 as MOSI
9
10 LJM_eWriteName(id, "SPI_MODE", 0) // Select mode zero.
11 LJM_eWriteName(id, "SPI_SPEED_THROTTLE", 65500) // Set clock speed to ~100 kHz.
12 LJM_eWriteName(id, "SPI_OPTIONS", 0) // No special operation
13 LJM_eWriteName(id, "SPI_NUM_BYTES", 1) // Transfer one byte.
14
15 LJM_eWriteNameByteArray(id, "SPI_DATA_TX", 0) // Load a test data byte.
16 LJM_eWriteName(id, "SPI_GO", 1) // Initiate the transfer
17
18 ? LJM_eReadNameByteArray(id, "SPI_DATA_RX")
I get the following error:
Write error with LabJack M: LJME_RECONNECT_FAILED: SPI_test Line 16 - Uncaught error in sequence SPI_test
02/02/18 11:01:31.000
: Read error with LabJack M: LJME_RECONNECT_FAILED
02/02/18 11:01:31.500
: Read error with LabJack M: LJME_RECONNECT_FAILED
Could someone please point out what I'm doing wrong?
Thanks!
Edit: The below workaround does not currently work because DAQFactory does not support LJM_eAddresses.
DAQFactory doesn't currently have support for LJM_eReadNameByteArray, as of writing.
The way to do it without LJM_eReadNameByteArray is to do this:
I've attached an example C program, spi.c, which demonstrates this. Please let me know if you have any questions about it or other feedback.
Dear Labjack,
Thanks for the above. DAQfac are still working on eReadNameByteArray, so I am trying to use your examples to make a dll for it in C# in the meantime.
I'm now having problems getting the data from the encoder (https://www.mouser.com/ds/2/54/EMS22A-50229.pdf ). The encoder works fine on my arduino using the simple script attached. In my C# LJM code though I seem to be missing the first bit of data. Please see the the encoder signal diagram, and the full datasheet also, attached. I have SPI_MODE = 2, and OPTIONS = 0. I've tried THROTTLE set to a variety of values from 1 to 4900 to 20000 to 0, but none seems to fix this. I'm wondering if it could be to do with the tCLKFE or other timings for the encoder? If so is there a way to fix this?
Many thanks,
Oli
P.S. I haven't posted my LJM code as if you can't see an issue with the diagram, I will just try translating the arduino code across OK.
Try cycling through the SPI modes. 1 and 2 look like they should work. Try them all just to be sure.
Yes sorry that was all it was. Works great now, cheers!