Pages: [1]   Go Down
Author Topic: "Large" files on SD cart  (Read 854 times)
0 Members and 1 Guest are viewing this topic.
Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is anyone else experiencing any problems with "large" (1KB+) files on SD card? I am working on my own LCD+SD shield (160x128 lcd from an epson printer) and I have a problem with reading image from sd card while sending it to lcd. I seem to only get ~400 bytes and then it just stops.
I've hooked everything to logic sniffer and I found out something interesting. Despite my code is designed to read each byte and send it to lcd what ardu actually does is read part of the file when "inFile=SD.open("1.lcd");" is called and does not communicate with SD card on "myFile.read();" calls.
How can I actually read something outside the area that was read on "open()"?
Code:
inFile = SD.open("1.lcd");
  
  digitalWrite(CS_LCD, 1);  
  writeLcd(startDraw);
  while(inFile.available()){
    digitalWrite(CS_LCD, 0);
    buffer = inFile.read();
    digitalWrite(CS_LCD, 1);
    SPI.begin();
    SPI.transfer(buffer);
    SPI.end();
  }


* output.jpg (170.63 KB, 1264x313 - viewed 17 times.)
« Last Edit: July 18, 2013, 11:21:31 am by Sulya » Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1604
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SD cards are block devices.  When you read the first byte, 512 bytes are read from the file into a block buffer. the next 511 bytes are read from the block buffer.

When you call SPI.end() the SPI controller is disabled.  The SD.h library does not expect this so it fails on the next block read.

Put the SPI.begin() in setup() and remove the SPI.end().

You could even omit the SPI.begin() since SD.begin() initializes the SPI bus.

« Last Edit: July 18, 2013, 11:40:38 am by fat16lib » Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that explains a lot. Meantime I've already tried using SdFat library instead (without removing SPI begin and end calls) and It worked, but a bit slower. Now when SPI begin and end calls are removed it works fine and a bit faster then with SdFat.
« Last Edit: July 18, 2013, 12:52:12 pm by Sulya » Logged

0
Offline Offline
Edison Member
*
Karma: 63
Posts: 1604
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've already tried using SdFat library instead (without removing SPI begin and end calls) and It worked, but a bit slower.
Yes, I modified SdFat to cope with SPI.end() calls.  SD.h is a wrapper for a very old version of SdFat that does not have that feature.

The call to SPI.begin() is very time consuming and is only required once.  It adds about 20 microseconds when you call it for every byte. 

SPI.end() only clears the enable bit in the SPI controller so it adds no time to re-enable the SPI controller since I write that controller register anyhow in SdFat.
Logged

Belgium
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for quick and complete answers and great libraries, my lcd + sd module is working now.
Logged

Pages: [1]   Go Up
Jump to: