Pages: [1]   Go Down
Author Topic: SPI slave select line glitch  (Read 780 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I noticed during SPI testing that there is a weird glitch in the SS line. Maybe it's my fault - would be glad to hear that.
Here's my code:
Code:
#include <SPI.h>

const int sspin = 10;
const int mosipin = 11;
byte val = 0x18;

void setup()
{
// Digital pins are: SS=10, MOSI=11, MISO=12, SCK=13
pinMode (sspin, OUTPUT); // must be guaranteed to be output
pinMode (mosipin, OUTPUT);
SPI.setClockDivider(SPI_CLOCK_DIV32); // => 500 KHz
SPI.setBitOrder(MSBFIRST); // endian
SPI.setDataMode(SPI_MODE0); // clock idles low
SPI.begin(); // => SCK and MOSI low, SS high
}


void loop()
{
digitalWrite(sspin, LOW); // enable slave
SPI.transfer(val);
digitalWrite(sspin, HIGH); // disable slave
}

And here's the trace - notice the quick bursts in the SS line
Can~t insert image - attached instead (however that works)


* clock trace_glitch.png (1.14 KB, 722x65 - viewed 17 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If we unravel the loop once we get this:

Code:
digitalWrite(sspin, LOW); // enable slave
SPI.transfer(val);
digitalWrite(sspin, HIGH); // disable slave   <--- "glitch" here
digitalWrite(sspin, LOW); // enable slave
SPI.transfer(val);
digitalWrite(sspin, HIGH); // disable slave

I would expect a brief high followed by mainly low. That's what you have written.
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 434
Posts: 23597
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, that just leads one to wonder why the wide pulse of SS High then? smiley Which I would submit is the commanded high followed by the code wrapping around back the start of the void loop.


The high glitch gives the appearance of occurring in the middle of this transfer
SPI.transfer(val);

Is the extra rising edge bothering anything in the circuit? Like prematurely moving data from the input register to the output register? If so, you may want to do something to take care of that.
Do you see that happen on other pins as well?
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, that just leads one to wonder why the wide pulse of SS High then? smiley Which I would submit is the commanded high followed by the code wrapping around back the start of the void loop.

Yes I was wondering about that too, but I assumed it was too large to be called a glitch.

I should point out too that the order of operations in the setup is a bit suspect. Check out what SPI.begin does:

Code:
void SPIClass::begin() {
  // Set direction register for SCK and MOSI pin.
  // MISO pin automatically overrides to INPUT.
  // When the SS pin is set as OUTPUT, it can be used as
  // a general purpose output port (it doesn't influence
  // SPI operations).

  pinMode(SCK, OUTPUT);
  pinMode(MOSI, OUTPUT);
  pinMode(SS, OUTPUT);
 
  digitalWrite(SCK, LOW);
  digitalWrite(MOSI, LOW);
  digitalWrite(SS, HIGH);

  // Warning: if the SS pin ever becomes a LOW INPUT then SPI
  // automatically switches to Slave, so the data direction of
  // the SS pin MUST be kept as OUTPUT.
  SPCR |= _BV(MSTR);
  SPCR |= _BV(SPE);
}

So the SPI.begin () overwrites some of the stuff you (maxmike) did before calling it. I can't really explain why SS becomes high during the transfer, except maybe the circuitry itself is responsible?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Looks like this may be a problem with the display instrumentation.
If I remove CLK from the display I don't see the glitches any more.
Thanks for the comments everybody. I will talk to the guys that
built the MSO19 I'm using.  smiley-mad
OTOH the MSO19 is attached to a 2.4 GHz dual processor Windows server and the fast
sample/display may be more than ol' Windows can handle on that machine.
Will try on an XP asap.
« Last Edit: February 20, 2011, 03:54:08 pm by maxmike » Logged

Pages: [1]   Go Up
Jump to: