View previous topic :: View next topic |
Author |
Message |
gordonac14
Joined: 13 Jul 2010 Posts: 5
|
SD card to 30F PIC challenging prob (INTERESTING... KIND OF) |
Posted: Tue Jul 13, 2010 11:51 am |
|
|
Hi,
I have been having trouble getting my "write block" method to work in my code. "Read block" works fine, which eliminates a lot of possible errors with the write. "Read Block" simply prints out 512 bytes of data from the start address I send the function. Another thing is that I am able to write a command, and get a response....
After I send the start token, data block, then crc bytes, I get a response that corresponds to "Data Accepted".... However, when I stick the card into a reader, or call my "read block" method, I can see that it was not written. I am also unable to program any of the registers..... I have also tried a CMD13 during and after programming, which returns with no errors (CMD13 checks to see if any error bits have been set.
I have been able to read all of the registers, and found that all of the data within is as I wanted it to be..... Anyone have any ideas?
Thanks. |
|
|
gordonac14
Joined: 13 Jul 2010 Posts: 5
|
|
Posted: Tue Jul 13, 2010 12:15 pm |
|
|
please help |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jul 13, 2010 2:57 pm |
|
|
gordonac14 wrote: | please help | Wow!!! You waited a whole 24 minutes before crying help?
You don't give us enough information to help you.
Which SD library are you using?
What is your compiler version number?
What PIC?
What type, brand and size of SD card?
Have you tried another SD card?
How is the SD card connected? Can you post a circuit diagram?
etc. |
|
|
gordonac14
Joined: 13 Jul 2010 Posts: 5
|
|
Posted: Wed Jul 14, 2010 7:15 am |
|
|
I am just following the "Physical Layer Simplified Specification" (version 2.00).
www.sdcard.org/developers/.../Simplified_Physical_Layer_Spec.pdf
The card that I am using is a Transcend microsd card plugged in through an adapter and connected to a circuit I will provide. (1 GB) version 1.xx (based on CMD8 which I used). I tried a toshiba 1 GB, and a sandisk 2 GB, but neither would even initialize.
The PIC I am using is a dsPIC30F4013.
As for the circuit and code.... I am following the project from this website, but implementing a write method, since he does not provide one: http://www.k9spud.com/sdcard/. The source code and schematic are provided there. I have changed it slightly... I am using print statements through a serial port to check everything.... again, the read block method is working, as well as reading all of the registers... I will paste my write method below...
Thanks!
Code: |
unsigned char SD_WriteBlock(unsigned long addr){
unsigned int i;
unsigned int count = 0;
unsigned char status, buf[512];
unsigned char CMD24[] = {24,0x00,0x00,0x00,0x00,0xFF};
CMD24[1] = ((addr & 0xFF000000) >> 24);
CMD24[2] = ((addr & 0x00FF0000) >> 16);
CMD24[3] = ((addr & 0x0000FF00) >> 8);
CMD24[4] = ((addr & 0x000000FF));
for(i = 0; i < 512; ++i) buf[i] = 'b';
//SD_Enable();
SD_CS = 0;
//SPISlowClock();
//SPI1CON = 0x0060;
for(i = 0; i < 16; ++i) SPIWrite(0xFF);
// Send the read command
//status = SD_WriteCommand(CMD24);
//uprintf(2, "wc: ");
//uprintf(2, "%d\n", command);
// Set the framing bits correctly (never change)
CMD24[0] |= (1<<6); // 1000000
CMD24[0] &= ~(1<<7); //01111111
CMD24[5] |= (1<<0); //
// Send the 6 byte command
for(i = 0; i < 6; ++i) SPIWrite(CMD24[i]);
i = 0;
do{
status = SPIRead();
if(i > 60000) break;
i++;
} while(status == 0xFF);
if(status != 0) return 1;
SPIWrite(0xFE);
for(i = 0; i < 512; ++i){
//while(1){
//SPIWrite(buf[i]);
SPIWrite(0xAA);
}
SPIWrite(0xFF);
SPIWrite(0xFF);
i = 0;
do{
status = SPIRead();
if( (0x0F & status) == 0x05 ){
uprintf(2, "Data Accepted (");
uprintf(2, "%d)\n", i);
break;
}
++i;
}while(i < 500);
if(i == 500) uprintf(2, "DIDN't ACCEPT\n");
do{
status = SPIRead();
if(status == 0xFF) ++count;
else count = 0;
}while(count < 5);
SPIWrite(0xFF);
SD_CS = 1;
return 0;
}
|
|
|
|
gordonac14
Joined: 13 Jul 2010 Posts: 5
|
|
Posted: Wed Jul 14, 2010 11:13 am |
|
|
anyone? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Jul 14, 2010 3:48 pm |
|
|
gordonac14 wrote: | anyone? | Stop bumping this thread so soon!
Your question takes more time to look into than the average question on this forum. Also not everyone is living on the same continent as you are, this will add to the time delay.
After reading that you are posting at more forums and you not mentioning your compiler I've lost interest. |
|
|
|