Go Down

Topic: Compiling an SD/MMC and fat16 library (Read 5 times) previous topic - next topic

Nuno

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.  :(

sirmorris

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

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?


Nuno

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

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?  :'(

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...

sirmorris

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.


Nuno

Quote
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

Code: [Select]
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

Go Up