SD card not reaching IDLE state


here's rough draft of code i'm working on store variables on sd card:

code: [select]
#include <sd.h>
#include <string.h>
#include <sdfile.cpp>

sd2card card;
sdvolume volume;
sdfile root;

/*
        encoding of "thejohnson" must utf8!!!!!     
*/


void setup() {
  serial.begin(9600);//baud = 9600 serial :)
  serial.print(f("total ram available: "));
  serial.println(freeram()); //this line can placed anywhere in code.
                             //if number printed less 5% of total, we're doomed

  //the following 2 lines necessary reason.
  pinmode(10,output);
  //digitalwrite(10,high);
  //i have 10,000 v actuator tied pin 10... i'm gonna have fix library somehow
  digitalwrite(a1,high);
  digitalwrite(a0,low);
 
  if (!card.init(spi_half_speed,a0)) //we're using pin a0 sd_ce, baby
    serial.println(f("failure initialize card."));
   
  if (!volume.init(&card)) //just making sure it's fat.
    serial.println(f("failure initialize volume."));
   
  serial.print(f("it's fat")); //in case wondering...
  serial.println(volume.fattype(),dec); //this fat type.
 
 
 
  //root.ls(ls_r); //built in arduino function printing folders/subdirectories
  serial.println(f("finished setup."));
}

//store indecies uint8_t.
//the goal trim "long"s 1 byte each in rom
//these "reference variables" our sd card stuff
//here's example var:
//int8_t dloca = 0; //10
//here's example file contents:
/*
,10,44,100000000,3,it's string!,somestuff,9,0,a,
*/
//in file, numbers accessible, strings return -1.




void loop() {
  float testvariable;
  if (!root.openroot(&volume)) //opening root
    serial.println(f("failure open root"));
  (uint8_t = 0; <= 8; i++)
  {
    serial.print("index ");
    serial.print(i);
    serial.print(": ");
    testvariable = getmyfloat(i);
    serial.println(testvariable);
  }
  while(true); 
}

//trying variables sd card...
//the first character in file delimiter, don't screw up.
//this function heavily dependent on careful handling of mainconf.zac,
//  hereafter known thejohnson
//the argument, "offset", number of delimiter characters pass before
//  reaching desired value (first character not included)
//the function return desired value, or -1 if there datatype error,
//  or else if there worse error
//right now, positive integers work.
long getmyfloat(uint8_t offset)
{
  sdfile thejohnson;
  int16_t delimiter;
  uint32_t startpos;
  uint8_t numdigits = 0;
  long thepower;
  long desiredvalue = 0;
  if (!thejohnson.open(root, "mainconf.zac", o_read))
    serial.println(f("failure open johnson"));
  else
  {
    thejohnson.rewind();
    delimiter = thejohnson.read();
    //serial.print(f("delimiter:")); serial.println((char)delimiter); //for debugging
    int16_t c = 0;
    (uint8_t n = 0; n < offset; n++)
      while (((c = thejohnson.read()) > -1 && (c != delimiter)));
    startpos = thejohnson.curposition();
    //we're @ first byte of thing want.
    //first need know how many digits has.
    while (((c = thejohnson.read()) > 0) && (c != delimiter))
    {
      ++numdigits;
    }
    thejohnson.rewind(); //going top of thejohnson
    thejohnson.seekset(startpos); //going previous spot on thejohnson
   
    //time try concatenate single-digit numbers:
    (uint8_t n = numdigits-1; n >= 0; n--)
    { //n goes 0 make powers easier calculate
      c = thejohnson.read();
      if ((c < 0) || (c == delimiter)) {
        serial.println(f("delimiter detected prematurely. make sure text encoding utf8"));
        return(-1);
      }
      if ( c >= 48 && c <= 57 )
      {
        c = c - 48;
      }
      else
      {
        serial.println(f("a bad character detected. values must positive integer."));
        return(-1);
      }
      thepower = 1;
      (uint8_t pow = n; pow > 0; pow--) //this calculate power
        thepower *= 10; //i did way wouldn't have include math.
      desiredvalue = desiredvalue + ((float)c * thepower);
    }
    return(desiredvalue);
  }
  return(-1);
 
}


it's pretty long.... sorry that. initialization on top, should be.

i've got pin 10 set output, , i've tried setting high. using pin a0 cs, , it's being driven low. have device on a1, being deselected code. sd card fat32 16kb allocation, , works on windows. i'm not using breakout. whole board custom , has little sd reader thingy on side; i'm using arduino ide , bootloader make programming atmega easier.

i get:
"failed initialize sd card."
followed multiple subsequent failures.
i put couple error flags in sd2card.cpp. sd card fails first check entering idle state. (library line ~245)

the code worked until hour ago, no errors, , doesn't work. i'm hoping didn't break something.

give me straight, doc. gonna live?

quote
my sd card fat32 16kb allocation, , works on windows.

but not on arduino. format card using format example provided sd library. won't fat32.


Arduino Forum > Using Arduino > Programming Questions > SD card not reaching IDLE state


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support