Compiling an SD/MMC and fat16 library

Hi Nuno

I was embarrassed with it like you when i first saw it. but next moment I thought it could be the port number of Atmega168 chip

As you know, the Port B0 ~ PortB4 are pin no. 14~17. try it :slight_smile:

Strohhalm~ please give us the real answer ~

P.S.

And I thank you all guys above for all of your efforts. It'll be very helpful to my project

Thank you very much~

Hiya.

If a standard FAT library is too heavyweight for your application and you don't fancy raw card reading & writing here's a halfway-house solution that I've written:

I'm very happy to help with enhancements or explanations.

Charlie

I'm still trying to make it works...that circuit just seems to do...nothing.
I checked every wire thousand times but it doesn't work. :frowning:

Working with MMC/SD cards can be frustrating. I had a hard time making my first effort work.. :frowning:

Are you using an MMC or an SD card? Have you tried different cards? The schematic you're using is good, you can cross-reference your work with a different version which shows the wiring for an SD socket here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/1#0. The main difference is that this version powers the card from an Arduino's 3v3 supply whereas the version you based your circuit on is using diodes to drop the 5v to around 3v3. Other than that both card types can be addressed in the same way.

I've come in late to this conversation - what do you want to achieve? What code are you using?

Working with MMC/SD cards can be frustrating. I had a hard time making my first effort work.. :frowning:

Are you using an MMC or an SD card? Have you tried different cards? The schematic you're using is good, you can cross-reference your work with a different version which shows the wiring for an SD socket here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/1#0. The main difference is that this version powers the card from an Arduino's 3v3 supply whereas the version you based your circuit on is using diodes to drop the 5v to around 3v3. Other than that both card types can be addressed in the same way.

I've come in late to this conversation - what do you want to achieve? What code are you using?

I'm already using the schematic without the two diodes, but I tried that one too.
I really don't know how to find the problem...if it was a SW I could use a debugger, but here?
Anyway...I'm using a Kingston 64mb SD. The card works fine in my PC even after all the soldering I've done on the card itself (I can not find a socket...) so the problem is not there.
I checked the value of the resistors and thery are all fine...
Connected VCC on SD to 3v3 on Arduino, GND on SD to GND beside 3v3,
pin 1 on SD to 10 on Arduino
pin 2 on SD to 11 on Arduino
pin 3 is GND
pin 4 is VCC
pin 5 on SD to 13 on Arduino
pin 6 is GND
pin 7 on SD to 12 on Arduino (without any resistor because it's from SD to Arduino so it's already 3.3v)

Am I forgetting something? :cry:

I'm trying to build a simple 3-channel datalogger...the input part is easy but useless if I have no place to store the data I collect...

Here's one of the best introductions to the software side of mmc interfacing:

http://www.retroleum.co.uk/mmc_cards.html

Can you point me to the software that you use to initialise and read the card? I'll have a look over it.

Here's one of the best introductions to the software side of mmc interfacing:

http://www.retroleum.co.uk/mmc_cards.html

Can you point me to the software that you use to initialise and read the card? I'll have a look over it.

I'm using the same libraries used by AgentOrange in the post that you linked me.
Anyway the init part is the following

uint8_t sd_raw_init()
{
    /* enable inputs for reading card status */
    configure_pin_available();
    configure_pin_locked();

    /* enable outputs for MOSI, SCK, SS, input for MISO */
    configure_pin_mosi();
    configure_pin_sck();
    configure_pin_ss();
    configure_pin_miso();

    unselect_card();

    /* initialize SPI with lowest frequency; max. 400kHz during identification mode of card */
    SPCR = (0 << SPIE) | /* SPI Interrupt Enable */
           (1 << SPE)  | /* SPI Enable */
           (0 << DORD) | /* Data Order: MSB first */
           (1 << MSTR) | /* Master mode */
           (0 << CPOL) | /* Clock Polarity: SCK low when idle */
           (0 << CPHA) | /* Clock Phase: sample on rising SCK edge */
           (1 << SPR1) | /* Clock Frequency: f_OSC / 128 */
           (1 << SPR0);
    SPSR &= ~(1 << SPI2X); /* No doubled clock frequency */

    /* initialization procedure */
    
    if(!sd_raw_available())
        return 0;

    /* card needs 74 cycles minimum to start up */
    for(uint8_t i = 0; i < 10; ++i)
    {
        /* wait 8 clock cycles */
        sd_raw_rec_byte();
    }

    /* address card */
    select_card();

    /* reset card */
    uint8_t response;
    for(uint16_t i = 0; ; ++i)
    {
        response = sd_raw_send_command_r1(CMD_GO_IDLE_STATE, 0);
        if(response == (1 << R1_IDLE_STATE))
            break;

        if(i == 0x1ff)
        {
            unselect_card();
            return 0;
        }
    }
    
    /* wait for card to get ready */
    for(uint16_t i = 0; ; ++i)
    {
        response = sd_raw_send_command_r1(CMD_SEND_OP_COND, 0);
        if(!(response & (1 << R1_IDLE_STATE)))
            break;

        if(i == 0x7fff)
        {
            unselect_card();
            return 0;
        }
    }

    /* set block size to 512 bytes */
    if(sd_raw_send_command_r1(CMD_SET_BLOCKLEN, 512))
    {
        unselect_card();
        return 0;
    }

    /* deaddress card */
    unselect_card();

    /* switch to highest SPI frequency possible */
    SPCR &= ~((1 << SPR1) | (1 << SPR0)); /* Clock Frequency: f_OSC / 4 */
    SPSR |= (1 << SPI2X); /* Doubled Clock Frequency: f_OSC / 2 */

#if !SD_RAW_SAVE_RAM
    /* the first block is likely to be accessed first, so precache it here */
    raw_block_address = 0xffffffff;
#if SD_RAW_WRITE_BUFFERING
    raw_block_written = 1;
#endif
    if(!sd_raw_read(0, raw_block, sizeof(raw_block)))
        return 0;
#endif

    return 1;
}

It seems to be ok, does everything explained in your link. I'll try to debug the library to see where it stops.
What do you think about the code?

Thank you for you help

The code looks good, I'll run it against my hardware and let you know what happens.

This is a long shot but could you email me a digi picture of your card with its soldered connections? I've PM'd you my email address.

The code looks good, I'll run it against my hardware and let you know what happens.

This is a long shot but could you email me a digi picture of your card with its soldered connections? I've PM'd you my email address.

Yes, I'll send you a pic as soon as I can...I'm quite busy rigth now with 2 exams in 2 days :smiley:
Check your email in 6-7 hours.

thank you

Post up the code your using in your arduino sketch., that could help. If the card does nothing, then try making a simple sketch which just initializes the card and then prints out the sd card info. That should tell you if the card was initialized and is working or not.

Also, be aware that once you write to the card from the arduino you cannot read it in the pc again until you reformat it. Because you are writing straight onto the card which overwrites the FAT table.

If the card can be initialized and the disk info printed out then you "should" be able to read/write to it(murphy usually stuffs things up though (^_^)).

Post up the code your using in your arduino sketch., that could help. If the card does nothing, then try making a simple sketch which just initializes the card and then prints out the sd card info. That should tell you if the card was initialized and is working or not.

No, the SD is not working. After all this tring I desoldered it and read in the PC...like new, nothing was changed.
I had some bad wiring in my circuit (thank you SirMorris!), fixed it I couldn't still make anything with the SD.
I can't really tell where the problem is...I used 2 SDs, made the circuit 4-5 time, checked resistors tolerances...
I'm starting to think that something is wrong with my board :expressionless:

Where did you get your library code from? Did you use rolands code or the one I posted up in the exhibition area. If the card reads fine in your computer then there are two options, either the code isn't correct or the circuit isn't correct. If you claim that the circuit is correct (check your input voltages through the voltage divider with a multimeter) then it should be software based. Post up your arduino board version, software version, the code your using and any other info you have and I'll see if I can find the trouble. It should work no problem :smiley: But thats electronics for u!...

agent_orange,

I am starting to play with AVRs and recently I found about the Arduino system. I am very puzzled with your post a while ago:

Yeah I finally got it to all compile properly. I put the .c and .h files into a directory, renamed the .c to .cpp and it compiled automatically. I had to change a bit of the code as he uses the C99 standard and I don't know where to add flags when the arduino environment automatically compiles.

I probably will just use the low level read/write routines although the fat16 would be interesting. Just wanted to use robust sd/mmc access routines.

As I understand, your files have some differences with the original from the Roland site. Do you have a link to your files , you've mentioned your commented your changes? When you mention the libraries and the problem on changing the extension from C to C++, what compiler are you using ? Not clear for me when you said "Arduino environment automatically compiles" Are you referring to a dedicated Compiler IDE for Arduino which handles C and C++ ?? . Roland uses C Standard and your compiler uses C++ ?? The WinAvr does not have a library area I think you put all the files in one folder.

I may be making silly questions, I've started to play with an atmega168 using WinAvr about one month ago and just now I am finding out about Arduino.

I will appreciate your comments . I've checked the exhibition area and downloaded your files , not yet sure whether they are the same as per your post I've quoted at the beginning of this reply.

Thanks a million in advance,

Jose

I used Rolands code. He uses a slightly different C standard which throws exceptions if you don't enable a flag in the compiler. If you place code into the library directory it automatically gets compiled into a new library. However, it won't compile if the files end with .c, only if they end with .cpp. So I just renamed them to .cpp. Rolands code should compile straight out of the box, however he uses a few pins for sensing a card insertion. These need to be disabled or the card won't read or write properly with the arduino.

Hi there,

I have an arduino duemilanove with atmega 328 chip. I am not able to compile the SD-Card example, and get tons of errors. I guess the problem is in sd_raw.h as there is no definition of the atmega328 chip.

When I select another chip in the ide it does compile, of course I am then not able to upload....

Do you have a solution for this?

Thanks a lot, as I am really urgently in need to get the SD-Card working...

Thanks an best regards,
Marcel

Hey all
Recently i have been trying to setup an SD data logger based on the information give above by all of you. However when i copy and paste the code i recieve warnings where some of you have said this is good code and it works.
Here are the warnings I recieve when i am uploading:

from C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:2:

C:\Program Files\arduino-0017\hardware\libraries\SDcard/sd_raw_config.h:86:6: error: #error "no sd/mmc pin mapping available!"

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:13: error: 'byte' does not name a type

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:16: error: 'byte' does not name a type

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp: In function 'void setup()':

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:22: error: 'Serial' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:23: error: 'delay' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp: In function 'void loop()':

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:39: error: 'Serial' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:41: error: 'incomingByte' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp: In function 'int sample()':

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:61: error: 'byte' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:61: error: expected `;' before 'low'

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:62: error: expected `;' before 'high'

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:63: error: expected `;' before 'inByte'

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:65: error: 'Serial' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:72: error: 'inByte' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:75: error: 'analogRead' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:76: error: 'DEC' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:80: error: 'low' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:81: error: 'high' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:86: error: 'tempBytes' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:94: error: 'delay' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp: In function 'int readDisk()':

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:106: error: 'byte' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:106: error: expected `;' before 'low'

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:107: error: expected `;' before 'high'

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:108: error: expected `;' before 'info'

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:111: error: 'Serial' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:114: error: 'info' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:119: error: 'low' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:120: error: 'high' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:124: error: 'DEC' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp: In function 'void printWelcome()':

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:132: error: 'Serial' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp: In function 'int print_disk_info()':

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:153: error: 'Serial' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:155: error: 'HEX' was not declared in this scope

C:\Program Files\arduino-0017\hardware\libraries\SDcard\arduino sd card example.cpp:161: error: 'DEC' was not declared in this scope

I don't understand what i am suposed to do. Can someone please help me!!!! :cry:

http://www.google.com/search?client=safari&rls=en-us&q=%23error+"no+sd/mmc+pin+mapping+available!"&ie=UTF-8&oe=UTF-8

First hit. :slight_smile:

Thanks but after i click the link what do i look at???

the first hit