Go Down

Topic: [Resolved] Random Error Codes (Read 2264 times) previous topic - next topic

ahref

Nov 01, 2012, 03:04 am Last Edit: Nov 09, 2012, 12:48 am by ahref Reason: 1
Hi there,

I've got a basic GPS data logger going and im randomly getting random SDCard Error codes. I was unable to find documentation on what each of these mean but so far ive had:
01
02
03
04
06
08
F

All of these seem to point to me that my hardware is at fault perhaps a dodgy pin or sd card holder But I do not know.

Using a: https://www.sparkfun.com/products/9802
With: http://code.google.com/p/sdfatlib/

Although I also have the standard GPS Sheild kit installed Above the micro SD one.

Code is bellow:
Code: [Select]

#include <SoftwareSerial.h>
#include <TinyGPS.h>

#include <SdFat.h>

#include <PString.h>

#define RXPIN 2
#define TXPIN 3

//Defined in the specs for the module we are using
#define GPSBAUD 4800

#define error(s) sd.errorHalt_P(PSTR(s))

const uint8_t chipSelect = SS;

TinyGPS gps;
//Create the variables to be used by SdFat Library
SdFat sd;


SoftwareSerial uart_gps(RXPIN, TXPIN);

char buff[50];
char pbuff[100];
PString line(pbuff,sizeof pbuff);

void getgps(TinyGPS &gps);
ofstream sdout;


void setup()
{
 
 Serial.begin(115200);
 uart_gps.begin(GPSBAUD);
 Serial.println("...waiting for lock...");
 if (!sd.begin(chipSelect, SPI_FULL_SPEED)) sd.initErrorHalt();
}


void loop()
{
 while(uart_gps.available()) {     // While there is data on RX
   int c = uart_gps.read();    
   if(gps.encode(c)) {
     int year;
     byte month, day, hour, minute, second, hundredths;
     unsigned long age;
     gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths,&age); //Get the date from the GPS
     unsigned long date;
     gps.get_datetime(&date,0,0);
     if(date == TinyGPS::GPS_INVALID_DATE){
         Serial.println("Invalid Date");
         continue;
     }
     if(age == TinyGPS::GPS_INVALID_AGE) {
         Serial.println("Waiting for more valid data");
         continue;
     }
     //Should only occur once per day
     if(!sdout.is_open()) {
       sprintf(buff, "%02d/%02d/%02d/",year,month,day);
       if(!sd.exists(buff)){
         sd.mkdir(buff);
       }
       *buff = '\0';
       sprintf(buff, "%02d/%02d/%02d/%02d_%02d_%02d.csv",year,month,day,hour, minute, second);
       sdout.open(buff,ios::out | ios::app);
       Serial.println(buff);
       if(!sdout) error("Cannot Open File");
     }
     float latitude, longitude;
     gps.f_get_position(&latitude, &longitude);

     line.begin();
     line.print("201,");
     line.print(latitude,8);
     line.print(",");
     line.print(longitude,8);
     line.print(",");
     line.print(year);
     line.print("-");
     line.print(month);
     line.print("-");
     line.print(day);
     line.print(" ");
     line.print(hour);
     line.print(":");
     line.print(minute);
     line.print(":");
     line.print(second);
     line.print(",");
     line.print(gps.f_altitude(),2);
     line.print(",");
     line.print(gps.f_course(),2);
     line.print(",");
     line.print(gps.f_speed_kmph(),2);
     sdout << line << '\n' << flush;
     Serial.println(line);
     // Here you can print statistics on the sentences.
 //unsigned long chars;
 //unsigned short sentences, failed_checksum;
 //gps.stats(&chars, &sentences, &failed_checksum);
 //Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
 //Serial.println(); Serial.println();
   }
 }
}

Feel free to poke holes in it, Jumped in at the deep end here :D

I have no idea what is going on and my back is starting to ache from transferring the microsd card from the shield into the adapter on the front of my pc.

Please help :D!

P.S. Some sample Serial Monitor output here:
Code: [Select]

...waiting for lock...
Invalid Age
2012/11/01/01_55_59.csv
201,5x.x,-2.x,2012-11-1 1:55:59,100.00,0.00,0.00
(continues for about 10 lines)
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X2
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X4
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X4
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X2
...waiting for lock...
Invalid Age
Invalid Age
2012/11/01/01_56_31.csv
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
Invalid Age
Invalid Age
2012/11/01/01_56_50.csv
error: Cannot Open File
SD errorCode: 0XF


el_supremo

My guess is that you are running out of SRAM. Which Arduino are you using?

Pete

ahref

Uno V3, is there a way to check free SRAM? I can chuck that out on the serial.


ahref

#4
Nov 01, 2012, 06:06 am Last Edit: Nov 01, 2012, 04:32 pm by ahref Reason: 1
Just occurred to me, i forgot to mention im hitting reset on errors there. Which may of given the "out of memory" idea as i know it recalls setup when out of memory. I'll still check out memory issues but any other ideas?

So ive added a Serial.print of free memory just before the file open call 525 is what its sitting on:
Code: [Select]

...waiting for lock...
525
2012/11/01/15_25_53.csv
error: Cannot Open File
SD errorCode: 0X4


That occurs now or:
Code: [Select]

...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0XF


then sometimes it just works:
Code: [Select]

...waiting for lock...
Invalid Age
525
2012/11/01/15_28_12.csv
201,5x.x,-2.x,2012-11-1 15:28:12,86.10,142.86,0.83



I used:
Code: [Select]

int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

el_supremo

I'm not too familiar with SdFat but haven't you declared sdout improperly?
Shouldn't it be declared as:
Code: [Select]
SdFile sdout;

Pete

ahref

#6
Nov 01, 2012, 09:56 pm Last Edit: Nov 01, 2012, 11:54 pm by ahref Reason: 1
im using the ofstream class as it seemed the easiest i also like being able to  do stdout << "stuff". I don't think using ofstream would cause the issue however ill switch to one that uses SDFile and see if im getting the same issue.

So I switched to a SDFile setup and the same thing occured again im hitting reset when this fails:
Code: [Select]

...waiting for lock...
581
error: Cannot Open File
SD errorCode: 0X6
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X2
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X4
...waiting for lock...
581
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
Invalid Age
581
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
581
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
Invalid Age
581
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
581
error: Cannot Open File
SD errorCode: 0X6
...waiting for lock...
581
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
581
error: Cannot Open File
...waiting for lock...
581
error: Cannot Open File
...waiting for lock...
581
error: Cannot Open File
SD errorCode: 0X4
...waiting for lock...
Invalid Age
...waiting for lock...
581
error: Cannot Open File
SD errorCode: 0XF
...waiting for lock...
Invalid Age
581
error: Cannot Open File
...waiting for lock...
581
error: Cannot Open File
...waiting for lock...
Invalid Age
581
error: Cannot Open File
...waiting for lock...
Can't access SD card. Do not reformat.
SD errorCode: 0X4
...waiting for lock...


Ill run one of the SDFat exmaples through continually for awhile see if they work or not.

It ran quite well but after awhile stopped, inserting the sdcard into the computer and then reformatting has caused it to work again but im still getting intermitent 13s and 8s.

Could bad pins cause this. My soldering isnt bad but isn't great :)?

el_supremo

If a generic SDFat example fails then it does suggest that either there's a hardware (e.g. wiring/soldering) problem or the SD card itself is at fault.

Pete

fat16lib

The SparkFun microSD shields uses pin 8 for SD chip select.  Sometimes it will almost work with the wrong chip select pin.  This happens if pin 8 floats low.

Try changing this line
Code: [Select]

const uint8_t chipSelect = SS;

to this
Code: [Select]

const uint8_t chipSelect = 8;

ahref


The SparkFun microSD shields uses pin 8 for SD chip select.  Sometimes it will almost work with the wrong chip select pin.  This happens if pin 8 floats low.

Try changing this line
Code: [Select]

const uint8_t chipSelect = SS;

to this
Code: [Select]

const uint8_t chipSelect = 8;


Many thanks, This worked perfectly. I went back re-read the product description and associated files and yes it does quite clearly state that pin 8 must be used.

THANKS :D

Go Up