Go Down

### Topic: Can SPI overload my UNO if called too much? (Read 2442 times)previous topic - next topic

#### SouthernAtHeart

##### Apr 28, 2012, 06:03 pm
This test code makes my LCD freeze up:
Code: [Select]
`void loop() {  if (millis() - lcdTime > 2000) { //Has it been 2 seconds yet?    lcdTime = millis(); //update the timer    UpdateLCD(); // Change the LCD messege  }       ReadTimeDate(); //UPDATE THE TIME VARIABLES  return;`

If I move the ReadTimeDate() function inside the 2 second waiting period, it works fine, like this:
Code: [Select]
`void loop() {  if (millis() - lcdTime > 2000) { //Has it been 2 seconds yet?    lcdTime = millis(); //update the timer    UpdateLCD(); // Change the LCD messege    ReadTimeDate(); //UPDATE THE TIME VARIABLES  }     return;`

Code: [Select]
`void ReadTimeDate(){  String temp;  for(int i=0; i<=6;i++){    if(i==3)  i++;    digitalWrite(cs, LOW);    SPI.transfer(i+0x00);     unsigned int n = SPI.transfer(0x00);            digitalWrite(cs, HIGH);    int a=n & B00001111;        if(i==2){       int b=(n & B00110000)>>4; //24 hour mode      if(b==B00000010)  b=20;              else if(b==B00000001)  b=10;      TimeDate[i]=a+b;    }    else if(i==4){      int b=(n & B00110000)>>4;      TimeDate[i]=a+b*10;    }    else if(i==5){      int b=(n & B00010000)>>4;      TimeDate[i]=a+b*10;    }    else if(i==6){      int b=(n & B11110000)>>4;      TimeDate[i]=a+b*10;    }    else{       int b=(n & B01110000)>>4;      TimeDate[i]=a+b*10;     }  }   temp.concat(TimeDate[rtcMonth]);  temp.concat("/") ;  temp.concat(TimeDate[rtcDay]);  temp.concat("/") ;  temp.concat(TimeDate[rtcYear]);  temp.concat("     ") ;  temp.concat(TimeDate[rtcHour]);  temp.concat(":") ;  temp.concat(TimeDate[rtcMinute]);  if (debugMode) {    Serial.println(temp);  }}`

...did I fix the problem, or just make it where it won't happen as often.  I don't want to just mask a problem that will show up less frequently. Thanks.

#### SouthernAtHeart

#1
##### Apr 28, 2012, 06:06 pm
This code also makes things freeze, but it seems delay(100) should be plenty of time?
Code: [Select]
`void loop() {  if (millis() - lcdTime > 2000) { //Has it been 2 seconds yet?    lcdTime = millis(); //update the timer    UpdateLCD(); // Change the LCD messege  }       ReadTimeDate(); //UPDATE THE TIME VARIABLES    delay(100);   return;`

#### Grumpy_Mike

#2
##### Apr 28, 2012, 06:12 pm
Why are you putting a return at the end of your loop? And why is there no closing brace?

#### SouthernAtHeart

#3
##### Apr 28, 2012, 08:09 pm
I missed the closing bracket when I cut/paste.  The return was to remove all other events, trying to narrow the problem.
It seems that just touch the pins on the back of the UNO's chip (DIP version) cause resets, and sporadic stuff.  Is this normal?  My hands are clean, dry, I'm in an A/C environment...
This was my first attempt at using a chip/crystal/and smd caps. ...I think it'll be my last!  I like the pro-mini.
Here's a photo of my board.  Should it be this sensitive?
I didn't put of ground plane on either side after I finished my traces in Eagle, does that matter?

#### Grumpy_Mike

#4
##### Apr 28, 2012, 08:21 pm
Quote
It seems that just touch the pins on the back of the UNO's chip (DIP version) cause resets, and sporadic stuff.  Is this normal?

No, it implies that there is some floating inputs.
Can you post the schematic and ALL the code?

#5
schematic...

#### Grumpy_Mike

#6
##### Apr 28, 2012, 08:30 pm
Any chance of actually posting the schematic, not an Eagle file that won't load with my freeware version.

#### SouthernAtHeart

#7
##### Apr 28, 2012, 08:34 pm
sorry. Here it is.  And also the code.  It's broken out into different tabs so I had to zip it up.

#### SouthernAtHeart

#8
##### Apr 28, 2012, 08:37 pm
One change I made, the SMD caps for the crystal are 22pF, not .1 uF which I tried first!
I'm wondering if I need to go back to PTH caps and resisters, and forget SMD.

#### Grumpy_Mike

#9
##### Apr 28, 2012, 08:49 pm
Thanks for that. I was looking at the schematic and my wife said "what are you doing". I said that I was looking at a schematic from someone and it would not work. She said "there won't be enough decoupling then" and she was right.
Quote
forget SMD.

No SMD is the way to go. However, I noticed that on the schematic you have just one 0.1uF on the motor control IC and yet on the photo that seems to be on the LCD.
You need a cap on the processor's Aref and one on each chip. I would also put some more round the motor and +12V supply. Just solder them on between the pins on the board.
The power regulator can also do with some 0.1uFs as well as the bulk values you have.

#### SouthernAtHeart

#10
##### Apr 28, 2012, 08:54 pm
possibly having buttons (but I don't push them) on the RX an TX pins causes issues.  ...I do declare them as inputs and turn on the internal pull-ups
Anyway, I've about have it with bare chip IC and smd parts.  I'm going to start over with the pro mini, and maybe even throw in a serial LCD for good measure.
One question, though.  Is this SPI DS3234 RTC breakout from Sparkfun a real solid interface?  It connects via SPI, which is my first experience with such.  I use an I2C chip last time.  Is SPI real finicky?

EDIT.  Your's just came in.  So your wife is on top of these things!  Great.  Well, I'll take a break, a walk, and check it out some more before throwing in the towel...  I would like to do some SMD if I knew it was reliable.
Thanks,

#### spirilis

#11
##### Apr 28, 2012, 09:27 pm
For complete giggles, can you try something?

In rtc.ino ReadTimeDate function, comment out EVERYTHING involving the "String" class (the declaration and all the temp.concat lines) and just put some simple message in place...

Then try running it outside of the every-2-second condition and see if it helps.

#### SouthernAtHeart

#12
##### Apr 30, 2012, 06:08 am
Thanks GrumpyMike.  I decided to give it one more whirl, and I think I'll be able to salvage the board.  Here's what I did:  BatchPCB sent an extra board (which they always do, !:), so I put the bare minimal on to start.
Atmega328
crystal, 22 pf caps
0.1 uF between GND & Vcc
0.1 uF between Aref and GND

then the 10K resister to ground from the reset, and the 0.1 uF cap to DTR
Then scrubbed it with alcohol and toothbrush.

No other parts populated.  Then I hooked it up to my FTDI cable and loaded a sketch.  It worked.  I modded the Serial example of ascii table to keep running/sending the table over and over.

Now, when I finger the back of the board/pins lightly, it continues to work, but if I handle it pretty good, the serial stream bleeps and blips.  After some experimenting, I see it mainly happens when I touch the two pins of the crystal.  (they're all cut clean, short).  So I hook up my store bought UNO and load the same sketch on it, and I discover that if I handle it fairly forcefully on the pins, I can reproduce the same thing.  So I am assuming things are okay, and that this isn't going to flake out after a years' time. (it's a gift).  Does it sound trust worthy to you?
Thanks,

#### Grumpy_Mike

#13
##### Apr 30, 2012, 06:21 am
Quote
and I discover that if I handle it fairly forcefully on the pins, I can reproduce the same thing.

Yes touching a circuit adds a bit of capacitance and a high resistance to it. So as the crystal has only 22pF capacitors it is easily upset by say doubling this capacitance.
The "laying on of hands" is an old fault finding trick that often bemuses onlookers. However don't use it on high voltage circuits like a TV.

Quote
So I am assuming things are okay,

Yes it sounds like it.

#### SouthernAtHeart

#14
##### Apr 30, 2012, 06:24 am
Great!  I've done a few projects but never ran into this.  Likely, because I've always worked with the pro mini.  Thanks again.  I'll post the final product if anyone's interested.  It's version 2 of my chicken coop door, slimmed down to the size of a deck of cards, and still has an LCD.

Go Up