CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

sd/mmc & pic18f2520

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
zaremchichak



Joined: 31 Jan 2012
Posts: 3

View user's profile Send private message

sd/mmc & pic18f2520
PostPosted: Sun Feb 19, 2012 10:26 am     Reply with quote

Hello!
Sorry, I'm from Russia and my english bad.
I'm trying to connect pic18f2520 and sd/mmc card.
Used:
Driver from http://www.ccsinfo.com/forum/viewtopic.php?t=31532
SanDisk 256 SD card - connected with 78l33, spi interface - with resistors 1.8k&3.3k on CLK, DI, CS and without it on DO.
On pic - internal oscillator 8 MHz
I'm try to run example code from this driver. For connect to PC used Terminal by Bray. They give me this text:

"MMC initialized
Error1st file in list was probably a dir"

Where I made a mistake, why it don't working correctly?
Schematic is ok.
on bottom - example project, please, help me! MMC_SPI_FAT32.h, MMC_SPI_FAT32.с did not change, modifed only "printf(glcd_putc,"NoLongFileName!");" string in MMC_SPI_FAT32.с - was removed.
Code:

#include <18f2520.h>
#fuses INTRC_IO,NOWDT,PROTECT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=pin_C6, rcv=pin_C7)

   #include <string.h>
   #include <MMC_SPI_FAT32.h> // As usual you also need to     
   #include <MMC_SPI_FAT32.c> // include your device .h file...


   void main(void)                                             
   {                                                           
      char f,filename[20],res,i,c;                             
      delay_ms(20);
      printf("\r\npic18 started! Good luck!\r\n");
      while(TRUE)                                               
      {
                                                               
         if(MMCInit() == MMC_OK)                               
         {                                                     
            printf("MMC initialized\r\n");                     
            InitFAT();                                         
            strcpy(filename,"DIR/");                           
            f = InitList(filename);                             
            if(f & MMC_ERROR)                                   
               printf("Error");                                 
            else                                               
            {                                                   
               do                                               
               {                                               
                  res = ListFiles(f);                           
                  for(i=0;i<res;i++)                           
                  {                                             
                     printf(FileList[i].name);                 
                     if(FileList[i].isDir)                     
                        printf("\\\r\n");//a "\" with row break
                     else                                       
                        printf("\r\n");                         
                  }                                             
               } while(NextPage(f) == MMC_OK);                 
               CloseList(f); // frees the file, but the list is
            }                // still there...                 
            strcpy(filename,FileList[0].shortName);             
            f = fopen(filename,'r'); // open file for reading   
            if((f & MMC_ERROR) == 0) // No error, same as       
            {                        // if(f < MAXFILES)       
               while(fgetch(&c,f) == MMC_OK)                   
                  printf(c);                                   
               fclose(f);                                       
            }                                                   
            else if(f == MMC_NOT_FOUND)                         
               printf("1st file in list was probebly a dir");   
            else                                               
               printf("Other error\r\n");                       
            while(TRUE)                                         
               ; // Loop forever, program is finished           
         }                                                     
         else                                                   
            printf("MMC init failed!\r\n");                     
         delay_ms(1000);                                       
         printf("Trying once more..\r\n");                     
      }                                                         
   }   
temtronic



Joined: 01 Jul 2010
Posts: 9162
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 12:48 pm     Reply with quote

Your mistake is in the HARDWARE and no amount of Software will fix it!

You CANNOT connect a 5 volt PIC to a 3 volt MMC card directly!! Resistors will NOT work......don't know how that ever got started...

Your 3 volt MMC card cannot give 5 volt OUTPUT to PIC for PROPER logic levels....

SEARCH this forum and you'll see dozens of replies,messages, etc.......about this problem which starts by NOT reading the datasheets of the devices....


YOU have 3 options
1) buy a 'low voltage' PIC ie: 18LF4550... 'L' means low voltage

2) add logic level translation chip inbetween the 5 volt PIC and the 3 volt MMC card

3) give up...find another hobby...
zaremchichak



Joined: 31 Jan 2012
Posts: 3

View user's profile Send private message

PostPosted: Sun Feb 19, 2012 6:45 pm     Reply with quote

ok, but why in internet we have a lot of devices, based on this shematic and work?
Hm...
Can i use logic level converter basen on BSS88 mosfets?
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Feb 19, 2012 7:08 pm     Reply with quote

zaremchichak wrote:
ok, but why in internet we have a lot of devices, based on this shematic and work?


There are lots of schematics by people that failed to read or understand the electrical specifications of the PIC micro-controller. You CAN use resistor dividers between the PIC and the SD/MMC card for the SDO, SCK and CS.

You SHOULD NOT directly connect DO from the SD card to SPI of the PIC. When the PIC is configured to use the SPI peripheral the input mode switches to Schmidt trigger input. If you examine the worst case logic 1 output voltage for the SD/MMC card (lowest voltage guaranteed for a logic 1) the value is LOWER that the PIC's guaranteed level to detect a logic 1. This means, in a worst case scenario a logic 1 output from the media is detected as a logic 0 by the PIC. Despite this worst case scenario, it works. So the question is when would it fail?

It could fail when the temperate reaches 38 deg C (or not)
It could fail when the temperature reaches 0 deg C (or not)
It could fail on a full moon (or not)
It could fail on a Tuesday (or not)
It could fail at any time (or not)
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group