Discussion in "8051 Discussion Forum" started by    Help    Dec 8, 2008.
Thu Feb 05 2009, 06:57 am
#81
Actually, I didn't realize your clock frequency was so low...Since the device is a 12 clock per instruction device, even a NOP will take1.085 usecs. That means you don't need an interrupt routine, you probably need to write just as fast as you possibly can to stay below the 10 usec limit...

Try rewriting your routine to just blast the data bits out as fast as possible, and then let's have a look at what you have...

-db
Thu Feb 05 2009, 07:09 am
#82
Dear Daves,

Ya, you are rite the device is a 12 clock per instruction device. Currently I ready have the WriteSector() and ReadSector() function, it's no using any interrupt function and I already tested in practical it's work OK. Now i able to read and write the data to SD card. Can we say the SPI routine work fine for SD card? But then, I'm not sure the SPI will work on FAT system not.

I ready have done all the basic function. What should i do for the next step?

Please advice,..

Thank you.l


[ Edited Thu Feb 05 2009, 10:40 am ]
Thu Feb 05 2009, 07:13 am
#83
I just realize your SD_Command() function passing the elements is difference with us.

Bellow is our code.
void MMCCommand(unsigned char command, unsigned int px, unsigned int py)
{
SPIPORT &= ~CS;
SpiByte(0xff);
SpiByte(command | 0x40);
SpiByte((unsigned char)((px >
>
 8)&0x0ff)); /* high byte of param y */
SpiByte((unsigned char)(px & 0x00ff));     /* low byte of param y */
SpiByte((unsigned char)((py >
>
 8)&0x0ff)); /* high byte of param x */
SpiByte((unsigned char)(py & 0x00ff));     /* low byte of param x */
SpiByte(0x95);            /* correct CRC for first command in SPI          */
                          /* after that CRC is ignored, so no problem with */
                          /* always sending 0x95                           */
SpiByte(0xff);
}


BYTE SD_Command        ( BYTE ThisCommand, ULONG ThisArgument );

May i know what Argument you passing to SD_Command() function?

Do we have to modifies the MMCCommand() function?

Thank you,.


[ Edited Thu Feb 05 2009, 11:00 am ]
Thu Feb 05 2009, 11:41 am
#84
Regarding SD_Command(...)

Refer to the product manual, section 5.2.1, as follows:




When you send a command to the SD card, the format must be 6 bytes long, and must consist of a command byte, 4 argument bytes, and an optional CRC (depending on which command you are sending).

Your function sends two 16-bit values for 4 bytes, and my function sends 1 32-bit value for 4 bytes. Both will work just fine.

If you compare your function to mine, you will see they both do essentially the same thing. Here is my function:

   typedef union
      {
      BYTE b[4];
      ULONG ul;
      } b_ul;

BYTE SD_Command( BYTE ThisCommand, ULONG ThisArgument )
   {
   b_ul Temp;
   BYTE i;

   /* enable the device... */
   SPI_EnableCS();
   
   /* send buffer clocks to insure no operations are pending... */
   SPI_Byte( 0xFF );

   /* send command */
   SPI_Byte(0x40 | ThisCommand);
   
   /* send argument */
   Temp.ul = ThisArgument;
   for( i=0; i<4; i++ )
      SPI_Byte( Temp.b[ i ] );

   /* send CRC if needed */
   SPI_Byte((ThisCommand == CMD_GO_IDLE_STATE)? 0x95:0xFF);
   //SPI_Byte( SD_CRC_7( Temp.b, 5 ) );

   /* send buffer clocks to insure card has finished all operations... */
   SPI_Byte( 0xFF );

   return( 0 );
   }


[ Edited Thu Feb 05 2009, 11:45 am ]
Tue Feb 10 2009, 10:48 am
#85
3) I'm using this sample scan_files().
static
FRESULT scan_files (char* path)
{
   while(){
      ....
      res = scan_files(path); // Q3
      ...
   }
   res;
}

May i know why the Q3 can be call again while current scan_files() function is still running? My compiler is show this routine is warning C265: '_scan_files': recursive call to non-reentrant function.

What can i do? please advice..
Thank you.
Tue Feb 10 2009, 10:53 am
#86
This is Chan's code:
void scan_files (char* path)
{
    FILINFO finfo;
    DIR dirs;
    int i;

    if (f_opendir(&dirs, path) == FR_OK) {
        i = strlen(path);
        while ((f_readdir(&dirs, &finfo) == FR_OK) && finfo.fname[0]) {
            if (finfo.fattrib & AM_DIR) {
                sprintf(&path[i], "/%s", &finfo.fname[0]);
                scan_files(path);
                path[i] = 0;
            } else {
                printf("%s/%s\n", path, &finfo.fname[0]);
            }
        }
    }
}


I have to go now, but will try and answer tomorrow...

-db
Tue Feb 10 2009, 10:54 am
#87
Please allow me to ask another question..
main(void)
{
   f_mount( 0, &SDCard );
   disk_initialize( g_card_type );
   scan_files( "" );
   f_mount(0, NULL);
   while(1);
}

Then how can i debug the result?
Tue Feb 10 2009, 04:46 pm
#88
Hello friends,

I am shiva. I am also working on the same project. I completed my project upto writing and reading 512 bytes to sd card. Now I want to create .txt files and dir in sd card. I have gone through chan's code but I cannot find where the function memset(memset(Buff, (BYTE)p1, sizeof(Buff));) is defined. Can some one help me to create .txt files.

regards
shiva
Tue Feb 10 2009, 05:25 pm
#89
Hi, shiva,

I think memset() function is the standard function for the compiler. Try to check for your compiler and add include the library in our program.

Gd Luck.
Tue Feb 10 2009, 05:48 pm
#90
One more question? Does this memset function sends data to sd card or stores the data in pic itself.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Richardgar
Sat Apr 20 2024, 11:05 am
AntoniaRoons
Fri Apr 19 2024, 09:59 pm
carpinteyrowrl
Fri Apr 19 2024, 02:51 pm
DonaldJAX
Fri Apr 19 2024, 01:08 pm
Lewisuhakeply
Thu Apr 18 2024, 06:00 pm
Darrellciz
Thu Apr 18 2024, 11:07 am
Charlessber
Thu Apr 18 2024, 09:29 am
BartonSem
Thu Apr 18 2024, 04:56 am