chipKIT® Development Platform

Inspired by Arduino™

SD Library can read only 32K of a file?

Created Sun, 27 Nov 2011 10:11:40 +0000 by amiarts


Sun, 27 Nov 2011 10:11:40 +0000


I already apologise for my bad English in advance.

I am just reading out pictures of a SC Card with the SD Library and displaying with the ITDB02 Library on a display. There are, unfortunately, still no Library (tinyfat) for the chip kit. Only the first 32K of the file are displayed, unfortunately and then the programme simply stops. I think that at all a variable is wrong dimmensioniert. Has this already tested One of You?

Greeting René from Germany


Wed, 30 Nov 2011 13:46:40 +0000

Can the not sometimes one have a look? This is, nevertheless, certainly a wrong dimensioned variable.

Thanks and greeting René


Wed, 30 Nov 2011 18:37:41 +0000

Signed vs. unsigned variable?

Alan KM6VV


Wed, 30 Nov 2011 20:09:48 +0000

Yes, then one could load at least 64 KB of the file. However, I think rather in interger to long. Unfortunately, I do not know a lot about C ++ thus.

I have not found signed variable.

Greeting René


Fri, 02 Dec 2011 00:27:24 +0000

I have found the cause in the file SdVolume.cpp in the following function. This is called after 32 KB and leads to the fall.

// Fetch a FAT entry
uint8_t SdVolume::fatGet(uint32_t cluster, uint32_t* value) const {
  if (cluster > (clusterCount_ + 1)) return false;
  uint32_t lba = fatStartBlock_;
  lba += fatType_ == 16 ? cluster >> 8 : cluster >> 7;
  if (lba != cacheBlockNumber_) {
    if (!cacheRawBlock(lba, CACHE_FOR_READ)) return false;

  if (fatType_ == 16) {
    *value = cacheBuffer_.fat16[cluster & 0XFF];
  } else {
    *value = cacheBuffer_.fat32[cluster & 0X7F] & FAT32MASK;

  return true;


In the line *value = cacheBuffer_.fat16[cluster & 0XFF]; the controller stops.

Unfortunately, I do not know a lot in such a way, but the error probably lie in cacheBuffer.

Greeting René


Wed, 07 Dec 2011 00:22:16 +0000

Does have really of no one idea?

I need to load urgently around a few pictures on a few TFT displays. I is to be built garade, besides, a digital speedometer for my car.


Wed, 07 Dec 2011 01:06:55 +0000

I am also interested in knowing whether this can be fixed soon.


Mon, 23 Jan 2012 22:47:41 +0000

It is a pity that here nothing more happens. There I will have to develop my speedometer project probably without Chipkit. Really a pity in the time which I have put there quite purely. Greeting René


Sun, 29 Jan 2012 12:24:20 +0000

Hi there, I can' t understand why the read noy function doesn' t work in my chipkit Max: I should read a 65 byte file called "setfile.txt" but all the code freeze at SD.begin(), I can' t understand why e CardInfo example works fine and the others don't. Am I missing something? This file is under 32K so it should work, do you use the SD library commands or others?

I don' t use any SD shield because I know the logic on of the pic32 is already 3v3 so no logic level converter is needed, or at least I think...I use a class4 lexar memory of 4GB, it' s a SDHC, that' s what CardInfo said. Could you please post some code to read a simple txt file? Thank you a lot, Pietro


Sun, 12 Feb 2012 22:18:36 +0000

Thanks Slayer,

with your Lib works now finally read beyond the 32k. Unfortunately, this is in connection with the extremely ITDB02 Lib by Henning Karlsen slowly. The raw image takes about 2 seconds to get back to the 320x200 pixel display.

Greetings René


Sun, 12 Feb 2012 22:33:57 +0000

I have found the error performance. It is very slow when you read prior to each () is still available (running). Now it's perfect! Thank you very much


Sun, 12 Feb 2012 23:44:22 +0000

Is it possible to accelerate the reading yet? The UN requires 153 600 bytes around 1600ms. Unfortunately, this is not exactly fast.


Tue, 27 Mar 2012 23:26:06 +0000

Hi Rene - you may already have read it, however there is a topic named SD card library on this forum, with many responses. Perhaps some of the suggestions in that topic may assist solve your question. I noticed that many people read your post yet so few replied. Perhaps you are more advanced in programming than many of us. Regards................Keith