free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Rickey's World :: Discussion Forums :: Discuss and Learn :: 8051 Discussion Forum
 
<< Previous thread | Next thread >>
MMC/SD Card interfacing and FAT16 File system - auto_mount problem
Go to page       >>  
Moderators: Ajay Bhargav, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph, ExperimenterUK, DavesGarage
Author Post
jmarques
Tue May 12 2009, 07:17AM
 User Offline
Registered Member #18426
Joined: Tue May 12 2009, 03:17AM

Posts: 7
Thanked 0 times in 0 posts
Hi,

I have a problem with auto_mount(), it is returning FR_WRITE_PROTECTED and i can't understand why. It is always in this part :

/* The logical drive must be re-mounted. Following code attempts to mount the logical drive */

memset(fs, 0, sizeof(FATFS)); /* Clean-up the file system object */
stat = disk_initialize(0); /* Initialize low level disk I/O layer */
if (stat & STA_NOINIT) /* Check if the drive is ready */
return FR_NOT_READY;
#if !_FS_READONLY
if (chk_wp && (stat & STA_PROTECT)) /* Check write protection if needed */
return FR_WRITE_PROTECTED;

Does this mean that the card is write protected? The SD card is new. Can they come from factory write protected?
I am using an 80c51f410.

THANKS!!!

Back to top

DavesGarage
Tue May 12 2009, 11:20AM

 User Offline
Registered Member #14254
Joined: Tue Jan 20 2009, 08:14AM

Posts: 609
Thanked 114 times in 110 posts
Chan's auto_mount() function decides if the card is write protected by looking at the return value from your disk_initialize() function.

Notice the parameters that are passed to auto_mount()? The last parameter is called "chk_wp" - this is a flag to check for write_protection. If this value is set to 1, then the last line in your code above will be executed. If it is zero, then it won't.

When you scan through all of the calls to auto_mount(), you will find that some have this set to 1, and some don't. The ones that have it set to 1 are the functions that want to write to the card, like making directories, making files, formatting the card, etc...

But the reason why you are getting the FR_WRITE_PROTECTED message is because the "stat" variable, which was set within your disk_initialize() function, has the STA_PROTECT bit set.

Try looking in the disk_initialize() function. This is where you problem lies...

Hope this helps,


-Dave
"Basic research is what I am doing when I don't know what I am doing"
Back to top

jmarques
Wed May 13 2009, 02:21AM
 User Offline
Registered Member #18426
Joined: Tue May 12 2009, 03:17AM

Posts: 7
Thanked 0 times in 0 posts
Hi,

The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:

if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;

With fm=2 the auto_mout returns :

if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;

Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.

Thanks for the help.
Back to top

jmarques
Thu May 14 2009, 04:15AM
 User Offline
Registered Member #18426
Joined: Tue May 12 2009, 03:17AM

Posts: 7
Thanked 0 times in 0 posts
Hi,

The disk_initialize() is the same as the example that is given here, and the SD_Init returns 0 as it should. Later I tried to send the command CLR_WRITE_PROT before the f_open, this as solved the problem... Now i have another one, again in auto_mount(). When it search for the FAT partition on the drive:
fmt = check_fs(bootsect = 0); the check_fs returns 2 (fm=2) in the second condition:

if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature */
return 2;

With fm=2 the auto_mout returns :

if (fmt || LD_WORD(&fs->win[BPB_BytsPerSec]) != 512U) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;

Do you think that there is a problem with the SD card? I have formatted the card in FAT and later i tried with FAT32. the same error happens.

Thanks for the help.
Back to top

DavesGarage
Tue May 19 2009, 08:44AM

 User Offline
Registered Member #14254
Joined: Tue Jan 20 2009, 08:14AM

Posts: 609
Thanked 114 times in 110 posts
Try separating the conditions in the if() statement, and look at the value returned from LD_WORD().

For instance:

NewVar = LD_WORD(&fs->win[BPB_BytsPerSec]);
if( fmt || (NewVar != 512U) ) /* No valid FAT patition is found */
return FR_NO_FILESYSTEM;


Tell me the value of NewVar and fmt...


-Dave
"Basic research is what I am doing when I don't know what I am doing"
Back to top

jmarques
Wed May 20 2009, 03:18AM
 User Offline
Registered Member #18426
Joined: Tue May 12 2009, 03:17AM

Posts: 7
Thanked 0 times in 0 posts
Hi,

NewVar = 0x00;
ftm = 0x02;
Back to top

DavesGarage
Wed May 20 2009, 08:04AM

 User Offline
Registered Member #14254
Joined: Tue Jan 20 2009, 08:14AM

Posts: 609
Thanked 114 times in 110 posts
try formatting the SD card using the f_mkfs() function. If NewVar == 0x00, then your SD card isn't formatted correctly.



-Dave
"Basic research is what I am doing when I don't know what I am doing"
Back to top

jmarques
Wed May 20 2009, 09:49AM
 User Offline
Registered Member #18426
Joined: Tue May 12 2009, 03:17AM

Posts: 7
Thanked 0 times in 0 posts
Using that func isn't the same as the format of windows?? because i have formatted in FAT16 and 32 and still didn't work.
It is possible that the 2 card that i have, have problems??
The 2 card are:
2Gb, Kingston and it is recognized as a type2.
1Gb, ??? and it is recognized as a type 1.
Back to top

jmarques
Wed May 20 2009, 09:51AM
 User Offline
Registered Member #18426
Joined: Tue May 12 2009, 03:17AM

Posts: 7
Thanked 0 times in 0 posts
Can you give an example of the f_mkfs(), I can't find one.

Thanks
Back to top

Ajay Bhargav
Thu May 21 2009, 01:32PM
Rickey's World Admin

 User Offline

Registered Member #1
Joined: Fri Feb 24 2006, 04:56AM

Posts: 7265
Thanked 1281 times in 1209 posts
can you try with a lower size card? 512MB or 256MB?

www.rickeyworld.info
If you feel satisfied with the user's forum reply please click on the thank button.

Obey forum rules!
Respect others!
Back to top

Go to page       >>   

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems