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 CCS Technical Support

Another MMC Over SPI FAT32 code!
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
incubus22



Joined: 15 Nov 2007
Posts: 14

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 10:30 am     Reply with quote

Why isn't anybody answering??? Hello Miniman... Are you still there?
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Nov 26, 2007 5:05 am     Reply with quote

Hi, im trying to simulate this code on proteus VSM, but im having some problems.... the MMCInit function does not work (but i already fixed it)... and a INITFat function does not work too.

my question is:

where all those structs and variables are initizalized ?

in this piece of code

Code:
   memcpy(&DiskInfo,gFiles[MAXFILES-1].IOpuffer,sizeof(DiskInfo));



DiskInfo struct is initialized with the data in IOPuffer, but IOpuffer are not initialized either.

Code:

   if (gFiles[MAXFILES-1].IOpuffer[0] != 0xEB)
   {
         gStartSectorL    = gFiles[MAXFILES-1].IOpuffer[0x1C6];
         gStartSectorH    = gFiles[MAXFILES-1].IOpuffer[0x1C7];
         gStartSectorHL    = gFiles[MAXFILES-1].IOpuffer[0x1C8];
         
         ReadSector (gFAT32Vars.gStartSector, gFiles[MAXFILES-1].IOpuffer);
   }





the data in IOpuffer never will be 0xEB, insted it is 0xFF

when this calculus

Code:


      actsector = gFAT32Vars.gStartSector + DiskInfo.Reserved1;
 



or

Code:

gFAT32Vars.gFirstDataSector = gFAT32Vars.gStartSector + DiskInfo.FATCopies * DiskInfo.hSectorsPerFat + DiskInfo.Reserved1 - 2;



is done:

we got a overflow in gFat32Vars.gFirstDataSector...

All those variables in that math have a 0xffff... value.

somebody have any sugestion ????

thanks in advance.

regards.
_________________
Andre
incubus22



Joined: 15 Nov 2007
Posts: 14

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 5:54 am     Reply with quote

Hello andreluizeng!

Mine is working properly. The only problem is the writing speed. Confused
Milhaus



Joined: 20 Oct 2007
Posts: 9

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 6:15 am     Reply with quote

incubus
if your HW SPI does not work, you have probably connected SPI device to different pins than use your PIC for HW SPI.

Milos
Milhaus



Joined: 20 Oct 2007
Posts: 9

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 6:30 am     Reply with quote

andreluizeng: the first sector MBR( start with 0xEB ) is read in InitFAT function look below. If not then SPI communication does not work or you have any problem with MMCInit.Do you have card formatted to FAT32 ?

void InitFAT()
{
int32 actsector;
char i;

gFirstEmptyCluster = 0;
gFAT32Vars.gStartSector = 0;
ReadSector(gFAT32Vars.gStartSector,gFiles[MAXFILES-1].IOpuffer);
if (gFiles[MAXFILES-1].IOpuffer[0] != 0xEB)
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Nov 26, 2007 7:02 am     Reply with quote

Milhaus,

my spi is totally functional, as i said, im using proteus VSM (simulation), probably my mmc initialization isnt working very good.

im try again.

thanks.
_________________
Andre
incubus22



Joined: 15 Nov 2007
Posts: 14

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 8:01 am     Reply with quote

Milhaus wrote:
incubus
if your HW SPI does not work, you have probably connected SPI device to different pins than use your PIC for HW SPI.

Milos


Hello Milhaus! Thank you for replying! Very Happy

I connected the MMC to the right SPI hardware pins on the PIC. Please try the hardware SPI configuration and your code (with hardware SPI settings on) on your own and let's compare notes. Please... Wink
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Nov 26, 2007 8:25 am     Reply with quote

Incubus,

try this code.. it probably will work.

Code:

#define   SPI_ENABLE  0x20
#define   SPI_DISABLE 0x00
#define CLK_L_TO_H   0x10
#define CLK_H_TO_L  0x00
#define CLK_DIV_4   0x00
#define CLK_DIV_16  0x01
#define CLK_DIV_64  0x02


void SPIConfig (void)
{
   SSPCON1 = 0x00;
   
   SSPCON1 = SPI_ENABLE | CLK_L_TO_H |  CLK_DIV_4;
}   



change configuration whatever way you want.

regards.
_________________
Andre
Miniman



Joined: 30 Apr 2007
Posts: 44

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 2:39 pm     Reply with quote

Hi!
sorry for being off a while. If your HW SPI does not work maybe the SDI pin don't recognize 3.3V as a logic '1'. Check the datasheet to see what type of pin it is when using it with SPI. You may need to convert 3.3v to 5v to get it to work properly. I believe i saw a thread in the discussion part of this forum about 3.3v to 5v and 5v to 3.3v conversion not long ago. This may be the problem.. otherwise i do not know what i could be..
Also make sure that these registers have the right address:
Code:

   #byte SSPBUF   = 0xFC9
   #byte SSPSTAT   = 0xFC7
   #byte SSPCON1   = 0xFC6
   #bit  BF      = SSPSTAT.0

I believe this would also work (and better for using in different pic:s):
Code:

   #byte SSPBUF   = Getenv("SFR:SSPBUF")
   #byte SSPSTAT   = Getenv("SFR:SSPSTAT")
   #byte SSPCON1   = Getenv("SFR:SSPCON1")
   #bit  BF      = SSPSTAT.0


hope it helps..
and to you andreluizeng, I do not know anything about proteus, but i know the code works in real life..

best regards
miniman
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Nov 26, 2007 4:21 pm     Reply with quote

Miniman, whats up ?

I fixed de code... now im using fat32 on pic18f2525.

im having now little problems like: no removing an existing file, or.. when i try to open a file with 'r' argument.. it creates another one... but i think that is not 'too' hard to fix.

thank you for the reply..

regards.
_________________
Andre
incubus22



Joined: 15 Nov 2007
Posts: 14

View user's profile Send private message

PostPosted: Tue Nov 27, 2007 12:22 am     Reply with quote

Hello andreluizeng! Smile

I managed it to work by implementing what you said. Thank you! Very Happy

I have another question. What delay should I use with this line of code in CCS?

#use delay(clock=20000000)

I am using a 20MHz crystal.

I also used HS for the oscillator option. Are my settings correct to get the maximum speed of writing data on the MMC? I really need to write data in a very fast manner.

Thanks in advance! Very Happy
vikram.kadian



Joined: 28 Nov 2007
Posts: 1
Location: CHENNAI,INDIA

View user's profile Send private message

mmc -spi
PostPosted: Wed Nov 28, 2007 12:47 am     Reply with quote

can anyone tell me hoe to write mmc in fat format . i have seen few programs with including files such as MMC_SPI_FAT32.C or .h . anybody have these files with them then please do send me to my mail id [email protected] . thanks in advance bro.
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

FAT32 on SD/MMC
PostPosted: Mon Feb 04, 2008 6:01 am     Reply with quote

Hi,

I have been trying to get the modified version of Tomi's code to work on a 18F2620, using hardware SPI. The code works providing I use DIV16 on the SPI, not DIV4.

The problem I find is this:

I write a small (about 300 bytes) file to the card - I can read this fine on the PC.

I then write a second file.

When I look at the card on the PC, either:

The second file id there and OK and the first file is corrupt and has lost its filename

or:

There is only one corrupted file with no name on the card.

The only way to get rid of the corrupted file is to reformat the card!!

The corrupted file says 256 bytes when mouse hovering over it, but 0 bytes in properties!

Can anyone help please?

Thanks

Brian
andreluizeng



Joined: 04 Apr 2006
Posts: 117
Location: Brasil

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Feb 05, 2008 3:33 pm     Reply with quote

Incubus22,


Im using 20MHz clock and clock_div_64 (312.5 khz clock) until those commands were sents:

1 - CMD0 (Reset)
2 - CMD1 (SPI)
3 - CMD16 (BLOCK SIZE)
4 - CMD10 (CID)
5 - CMD9 (CSD)
6 - CMD6 (HI-SPEED MODE)

then you can change spi clock to clock_div_4 (at 20MHZ fullspeed is 5mhz (theorical)) and write or read at a higher speed. (im not using any delay between comands)

im using it and still working.

hope it helps.

regards.
_________________
Andre
BLL



Joined: 11 Nov 2006
Posts: 181
Location: Birmingham, UK

View user's profile Send private message

PostPosted: Tue Feb 05, 2008 3:43 pm     Reply with quote

Hi,
Thanks for that - I'll go and play with it.

Brian
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 3 of 6

 
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