LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

USB 8451 SPI Error (C++)

Hello,

I am brand new with with this SPI protocol, so pardon my innacuracies. I have 4 sensors connected to the USB 8451 device (connected the same way as the diagram I've attached plus two more chips where MOSI is the SDO, MISO is the SDI, and CS is the SS). The datasheet states that I should first hold the chip/slave select low to select the appropriate chip followed by a 10-byte word consisting of AA FF FF FF FF FF FF FF FF FF (all in hex). Since the chips are connected as diagramed, I used a customized version (attached to this message) of the "General Read" C++ program (packaged with the USB8451) to write 55 00 00 00 00 00 00 00 00 00. My program returns the following:

Searching for Devices

USB0::0x3923::0x7166::00E3C478::RAW initialized successfully

Data received:

 AA
 FF
 FF
 FF
 FF
 FF
 FF
 FF
 FF
 FF
 33
 33
 33
 33
 33
 33
..and so on with 33 indefinately..

Firstly you'll notice that the response is exactly the inverse of the 55 00 00 00 00 00 00 00 00 00 that I sent: this is probably expected. The problem is that those 33's shouldn't be there! Since the chip should return a 10-byte word starting with 2-bytes FF and ending with 4-bytes FF (data in between these bytes). Is there something that I am assuming incorrectly about the NI USB-8451? Will the data return interlieved between each byte of my initial written word? Since this is basically operating in half-duplex: is the SDI line listening too soon? How could I change that if it was?

Thanks for your time,
Nathan
Download All
0 Kudos
Message 1 of 9
(5,477 Views)
Nathan,

Can you please give me more information concerning which manual you were referencing also which device you are talking to? Have you tried to use a shipping example that was not modified?

What is the output that you are expecting to occur? I know that you said you are seeing 33 repeating, what do you expect to see instead of these?

Please let me know. Thank you very much.
Sarah S.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 9
(5,454 Views)
I am using the Melexis 90316 chips and the manual has been attached to this reply.

As for the response I am expecting: it is as stated above ..2 0xFF's following by 4 byte of data followed by 2 bytes 0xFF.

-n
0 Kudos
Message 3 of 9
(5,449 Views)
Nathan,

I have found a developer zone tutorial: Using the National Instruments USB-8451 I2C and SPI Interface, which steps through a related setup to yours. Although it is using a different device then what you are, I think it would be a great resource to ensure that the setup you currently have is correct.

Please let me know if this is able to help out in anyway. Thank you very much.
Sarah S.
Applications Engineering
National Instruments
0 Kudos
Message 4 of 9
(5,430 Views)
Hi Sarah,

This doesn't really help me at all since the lines are essentially setup as a full-duplex (not half, as I have to work with) and you end up using the I2C side of the 8451... I need to communicate using SPI: hence i need to wait to recieve the bits on the SDI line: Im not sure how to do this. Additionally: the setup is different from the one that I need here.

-Nathan
0 Kudos
Message 5 of 9
(5,426 Views)
Nathan,

I had a couple questions concerning the pin configuration you are using. Are you using the following configuration? Also what do you have connected to Pin 3: /SS?

Pin 1: Vdd                 Connected To Pin 2    
Pin 2: Test0 GND     Connected To GND    
Pin 3: /SS                 Connected To ????
Pin 4: SCLK             Connected To Pin 16 
Pin 5: MOSI              Connected To Pin 14
Pin 6: Test1 GND     Connected To GND
Pin 7: VDig               Connected To GND 
Pin 8: Vss GND        Connected To Pin 1

Thanks


Message Edited by Sarah_S on 11-09-2007 11:34 AM
Sarah S.
Applications Engineering
National Instruments
0 Kudos
Message 6 of 9
(5,411 Views)
Hi Sarah,

The SS (slave select) line (pin 3 on the chip) is connected to CS (chip select...so same thing) line CS0 (so that's pin 13 on the USB 8451). Also: the MOSI line (pin #5 on the Melexis chip) is connected through a transistor (2N5457) on the "source" pin to the SDI line (pin 15 on the USB 8451). Pin 14 (the SDO) line is connected to the "gate" of the transistor. It is as illustrated in figure 17.4.2 on page 33 of the specs for the Melexis chip. I hope that clears the connection...and gives you a better idea of how you can help!!

Thanks for your time!
-n
0 Kudos
Message 7 of 9
(5,398 Views)

Hi,

I had a look to the chip manual and your code and here is what i found:

Mainly code issues. You are seeing all those hex 33s because he is writing/reading 200 bytes in his script instead of 10. The chip requires at least a 1.5 ms delay between its "frames" (a frame being a 10-byte SPI write/read). See the code below with comments in red:

uInt8 WriteData[200];

// write array for address bytes // Why 200? Only 10 bytes are transferred.

uInt32 ReadSize = 200;

// Why 200? Only 10 bytes are transferred.

uInt8 ReadData[200];

// read array for bytes to read // Why 200? Only 10 bytes are transferred.

.

.

WriteSize = 200;

// Write size should be 10 and not 200.

WriteData[0] = 0x55;

// Okay, I think this makes sense for 2N5457 transistor (N-channel instead of P-channel as shown in datasheet)...

WriteData[1] = 0x00;

WriteData[2] = 0x00;

WriteData[3] = 0x00;

WriteData[4] = 0x00;

WriteData[5] = 0x00;

WriteData[6] = 0x00;

WriteData[7] = 0x00;

WriteData[8] = 0x00;

WriteData[9] = 0x00;

.

.

/* configure Polarity and Phase */

errChk (ni845xSpiScriptClockPolarityPhase (ScriptHandle,

kNi845xSpiClockPolarityIdleLow, kNi845xSpiClockPhaseFirstEdge));

//kNi845xSpiClockPhaseSecondEdge));

// Polarity looks good. Phase should be kNi845xSpiClockPhaseSecondEdge. From the datasheet, CPOL=0, CPHA=1.

.

.

/*issue a delay to allow the MLX90316 to boot up*/

errChk (ni845xSpiScriptDelay (ScriptHandle, 1));

// From the datasheet, 6.9us required between CS LOW and first clock... He may not need this delay here, but won't hurt anything...

/* write data array */

errChk (ni845xSpiScriptWriteRead (ScriptHandle, WriteSize, WriteData, &ScriptReadIndex));

/*issue a delay to allow the MLX90316 for a response*/

errChk (ni845xSpiScriptDelay (ScriptHandle, 20));

// Not necessary... The 90316 "responded" as the

// data was being transferred (during ni845xSpiScriptWriteRead).

/* issue stop condition */

errChk (ni845xSpiScriptCSHigh (ScriptHandle, Chip0Select));

/*issue a sync delay between MLX90316 frames (an MLX90316 frame being an SPI write/read of 10 bytes)*/

errChk (ni845xSpiScriptDelay (ScriptHandle, 2));

// The datasheet does specify that the CS line must

// held HIGH between 10-byte (MLX90316 frame) accesses, for 1.5 ms. The resolution of our delay is 1 ms, so he should write a delay of 2

// to meet their minimum. This should be here for when he uncomments the while loop (should follow each 10-byte write/read)...

For a single write read try the basic code attached to this answer.

Concern: I don't see mention of a pullup resistor, but everything else looks correct. Melexis does not specify a part number or electrical characteristics for the transistor to use anywhere in the datasheet. Whether or not the 2N5457 you have choosen chosen is appropriate or not is unknown. The 8451 provides a "standard" SPI interface with separate MOSI and MISO pins (and our documentation provides voltage and current characteristics for those pins). Melexis has developed their own 1-wire version of SPI that requires a custom circuit between the 8451 (or any other "standard" SPI master) and their slave.

DirkW

0 Kudos
Message 8 of 9
(5,367 Views)
aha! got it! The problem was actually this: DirkW, you mentioned something about the transistor...and that was exactly the problem. I had originally recieved an n-type JFET as opposed to a MOSFET unit...problem with this is that there was current leakage! So whenever the data lines would try to communicate, there would be no way to sharply move between bit values (the voltage would kinda move around sloppily, if at all). I had those 200 values in there b/c I was thinking that the communication from the chip would happen AFTER the signal sent from the 8451: this was obviously incorrect (as per your commentary in the corrected code snippet of your message).

One question is: I ran your code without any sort of delay...if I wanted to call this code continuously, I would obviously have to have that 2ms pause after each 10-bit word: is this feature only available in "script" mode? or is there another 2ms delay that I can use from the NI library? Why is scripting better/important?

Thank you very much!
0 Kudos
Message 9 of 9
(5,350 Views)