Starting up SPI.

Hello everyone.
Arduino newby here. I have Mega 1280

I Wanted to test my temp sensors, using SPI. I found a library, but not for Mega. I uploaded it to my mega (With changing SPI pins), but it's not working, so I decided to start from a scratch.

this is my test code, configuring SPI, and Serial, and sending test data on SPI (At least it should)
On my scope, I don't see any signal on clock pin, or any others.

/*************************************************
 * Arduino  }  ADT7310
 * pin 52    }  pin 1  (SCLK)
 * pin 50    }  pin 2  (DOUT)
 * pin 51    }  pin 3  (DIN)
 * pin 53    }  pin 4  (CS)
 * 
 **/

#include <SPI.h>

void setup()
{

  SPI.setDataMode(SPI_MODE3);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setBitOrder(MSBFIRST);

  Serial.begin(9600);
  SPI.begin();

  Serial.println("done"); 
}

void loop() {
  SPI.transfer(0x84);
  Serial.println("Xmit");
  delay(1000);
}

can anyone, please,guide me in the right tracks?

BR. gr00ve

I used your exact code on my Mega2560 and got a signal on the clock line. See attachment.

I should point out that it is very brief - the entire set of pulses shown has a width of 958 ns - that is 0.958 microseconds. Unless you have a trigger set up you may well miss it. Try taking out the 1-second delay.

SPI_Logic_Analyzer_Mega2560.png

Also if you want your device to respond you have to drop CS low - otherwise it will ignore the clock pulses (assuming it is active low).

hmm. interesting.
I'd like to know, what I'm doing wrong.
nothing on the outputs.
Except solid High, or Low.

Temp. Sensor.
ADT7310

Datasheet
http://www.analog.com/static/imported-files/data_sheets/ADT7310.pdf

Article with Library

SPI doesn't care if the device is there or not. What happens if you try with nothing connected, just measure the pins?

nothing on the outputs.
Except solid High, or Low.

What are you measuring this with?


Rob

gr00ve:
hmm. interesting.
I'd like to know, what I'm doing wrong.
nothing on the outputs.
Except solid High, or Low.

Try also using 128 as divider value (SPI_CLOCK_DIV128), just in case your scope is too slow.

And remove the delay(Nick Gammon already said that) and serial print. They don't help in this circumstance. Better would be to monitor the result of the transfer for later when you attach the sensor, smth like:

char outb[4];
sprintf(outb,"%02x ", SPI.transfer(0x84));
Serial.print(outb); // add line feed in case you like

Graynomad
It´s a Tektronix TDS-220
It should be able to see signal at full speed, right?

Ok. Turned speed town, with 128 divider, and now I can see some signals on MOSI, SCK and SS.
but still, I cannot get anything back from my sensor.

I think I should first start with something more simple, and then get back to this later.
Second -- Maybe I fried something during the soldering process. I improvised and soldered SOIC chip onto a breadboard, with a help of some wires.

And maybe somebody can explain me, can I pull the CS pin on the chip to the ground, without the use of SS pin from the Mega?

You have plenty of pins, right? But according to the datasheet:

CS can be tied to ground, and the serial interface can be operated in a 3-wire mode. DIN, DOUT, and SCLK are used to communicate with the ADT7310 in this mode.

However tying CS to ground precludes your using your SPI pins (MOSI, MISO, SCLK) for other SPI devices, because the temperature sensor will respond too.

And despite what the datasheet says about tying CS to ground, it also says on the same page:

The read transaction finishes when the master takes CS high.
The master must begin a new read transaction on the bus for every register read.

So that implies that taking CS high is important.

It´s a Tektronix TDS-220
It should be able to see signal at full speed, right?

Yes, but I would have it in single-shot mode and have a trigger set up on that line. Otherwise the pulses will come in too fast to capture them. It only captures 2500 points, if left running in auto mode that brief pulse per second won't be remembered for very long.