Pages: [1] 2   Go Down
 Author Topic: Can SPI overload my UNO if called too much?  (Read 761 times) 0 Members and 1 Guest are viewing this topic.
South East USA
Offline
God Member
Karma: 2
Posts: 571
 « on: April 28, 2012, 11:03:32 am » Bigger Smaller Reset

This test code makes my LCD freeze up:
Code:
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:
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;

Here is the ReadTimeDate() function:
Code:
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.
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #1 on: April 28, 2012, 11:06:56 am » Bigger Smaller Reset

This code also makes things freeze, but it seems delay(100) should be plenty of time?
Code:
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;
 Logged

Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
 « Reply #2 on: April 28, 2012, 11:12:26 am » Bigger Smaller Reset

Why are you putting a return at the end of your loop? And why is there no closing brace?
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #3 on: April 28, 2012, 01:09:14 pm » Bigger Smaller Reset

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?
 Logged

Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
 « Reply #4 on: April 28, 2012, 01:21:30 pm » Bigger Smaller Reset

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?
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #5 on: April 28, 2012, 01:27:45 pm » Bigger Smaller Reset

schematic...
 Logged

Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
 « Reply #6 on: April 28, 2012, 01:30:58 pm » Bigger Smaller Reset

Any chance of actually posting the schematic, not an Eagle file that won't load with my freeware version.
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #7 on: April 28, 2012, 01:34:48 pm » Bigger Smaller Reset

sorry. Here it is.  And also the code.  It's broken out into different tabs so I had to zip it up.
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #8 on: April 28, 2012, 01:37:16 pm » Bigger Smaller Reset

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.
 Logged

Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
 « Reply #9 on: April 28, 2012, 01:49:36 pm » Bigger Smaller Reset

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.
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #10 on: April 28, 2012, 01:54:59 pm » Bigger Smaller Reset

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,
 Logged

Maryland, USA
Offline
Full Member
Karma: 0
Posts: 162
 « Reply #11 on: April 28, 2012, 02:27:00 pm » Bigger Smaller Reset

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.
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #12 on: April 29, 2012, 11:08:29 pm » Bigger Smaller Reset

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,
 Logged

Manchester (England England)
Offline
Brattain Member
Karma: 299
Posts: 26031
Solder is electric glue
 « Reply #13 on: April 29, 2012, 11:21:31 pm » Bigger Smaller Reset

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.
 Logged

South East USA
Offline
God Member
Karma: 2
Posts: 571
 « Reply #14 on: April 29, 2012, 11:24:38 pm » Bigger Smaller Reset

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.
 Logged

 Pages: [1] 2   Go Up