0
\$\begingroup\$

So we're trying to store bytes (from an A/D converter) of data into a SanDisk 1Gb microSD card from a LPC1769 microcontroller board using the on-board SPI protocol. I know how all that stuff works, but I have no idea how to start working with the microSD card - I've seen various references to CMD0 and what not, but I don't know where to find this library or how to properly incorporate it into the C compiler for the board.

All I need is to figure out how to start the connection properly and then how to read and write data into the card at designated blocks.

void write(int data, int block)
int read(int block)

Is there a library to do that? If not, how can I implement this?

\$\endgroup\$
  • \$\begingroup\$ If you know "how all that stuff works" you can probably write your own library by reading datasheets and the compiler's documentation. \$\endgroup\$ – Renan Nov 29 '12 at 0:22
5
\$\begingroup\$

From nxp.com: AN10916 - "FAT library EFSL and FatFs port on NXP LPC1700" should give you some pointers.

There is also AN11070 - "Accessing SDC/MMC card using SPI/SSP on LPC1700".

The specifications for SD(-HC, -XC) can be downloaded from sdcard.org.

how to properly incorporate it into the C compiler for the board

We don't know which compiler or board you use.

|improve this answer|||||
\$\endgroup\$
2
\$\begingroup\$

Well there are a couple of ways to get your microcontroller to talk to the SD card. The simplest is to use the SPI interface and use the card in SPI mode. Another mode you could use is called the SDIO mode, but that's quite complicated to implement. You can find the details of these modes and their corresponding protocols in the SD specifications. For an overview of the SPI mode look at: http://elm-chan.org/docs/mmc/mmc_e.html. So if you choose the SPI mode, the next thing is to implement a layer to intiialize and read/write blocks of memory. This is where you need to worry about CMD0 etc. Finally, just simply talking to an SD card is not enough, you will inevitably have to have a file system on the card, and to do that with your LPC you need to have a FAT (or other file system) library too.

I would recommend you try to port Chan's FatFS on to your chip, or find some other FAT implementation. FatFs comes with disk management routines for many MCUs including some LPC ones. And of course the FAT layer is MCU independent.

|improve this answer|||||
\$\endgroup\$
0
\$\begingroup\$

Check https://github.com/microbuilder/LPC1343CodeBase/ - it's a software stack for LPC1343, but is has a nice FAT / SD card library that is abstract enough, you shuld be able to copy and use it quite easily, all you have to do is to rewrite SPI calls.

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.