Sd card interface

View: New views
16 Messages — Rating Filter:   Alert me  

Sd card interface

by threewheeler7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i have been searching around for good place to learn about the sd card SPI interface. i will be writing this in asm and i hope to even implement the use of the fat16 file system. so i may be able to read a file on the pic that was written on the pc and vise versa. i am having a hard time even finding the a good pic interface. any help would be appreciated.

Re: Sd card interface

by Marcel Birthelmer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I have this link bookmarked: http://www.captain.at/electronics/pic-mmc/
Basically, you'll want to use the MMC interface, but this is also
implemented by SD cards (at least for those <= 2GB, not sure about SDHC).
This is in C, but it might be good enough.
Regards,
- Marcel

On Mon, Jul 21, 2008 at 3:47 PM, threewheeler7 <threewheeler7@...>
wrote:

>
> i have been searching around for good place to learn about the sd card SPI
> interface. i will be writing this in asm and i hope to even implement the
> use of the fat16 file system. so i may be able to read a file on the pic
> that was written on the pc and vise versa. i am having a hard time even
> finding the a good pic interface. any help would be appreciated.
> --
> View this message in context:
> http://www.nabble.com/Sd-card-interface-tp18579174p18579174.html
> Sent from the PIC - [PIC] mailing list archive at Nabble.com.
>
> --
> http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: Sd card interface

by Zik Saleeba :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Microchip has a library which may be of use to you:

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en532040

AN1045 - Implementing File I/O Functions Using Microchip's Memory Disk Drive
File System Library

"This application note covers the usage of file I/O functions using
Microchip's memory disk drive file system library. Microchip's memory disk
drive file system is based on ISO/IEC 9293 specifications. It is also known
as the FAT16 file system, and used on earlier DOS operating systems by
Microsoft Corporation. The included source code also supports the FAT32 file
system. This is the most popular file system with SD cards, CF cards and USB
thumb drives. The applications note code is designed to run on 8-bit PIC18
devices and all 16-bit devices (PIC24F, PIC24H, dsPIC30F, dsPIC33F)."

Cheers,
Zik

On Tue, Jul 22, 2008 at 8:47 AM, threewheeler7 <threewheeler7@...>
wrote:

>
> i have been searching around for good place to learn about the sd card SPI
> interface. i will be writing this in asm and i hope to even implement the
> use of the fat16 file system. so i may be able to read a file on the pic
> that was written on the pc and vise versa. i am having a hard time even
> finding the a good pic interface. any help would be appreciated.
> --
> View this message in context:
> http://www.nabble.com/Sd-card-interface-tp18579174p18579174.html
> Sent from the PIC - [PIC] mailing list archive at Nabble.com.
>
> --
> http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: Sd card interface

by Harold Hallikainen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've used this library, and it works! It's pretty easy to configure (just
select SPI port and slave select).

Harold


> Microchip has a library which may be of use to you:
>
> http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en532040
>
> AN1045 - Implementing File I/O Functions Using Microchip's Memory Disk
> Drive
> File System Library
>
> "This application note covers the usage of file I/O functions using
> Microchip's memory disk drive file system library. Microchip's memory disk
> drive file system is based on ISO/IEC 9293 specifications. It is also
> known
> as the FAT16 file system, and used on earlier DOS operating systems by
> Microsoft Corporation. The included source code also supports the FAT32
> file
> system. This is the most popular file system with SD cards, CF cards and
> USB
> thumb drives. The applications note code is designed to run on 8-bit PIC18
> devices and all 16-bit devices (PIC24F, PIC24H, dsPIC30F, dsPIC33F)."
>
> Cheers,
> Zik
>
> On Tue, Jul 22, 2008 at 8:47 AM, threewheeler7 <threewheeler7@...>
> wrote:
>
>>
>> i have been searching around for good place to learn about the sd card
>> SPI
>> interface. i will be writing this in asm and i hope to even implement
>> the
>> use of the fat16 file system. so i may be able to read a file on the pic
>> that was written on the pc and vise versa. i am having a hard time even
>> finding the a good pic interface. any help would be appreciated.
>> --
>> View this message in context:
>> http://www.nabble.com/Sd-card-interface-tp18579174p18579174.html
>> Sent from the PIC - [PIC] mailing list archive at Nabble.com.
>>
>> --
>> http://www.piclist.com PIC/SX FAQ & list archive
>> View/change your membership options at
>> http://mailman.mit.edu/mailman/listinfo/piclist
>>
> --
> http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
>


--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: Sd card interface

by threewheeler7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i do beleve that the mmc interface is the SPI interface, am i correct?
Marcel Birthelmer wrote:
Hi,
I have this link bookmarked: http://www.captain.at/electronics/pic-mmc/
Basically, you'll want to use the MMC interface, but this is also
implemented by SD cards (at least for those <= 2GB, not sure about SDHC).
This is in C, but it might be good enough.
Regards,
- Marcel

Re: Sd card interface

by Bob Blick-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 21 Jul 2008 15:47:52 -0700 (PDT), "threewheeler7"
<threewheeler7@...> said:
>
> i have been searching around for good place to learn about the sd card
> SPI
> interface. i will be writing this in asm and i hope to even implement the
> use of the fat16 file system. so i may be able to read a file on the pic
> that was written on the pc and vise versa. i am having a hard time even
> finding the a good pic interface. any help would be appreciated.

One trick made popular by a piclister avoids the filesystem firmware
requirement by creating one big blank file on the card(using a PC) and
then treating it like your own private play area. That way the PIC
doesn't have to deal with the FAT file system at all. Just use your own
delimiters within the file itself.

Cheerful regards,

Bob

--
http://www.fastmail.fm - Access all of your messages and folders
                          wherever you are

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: Sd card interface

by John Coppens :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 21 Jul 2008 16:35:55 -0700 (PDT)
threewheeler7 <threewheeler7@...> wrote:

>
> i do beleve that the mmc interface is the SPI interface, am i correct?

Yes... And just to point out the largest stumbling block: all of the
filesystems use 512-byte 'sectors'. So you need a PIC with at least 512
bytes of memory to store one complete sector (which is why all the
references point to the larger PICs).

The only exception, is that you could only partially write each sector,
and then use some program in the PC to put it all together.

As far as I know, that limit is part of the SD norm, and not changeable.

John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

RES: Sd card interface

by Alexandre GuimarĂ£es :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi, Bob.

        Could you give some more details ? I do not remember seeing it
around at the list :-( Google also did not help a lot. I have no immediate
application for it but it is a good thing to put on the "bag of tricks" for
using someday.

>One trick made popular by a piclister avoids the filesystem firmware
requirement by creating one big blank file on the card(using a PC) >and then
treating it like your own private play area. That way the PIC doesn't have
to deal with the FAT file system at all. Just use
>your own delimiters within the file itself.

Best Regards,
Alexandre Guimaraes






--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: RES: Sd card interface

by Bob Blick-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here:

http://repatch.dyndns.org:8383/pic_stuff/carmon/index.html

Cheerful regards,

Bob

Alexandre Guimara~es wrote:

> Hi, Bob.
>
> Could you give some more details ? I do not remember seeing it
> around at the list :-( Google also did not help a lot. I have no immediate
> application for it but it is a good thing to put on the "bag of tricks" for
> using someday.
>
>> One trick made popular by a piclister avoids the filesystem firmware
> requirement by creating one big blank file on the card(using a PC) >and then
> treating it like your own private play area. That way the PIC doesn't have
> to deal with the FAT file system at all. Just use
>> your own delimiters within the file itself.
>
> Best Regards,
> Alexandre Guimaraes
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: RES: Sd card interface

by Marcel Duchamp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think several people mentioned doing this; one of them was me.  At
this point, I would jump into implementing a FAT16 or FAT32 system.  But
when I worked on this in the past, this method worked well enough.

I only wanted to build a datalogger that would record an incoming RS232
data line.  To avoid the FAT issues, I created a .txt file that used all
available space and had a marker string at every 512 byte sector boundary.

I used various hex file utilities found on the net to investigate the
card structure and learn how data is stored.  Then my code jumps to
about the half way point in a given card and reads a sector.  If the
string is found, then I'm too far so I did a divide and conquer method
of searching back towards the bottom of the card to get to the last
sector not yet written to.

Upload the card in a PC and read the txt file out.  My code had a few
"quick and dirty" choices made to get it done that are a bit limiting so
  it should be completely redone.  Some day.  When I have time.  Before
the end of the universe.

Alexandre GuimarĂ£es wrote:

> Hi, Bob.
>
> Could you give some more details ? I do not remember seeing it
> around at the list :-( Google also did not help a lot. I have no immediate
> application for it but it is a good thing to put on the "bag of tricks" for
> using someday.
>
>> One trick made popular by a piclister avoids the filesystem firmware
> requirement by creating one big blank file on the card(using a PC) >and then
> treating it like your own private play area. That way the PIC doesn't have
> to deal with the FAT file system at all. Just use
>> your own delimiters within the file itself.
>
> Best Regards,
> Alexandre Guimaraes
>
>
>
>
>
>

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: RES: Sd card interface

by Harold Hallikainen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Similar to the "one big text file" approach, I made an SD/MMC card
bootloader. I store the code to be bootloaded as a hex text file on a
freshly formatted card. I edit the hex file to add a distinct string at
the start. Then, my code just reads sector by sector until it finds the
unique string. Then, it reads in a byte at a time passing it to the
bootloader. To make sure it will work, the code actually first goes
through the hex file checking the checksum on each line. If it all looked
ok, it goes back and loads the file. So, there's a way of reading a single
file from a freshly formatted MMC/SD.

Harold

--
FCC Rules Updated Daily at http://www.hallikainen.com - Advertising
opportunities available!
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: Sd card interface

by threewheeler7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



John Coppens wrote:
filesystems use 512-byte 'sectors'. So you need a PIC with at least 512
bytes of memory to store one complete sector (which is why all the
references point to the larger PICs).
if i need to write smaller files cant i just write it and tell the pic to add appropriate zeros to finish off the sector?

Re: Sd card interface

by threewheeler7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Bob Blick-4 wrote:
One trick made popular by a piclister avoids the filesystem firmware
requirement by creating one big blank file on the card(using a PC) and
then treating it like your own private play area. That way the PIC
doesn't have to deal with the FAT file system at all. Just use your own
delimiters within the file itself.
Yes Bob i actually thought of doing something like that, but i would like to be able to read a file made by a pc a little easier rather than having to put a specific text string in the file for the pic to look for.

Re: RES: Sd card interface

by threewheeler7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Harold Hallikainen-2 wrote:
Similar to the "one big text file" approach, I made an SD/MMC card
bootloader. I store the code to be bootloaded as a hex text file on a
freshly formatted card. I edit the hex file to add a distinct string at
the start. Then, my code just reads sector by sector until it finds the
unique string. Then, it reads in a byte at a time passing it to the
bootloader. To make sure it will work, the code actually first goes
through the hex file checking the checksum on each line. If it all looked
ok, it goes back and loads the file. So, there's a way of reading a single
file from a freshly formatted MMC/SD.
you know i thought of building an sd bootloader a wile back, how did it turn out? you have a page with any details?

Re: Sd card interface

by John Coppens :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 21 Jul 2008 21:05:05 -0700 (PDT)
threewheeler7 <threewheeler7@...> wrote:

> if i need to write smaller files cant i just write it and tell the pic
> to add appropriate zeros to finish off the sector?

Yes... Eg. you could only write 128 'data' bytes, and fill the rest with
anything. On the PC you'd have to read only the first 128 bytes.

But if  you want to write several files, you'd have to manage the
directory too, which complicates the software a lot. Easier to pre-write
a large file, then fill it with partial sector. Sort of making your
mini-filesystem inside a large file.

John
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

Re: Sd card interface

by Herbert Graf-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, 2008-07-21 at 21:03 -0300, John Coppens wrote:

> On Mon, 21 Jul 2008 16:35:55 -0700 (PDT)
> threewheeler7 <threewheeler7@...> wrote:
>
> >
> > i do beleve that the mmc interface is the SPI interface, am i correct?
>
> Yes... And just to point out the largest stumbling block: all of the
> filesystems use 512-byte 'sectors'. So you need a PIC with at least 512
> bytes of memory to store one complete sector (which is why all the
> references point to the larger PICs).
>
> The only exception, is that you could only partially write each sector,
> and then use some program in the PC to put it all together.
>
> As far as I know, that limit is part of the SD norm, and not changeable.

You are correct, however you don't necessarily need a PIC with 512bytes
of RAM to get things going.

For my carmon project http://repatch.dyndns.org:8383/pic_stuff/carmon I
used a 32kB I2C EEPROM for sector storage on a 877. Works to this day
perfectly.

TTYL

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist