using WIZ820_SD_ADAPTOR. getting file corruption

Status
Not open for further replies.

Gibbedy

Well-known member
Hello.
I'm using WIZ820_SD_ADAPTOR to write 2kb of text every 5 seconds..

Code:
File dataFile = SD.open("datalog.txt", FILE_WRITE);
      if (dataFile) // if the file is available, write to it:
      {
        dataFile.print(dataString);
        dataFile.close();
      }

I just did a test, and unplugged my teensy when I know my code is in between writes, however I'm getting the following files on my sdcard.
DAALO.TXT (this file has a character where the G should be but is not displayed here)
DADALOC.TXT
DATALOG.TXT

What should I do here?
Thanks.
 
Better to post entire sketch ;) .

Tried using another SD card? Do you use the new revision of the adaptor? If not, try adding pull-up resistors on pins 4, 9 and 10.
 
Better to post entire sketch ;) .

Tried using another SD card? Do you use the new revision of the adaptor? If not, try adding pull-up resistors on pins 4, 9 and 10.

On my third. I have one that used to work but now fails to initialize despite working on pc.
Using revision 2.

I will do some more testing and post the simplest code that fails.
 
Do you have a Wiznet module installed? I've had a lot of stability issues when using both SD and Ethernet.
 
Do you have a Wiznet module installed? I've had a lot of stability issues when using both SD and Ethernet.

No wiznet... but I do have a color touchscreen ILI9341 connected.

I'm in the process of trying to re-create the fault but proving difficult.
 
Try using it without the LCD and see if you keep getting the same problems. Alternatively, use the SDfat library in stead of the standard SD lib.
 
Try using it without the LCD and see if you keep getting the same problems. Alternatively, use the SDfat library in stead of the standard SD lib.

Just an update.. Working so far without screen but haven't done allot of testing yet.
My project will require 2 devices on spi (max7456 OSD and the sdcard writer).

I just enabled verbose output to see what libraries I'm using.
Is this correct for my teensy 3.2 with WIZ820_SD_ADAPTOR and DISPLAY_ILI9341_TOUCH :

Using library ILI9341_t3 at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\ILI9341_t3
Using library XPT2046_Touchscreen at version 1.1 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\XPT2046_Touchscreen
Using library SPI in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI (legacy)
Using library SD in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD (legacy)

Thanks.
 
I don't have the first two libraries, but the last two are the right ones yeah.
 
This is known to not be an issue of needing SPI Transactions for any SPI interafce where the ISR uses the SPI port, and there are other SPI drivers competing for the SPI peripheral on different chip selects, and "SPI Transactions" is not used by all drivers?
 
This is known to not be an issue of needing SPI Transactions for any SPI interafce where the ISR uses the SPI port, and there are other SPI drivers competing for the SPI peripheral on different chip selects, and "SPI Transactions" is not used by all drivers?

I think I know what your saying.

Using only WIZ820_SD_ADAPTOR and teensy3.2 hardware
And the SD example sketch everything seems to be working.

however if I attach my pjrc color touchscreen and use the ILI9341_t3 library at some point my program will stop and sdcard will fail to read when put into pc.

Do SD or ILI9341_t3 library's use ISR for SPI?
 
I'm testing sd card using the following code:
Code:
#include <SD.h>
#include <SPI.h>

const int chipSelect = 4; //cs for sd card


void setup()
{
    pinMode(8,OUTPUT);      //Touch
  digitalWrite(8,HIGH);
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);   //ILI9341
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);   // de-select the SD Card
  
 // Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop()
{
  Serial.println("looping");
  // make a string for assembling the data to log:
  String dataString = "";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ","; 
    }
  }

  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";   

  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; 

  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; 

  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; 

  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
  dataString+="1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; 
  
  
  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
  delay(10000);
}
I leave it run for a few hours. Then check sdcard:
Capture.JPG

Currently testing with another different brand of sdcard to see if I get same results.

Hardware wise I have 3X SPI hooked up. Sd card, lcd and touch.

Next step is to test with only teensy and sdcard.
 
Setting cs high and not using lcd/touch was not enough.
Absolutely no file corruption after removing combined lcd/touch spi hardware.

Thanks all.
 
Status
Not open for further replies.
Back
Top