CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

32MB SD card is working fine, 128MB card is not.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

32MB SD card is working fine, 128MB card is not.
PostPosted: Sat May 15, 2004 10:20 pm     Reply with quote

Initialing a 32MB SD card works fine. I am also able to read and write the card with FAT16 files.

Using the same code to initialize a 128MB card goes OK until it comes time to read it. Then it returns 00 for each read.

128MB card works fine on iPaq.

32MB card is formated FAT16 with 512byte sector and 1 sector per cluster.

128MB card is formated FAT16 with 512bytes sector and 4 sectors per cluster.

The SD data sheet from Sandisk it states Write BLOCK size (spi mode) is fixed at 512 bytes and must be on sector boundaries.
"The information about allowed block sizes and the programmability is stored in the CSD."

Here's the problem. I can't read the darn thing to get at the CSD to find out what block limitations are for the 128MB card.

Then again the data sheet implies there is no limitation on block size for the read command, as there is with the write command. So reading 32 bytes should be as easy as reading 128 byte. !

Has anyone else had problem reading 128MB SD cards ?

Best regards
Hans W
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sun May 16, 2004 6:10 am     Reply with quote

I've seen variations between card manufacturers and card sizes....I've only used 16 MB and 32 MB both formatted with FAT16.You can sometimes get 16mb cards for $7 which makes for an economical flash memory add on to a pic project .There is a variation in the number times you have to poll the card to get it into SPI mode and in the number of times to poll to get the controller to permission read and write commands when in SPI mode.
Also the internal controller on the card can have busy work to do such as when a block fails and it has to re organize the memory space to keep the outside world appearance of contiguous memory blocks. Try lengthening the polling loops. As you say the sector and cluster size is a FAT issue the cards world is 512 byte blocks...the restriction that the block divides into the sector size is done for the windows drivers so they don't have to write code to span SD card blocks when writing or reading a sector. It simplifies the code both for them and for the PIC driver code as well.
Now FAT16 means 65536 addresses. Now 65536 x 512 sector gives 32MB so 512 is the sector size choice for under 32mb. With a sector size of 2048 you have 128MB. The small downside is the sector size sets the size of the smallest file chunk. So with 2048 even a 1 byte file will take up 2048 bytes on the other hand you get the full 128MB you were looking for in an earlier post via partioning.
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Update:
PostPosted: Mon May 17, 2004 1:01 pm     Reply with quote

I have some progress, it is now possible to read the CSD and CID registers, the data does not indicate that I need to change any timing.

Comparing signals for the 32MB and 128MB cards using my logic analyzer, I have reached the conclusion that there is something else preventing me from reading the 128MB card.

Sandisk are not very interested, and they referred me to the SD memory Org. Where I found they wanted $1100 for a set of up to date data sheets...

Just think if Microchip wanted $1100 for PIC data sheets.... ! I think the SD memory org. people are ging around with their head stuck up where the sun does not shine !

So. until I get time my experience with SD cards will be limited to 32MB cards only.
When I get time I'll hook the LA to my Memorx SD card reader and "have a look" at the timing when WinHex read the card it works fine. Perhaps that can shed some light on the subject.

If anyone has a more up to date data sheet for SD memory cards I'd appreciate a link... I have SD Spec. version 1.7

Any other suggestions about reading 128MB cards are welcome.

Hans W
scarr



Joined: 15 Nov 2003
Posts: 4

View user's profile Send private message

Are you making this a general purpose project?
PostPosted: Wed May 19, 2004 5:39 pm     Reply with quote

Hi,

I have been looking for CF routines for soem time, ideally using a slave PIC to interface to the CF and I2C / SPI to send read/write commands is this what you are working on?

thanks
Guest








Re: Are you making this a general purpose project?
PostPosted: Thu May 20, 2004 7:11 am     Reply with quote

If you search the web, you will find plenty of code to CF cards.
I'm trying to use the SD card, whihc has a different interface, in fact it has three ways to communicate with it. SD SPI and Single Wire.

I'm waiting for some other memory cards to arrive (ebay purchase) and that may tell me the two 128MB cards I have are defective on the SPI interface, or it may be not.... :-) in which case I'll have to figure out something else.

BTW there is NO hope of getting any tech support from SanDisk. I put in a call to engineering support and they replied yesterday telling me I had to become a member to the SD org. (at about $10,000 a year) before they could talk about my issue ! There are wondeful benfits to joinign the SD org. like the right to buy the Data sheets for $1100 !

Anyway, it may all end up with this project moving over to CF cards.
Best regards

Hans W
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 20, 2004 10:40 am     Reply with quote

Hi Hans,

How are you accessing the SD-cards? SPI, SD-mode (4-wire) or MMC-mode (2 wire)?

As I understood from the datasheets you can only write a complete block, not part of a block. Current MMC/SD cards have block sizes of 512 bytes, but this can change in the future so you will have to check the info-structure on the card.
By specifying SET_BLOCKLEN(cmd16) you can read in units as small as a single byte. The start address and block length must be set so that the data transferred will not cross a physical block boundary.

I'm currently implementing the routines for accessing an MMC-card using the SPI-bus, future versions will also have to handle SD-cards.

Right now I can initialize the MMC card (SD-card support is implemented too, but I don't have an SD-card available for testing yet).

Tomorrow I will start programming the routines for writing and reading data. I'm not going to use FAT16/32 because it requires a lot of code (10kb+) and is not good in handling lots of small files. I have to create a data-logger kind of device which logs a record every minute for at least a month (43000 records a month). Something like a huge circular buffer will suit my project.

I'm willing to share my code.

Carlo
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

PostPosted: Sat May 22, 2004 3:53 pm     Reply with quote

ckielstra wrote:
Hi Hans,

How are you accessing the SD-cards? SPI, SD-mode (4-wire) or MMC-mode (2 wire)?

As I understood from the datasheets you can only write a complete block, not part of a block. Current MMC/SD cards have block sizes of 512 bytes, but this can change in the future so you will have to check the info-structure on the card.
By specifying SET_BLOCKLEN(cmd16) you can read in units as small as a single byte. The start address and block length must be set so that the data transferred will not cross a physical block boundary.


I'm currently implementing the routines for accessing an MMC-card using the SPI-bus, future versions will also have to handle SD-cards.

Right now I can initialize the MMC card (SD-card support is implemented too, but I don't have an SD-card available for testing yet).

Tomorrow I will start programming the routines for writing and reading data. I'm not going to use FAT16/32 because it requires a lot of code (10kb+) and is not good in handling lots of small files. I have to create a data-logger kind of device which logs a record every minute for at least a month (43000 records a month). Something like a huge circular buffer will suit my project.

I'm willing to share my code.

Carlo


I'm using SPI and it works fine with 32MB SD cards but not wioth 128MB.

Yes in understand the 512 byte block write limitation, that's not a problem. All SD card can be set to READ anything from 1 byte to 512 bytes.

That is the problem. I try to read the first 32 bytes from address Zero and the code read OK on 32MB cards but not one 128MB.

Today I received a 64MB card and it is brand new, the good code that read 32MB ok still cannot read the 64MB cards.
I do not want to go back to MMC cards because SD ARE MMC compatible, and can be read as a regular MMC card.

There has to be another reason why cards over 32MB cannot be read with good code that readas AND writes 32MB cards OK....

At the moment I can't share code, because the code I have was given to me and I do not have the right to pass it on.
When / IF I ever get to read larger MB cards, I think the original code auther will release the code, but I can't promise that.

Anyway, you should be OK reading and writing as linear memory upto 32MB or are you using larger cards ?
You will have a problem reading the data with a PC and card reader ! or how do you plan to access the data on your MMC cards ?

Best regards
Hans W
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun May 23, 2004 9:22 am     Reply with quote

Quote:
I do not want to go back to MMC cards because SD ARE MMC compatible, and can be read as a regular MMC card.


SD cards are hardware backwards compatible, but there are some differences in the commands. I haven't figured out all the details yet as I'll be concentrating on the 64MB MMC cards first. One important difference is the init-command, CMD0 for MMC and CMD51 (or so) for SD cards. Maybe your 32MB SDcard accepts CMD0 where the others don't?
Guest








PostPosted: Sun May 23, 2004 9:35 pm     Reply with quote

ckielstra wrote:
Maybe your 32MB SDcard accepts CMD0 where the others don't?


At this stage anything is possible.
I have the SD data sheet version 1.7.
Wish I could get my hands on more inforation about the SPI interface, or at least find out if what I have (rev.1.7) is the final document.

If I could find a commerical SD card reader that uses SPI, I could hook my Logic Ana. to it and figure it out that way.
I made an adapter for the SD card to get access to the pins while it is pluged into the reader, with that I figured out my reader uses the SD interface. I suspect most commercial reader will use the SD interface, because it's faster.

At $1100 for the data sheet it will be a while before I figure this out Very Happy
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon May 24, 2004 3:07 am     Reply with quote

From the internet I downloaded a pdf document with examples of SPI timings for MMC. It is small, only 19kb, two pages with no explaining text, but it helped me a lot!!
I just checked Google with the terms "spi timing" and "mmc" and found the document again on:
http://kilm.by.ru/im/flash/index.shtml
NikkC
Guest







PostPosted: Mon May 24, 2004 3:27 am     Reply with quote

Progressive Resources LLC sell source code for AVR mcus for reading and writing SD/MMC and CompactFlash.

It could provide you with the necessary information.

http://www.prllc.com/prllc_homemainFlash.htm

Nikki
Guest








PostPosted: Mon May 24, 2004 3:00 pm     Reply with quote

ckielstra wrote:
From the internet I downloaded a pdf document with examples of SPI timings for MMC. It is small, only 19kb, two pages with no explaining text, but it helped me a lot!!
I just checked Google with the terms "spi timing" and "mmc" and found the document again on:
http://kilm.by.ru/im/flash/index.shtml


I downloaded it and it looks OK, and confirms my timing is correct.
What's wrong I have no idea at the moment.
32MB cards are perfect, no problem, which I expected as the timing is correct. Confirmed using my Logic Analyzer.

However 64MB and 128MB cannot read data.

With the 64MB and 128MB cards, the code can only read the two CID and CSD, and the data read makes sense when compared to the data sheets.
Guest








PostPosted: Mon May 24, 2004 3:05 pm     Reply with quote

NikkC wrote:
Progressive Resources LLC sell source code for AVR mcus for reading and writing SD/MMC and CompactFlash.

It could provide you with the necessary information.

http://www.prllc.com/prllc_homemainFlash.htm

Nikki


Thanks for the link. I'll only resort to buying it if I can;t find a solution. At the moment 32MB cards works fine.
There is also another library:
look for SDMXSRC SD/MMC FAT16 source code

http://www.compsys1.com/workbench/BenchOrders/bench_orders.html#sdmmc

price is $23.- ! I have no idea how good it is.

Progressive Resources LLC stuff looks good, but does need work to port it over to PIC.
MGP



Joined: 11 Sep 2003
Posts: 57

View user's profile Send private message

PostPosted: Mon May 24, 2004 4:25 pm     Reply with quote

Hans,

That $23 MMC FAT16 software is written in PicBasic Pro. I looked at it several months ago and besides being written in PBP, it's also a limited implementation of FAT16.

I'm actually considering buying the Progressive Resources LLC FAT16 library. I downloaded the manual for it and it looks very complete and professional. $139 isn't too bad either, even considering the porting that will have to happen for a PIC (and CCS in particular).
Guest








PostPosted: Mon May 24, 2004 6:43 pm     Reply with quote

MGP wrote:
Hans,

That $23 MMC FAT16 software is written in PicBasic Pro. I looked at it several months ago and besides being written in PBP, it's also a limited implementation of FAT16.

I'm actually considering buying the Progressive Resources LLC FAT16 library. I downloaded the manual for it and it looks very complete and professional. $139 isn't too bad either, even considering the porting that will have to happen for a PIC (and CCS in particular).


Thanks for the heads up.... I don't want to port from basic.
I agree $139 is a good price. But as I'm so close (32MB cards OK) and I can hold off for a while as I have BlueTooth going at the moment. I'll give it some more time and perhaps locate the reason for the problem, which I still think is me doing something wrong ! but i'ts hard to see my own mistakes when the 32MB cards are identical, and nothing in the data shees say anything else. !
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group