Pages: [1]   Go Down
Author Topic: SPI dead pins ?  (Read 998 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm trying to connect my Arduino Duemilanove-ATMEGA168 with a SPI device (ADIS1480, http://www.analog.com/en/mems-sensors/mems-inertial-measurement-units/adis16480/products/product.html).

In the attached sketch all I'm trying to do is to read the product ID of the device but I read always 0, regardless of the SPI settings (changing SPI clock speed, but even SPI mode, I always get zero readings).

After investigation with oscilloscope, I found that both SPI clock pin (D13) and MOSI pin (D11) do not carry any signal: D13 carries a constant 5V and D11 a constant 0V. I tried to disconnect the device and its interfacing board, leaving the Arduino running the sketch totally diconnected from the rest of the world, but also in this case I wasn't able to see any signal in either the SCK or the MOSI pins.

At this point I suspected that one the SPI pins was dead and I loaded the skech into a second Arduino board, but the results were identical. I also verified that the interfacing board that connects the Arduino to the sensor was not damaging the Arduino pins and I measured the resistance as seen by MOSI and SCK pins: it was a safe 15KOhm.

Now I'm suspecting that the SPI library, for some reasons, doesn't load into my Arduinos... even if all compiling and loading messages say that everything is OK.

Do you have any suggestion ?

Thank you very much for any help !


* Prova_SPI.ino (0.6 KB - downloaded 4 times.)
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5356
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Connect your o-scope to digital pin 10 and compile/upload this code.  Open the serial monitor and watch both the serial output and the o-scope. The test pin should go HIGH for half a second, then LOW for half a second. Does the pin output change?
Code:
int pinCheck = 10;

void setup() {
   Serial.begin(9600);
   pinMode(pinCheck,OUTPUT);
}

void loop() {
   Serial.println("tick");
   digitalWrite(pinCheck,HIGH);
   delay(500);
   digitalWrite(pinCheck,LOW);
   delay(500);
}
Then check pins 11-13 the same way.

edit: I hope it was not necessary to tell you to disconnect the AD device (and any other SPI device) while running these tests.
« Last Edit: October 16, 2012, 07:30:54 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Tim,

everything seems to work fine: voltage in pin 10 changes and serial message is been displayed.

Thank you for your support !
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Tim,

Also pins 11,12,13 correctly change voltage.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5356
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good. Then try this. It tests the SPI.
Code:
#include <SPI.h>
#define adCS 10

void setup() {
   Serial.begin(9600);
   pinMode(adCS,OUTPUT);
   digitalWrite(adCS,HIGH);
   SPI.begin();
}

void loop() {
   Serial.println("tick");
   digitalWrite(adCS,LOW);
   SPI.transfer(0xf0);
   digitalWrite(adCS,HIGH);
   delay(1000);
}
Upload and watch the serial monitor. When it prints "tick", it will set pin 10 LOW, then you should see the clock (pin 13) pulse 8 times, then pin 10 goes HIGH again for the rest of the second. Do you see that? Leave all SPI devices disconnected for this test also.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I ran the test and everything should be fine: pin10 switches between HIGH and LOW as it should and also the clock "should" be correctly present on pin13.

NOTE: I'm using "should" because at the moment I don't have the o-scope available and, in order to read the clock, I modified your test sketch as follows. As you will see, I made the clock last longer so that I could take a voltage measurement on pin13: the voltage that I measured is 2.5V, as it should be when the clock is pulsating. Also the mean voltage on pin11 (MOSI) reads 2.5V (that is the average of 0xF0.

Sorry the above is not (of course) a good way to carry out a measurement... I'm however confident that the result of your recommended test everything should be OK. (I also ran the same measurements while my original code is running and pin13 remains stuck at 5V: no clock present).


Code:
#include <SPI.h>
#define adCS 10


void setup() {
  Serial.begin(9600);
  pinMode(adCS, OUTPUT);
  digitalWrite(adCS,HIGH);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV128);
}

void loop() {
  Serial.println("tick");
  digitalWrite(adCS,LOW);
  for (unsigned long i=0; i<4000000; i++) SPI.transfer(0xf0);
  digitalWrite(adCS,HIGH);
  delay(2000);
  }

 
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5356
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Then it is working. I would check with the o-scope, but that is why I picked 0xf0 as the transfer value. Half on, half off.  smiley-wink

Now you just need to make the fine adjustments to the SPI,transfer() calls and connect it up. I'll bet when you send the right stuff the right way, it will start talking also.

edit: That appears to be SPI mode 3. The clock is HIGH with LOW pulses for clock, and data capture on the rising edge of the clock.
« Last Edit: October 16, 2012, 09:43:47 am by SurferTim » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you Tim, also to point out that in mode3 the signal is normally HIGH (with LOW pulses): this is what lead me to suspect that the pin was faulty. I repeated the same test above with mode3 and I correctly measured an average voltage of 2.5V when the clock was pulsating and 5V when the clock was off. Pins should be OK !

...still trying to trobleshoot what is wrong with my reading of the sensor.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5356
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The device datasheet says the max supply voltage is 3.6v. The max voltage applied to any input is 3.8v. You may be exceeding that. The microSD interface (also 3.3v) on the ethernet shield has logic converters on the microSD inputs.

Just a thought...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The voltage levels seem to be OK. As displayed in the attached schematic:

  • I'm translating the 5V voltages from Arduino to the sensor (clock, MOSI, /SS) with a voltage divider (I'm aware that the voltage divider might introduce some distorsion and delay in the waveform, but I figured that these should have no effect as long as I decrease the SPI clock speed (eg: 16MHz/128).
  • The 3.3V voltages coming from the sensor (MISO and an interrupt signal) are translated to 5V by an SN74LVC2T45 voltage translator.

Measuring all voltages however I observed the following strange behavior, that I'm not able to explain:

  • When the sensor and its interface board are powered on but are not connected to the Arduino, I read 0V at both the 3V3 MISO signal and at its 5V MISO traslation (pin7 and pin2 of the SN74LVC).
  • When, instead, the sensor and its interface board are connected to the Arduino, I still read 0V at 3V3 side of MISO but 5V at its 5V side (on pin2 fo the SN74LVC). In other words, it seems that Arduino's MISO line (digital pin 12) is generating a 5V (that cannot be, as the Arduino MISO pin is defined as an INPUT).
  • When the Arduino is powered on but disconnected from the sensor and its interface board, I correctly read 0V on Arduino MISO pin (D12).

The above would seem to be a grounding issue, but the 12V that I'm using to power Arduino and the 5V and 3V3 of the inteface board and sensor all share the same ground...

(Note: in the attached schematic, the ATMega168 pinout is reported for convenience; in reality, all connections are reported to the corresponding Arduino pins instead).


* Schematic.pdf (9.84 KB - downloaded 4 times.)
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5356
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this the device?
http://www.ti.com/lit/ds/symlink/sn74lvc2t45.pdf
How are you controlling pin 5? DIR
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, that's the voltage translator I'm using.

DIR is always connected to ground, so that the only translating direction that is always active is from B (3V3) to ----> A (5V). All signals received from the sensor (MISO and interrupt) are always translated to 5V.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5356
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would use that device the other way, like the microSD interface. I would translate 5v to 3.3v, but that is just me.
Logged

Pages: [1]   Go Up
Jump to: