Interfacing SD card with Atmega32 via SPI using codevision avr v2.05.3

Go To Last Post
37 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi all, 

 Good day. I did interfacing SD card with Atmega32 via SPI.  i gone through with these links http://elm-chan.org/fsw/ff/00index_e.htmlIn this i could not create or open a existing file. And my code is

 http://elm-chan.org/fsw/ff/en/open.html
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date    : 11/3/2014
Author  : Dev6
Company : sass
Comments:


Chip type               : ATmega32L
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512
*****************************************************/

#include <mega32.h>
#include <stdio.h>
#include <stdlib.h>
#include <spi.h>
#include <sdcard.h>
#include <ff.h>
#include <delay.h>



void main(void)
{

    unsigned char wr_buf[7] = "sriram";
    unsigned int i=0;
    FRESULT res;
    FATFS fs;
    FIL fp;
    unsigned char buffer[10];
    unsigned int br, bw;               // File read/write count
    
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xB0;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 2000.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x00;

puts("\nstart_sd_card");

res = f_mount(0, &fs);
if (res == FR_OK)
{
    printf("\nres_mount: %d", res);
}

if (res == FR_OK)
{
    puts("\nin create_new");
    res = f_open(&fp,"0:sd0.txt",FA_CREATE_NEW);    //create a new file
}
else puts("\nfail create_new");
f_close(&fp);

if (res == FR_OK)
{
    puts("\nin write");
    res = f_open(&fp,"0:sd0.txt",FA_WRITE);
    //res = f_write(&fp,buffer,sizeof buffer,&br);
    res = f_write(&fp,wr_buf,sizeof(wr_buf),&bw);
}
else puts("\nfail write");
f_close(&fp);   

if (res == FR_OK)
{
    puts("\nin read");
    res = f_open(&fp,"0:sd.txt",FA_READ);
    if(res) printf("res: %d",res);
    //delay_ms(2000);
    //res = f_read(&fp,buffer,br,&bw);
    res = f_read(&fp,buffer,10,&bw);
    if(res) printf("res_read: %d",res);
    printf("\nbuffer:%s",buffer);
}
else puts("\nfail read");
f_close(&fp);

puts("\nend"); 


while (1)
      {
      // Place your code here

      }
}

and my result is 

 

 

start_sd_card

             res_mount: 0

in create_new

 

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

Last Edited: Wed. Nov 5, 2014 - 11:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and now i changed code. reference link is http://elm-chan.org/fsw/ff/en/open.html

 

/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.3 Standard
Automatic Program Generator
© Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project :
Version :
Date    : 11/5/2014
Author  : Dev6
Company : sass
Comments:


Chip type               : ATmega32L
Program type            : Application
AVR Core Clock frequency: 8.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 512
*****************************************************/

#include <mega32.h>
#include <stdio.h>
#include <spi.h>
#include <ff.h>
#include <sdcard.h>

// Declare your global variables here

FATFS FatFs;   /* Work area (file system object) for logical drive */

void main(void)
{
// Declare your local variables here

    FIL fil;       /* File object */
    char line[20]; /* Line buffer */
    FRESULT fr;    /* FatFs return code */
    unsigned int bw;

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=Out Func6=In Func5=Out Func4=Out Func3=In Func2=In Func1=In Func0=In
// State7=0 State6=T State5=0 State4=0 State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0xB0;

// Port C initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTC=0x00;
DDRC=0x00;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x00;
DDRD=0x00;

// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud Rate: 9600
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 2000.000 kHz
// SPI Clock Phase: Cycle Start
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x50;
SPSR=0x00;

    puts("\nstart");
    /* Register work area to the default drive */
    fr = f_mount(0,&FatFs);
    if(fr == FR_OK)
    {
        printf("\nfr_mount: %d",fr);
    }

    /* Open a text file */
    if(f_open(&fil, "sd.txt", FA_READ) == FR_OK)
    {
        printf("\nfr: %d",fr);
    }

    /* Read all lines and display it */
    //    while (fgets(line, sizeof line, &fil))
    fr = f_read(&fil,line,19,&bw);
        printf("\nline: %s",line);

    /* Close the file */
    f_close(&fil);

    puts("\nend");

while (1)
      {
      // Place your code here

      }
}

result

 

start

     fr_mount: 0

 

But I could not  open the sd card. Why it is. i did some mistake but i dont know where the mistake is ane what it is.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

Last Edited: Wed. Nov 5, 2014 - 11:33 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

But I could not  open the sd card. Why it is. i did some mistake but i dont know where the mistake is ane what it is.

The whole point of Fatfs (or any library for that matter) returning OK/Error codes is so that if it does go wrong you can print/examine the error to see what went wrong. The 0 return from the f_mount() seems to suggest that went OK but then you do:

    /* Open a text file */
    if(f_open(&fil, "sd.txt", FA_READ) == FR_OK)
    {
        printf("\nfr: %d",fr);
    }

Surely it is actually more interesting to know what f_open() returned if it is NOT FR_OK?!? So something like:

    /* Open a text file */
    fr = f_open(&fil, "sd.txt", FA_READ);
    if(fr == FR_OK)
    {
        printf("\nfr: %d",fr);
    }
    else {
        printf("OPEN returned error %d\n", fr);
    }

This will give you an error code that you can then check against:

/* File function return code (FRESULT) */

typedef enum {
	FR_OK = 0,				/* (0) Succeeded */
	FR_DISK_ERR,			/* (1) A hard error occurred in the low level disk I/O layer */
	FR_INT_ERR,				/* (2) Assertion failed */
	FR_NOT_READY,			/* (3) The physical drive cannot work */
	FR_NO_FILE,				/* (4) Could not find the file */
	FR_NO_PATH,				/* (5) Could not find the path */
	FR_INVALID_NAME,		/* (6) The path name format is invalid */
	FR_DENIED,				/* (7) Access denied due to prohibited access or directory full */
	FR_EXIST,				/* (8) Access denied due to prohibited access */
	FR_INVALID_OBJECT,		/* (9) The file/directory object is invalid */
	FR_WRITE_PROTECTED,		/* (10) The physical drive is write protected */
	FR_INVALID_DRIVE,		/* (11) The logical drive number is invalid */
	FR_NOT_ENABLED,			/* (12) The volume has no work area */
	FR_NO_FILESYSTEM,		/* (13) There is no valid FAT volume */
	FR_MKFS_ABORTED,		/* (14) The f_mkfs() aborted due to any parameter error */
	FR_TIMEOUT,				/* (15) Could not get a grant to access the volume within defined period */
	FR_LOCKED,				/* (16) The operation is rejected according to the file sharing policy */
	FR_NOT_ENOUGH_CORE,		/* (17) LFN working buffer could not be allocated */
	FR_TOO_MANY_OPEN_FILES,	/* (18) Number of open files > _FS_SHARE */
	FR_INVALID_PARAMETER	/* (19) Given parameter is invalid */
} FRESULT;

that should give you a strong clue as to why something is not working! For example if it was 4 then it's saying "could not find the file".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes clawson. It is good thing. I will check it.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

The answer is pretty obvious.

 

Since you did not receive a

printf("\nfr: %d",fr);

it is obvious that the

if(f_open(&fil, "sd.txt", FA_READ) == FR_OK)

has failed.

 

As Cliff has suggested,    you should always do something with the Error returns.

In practice,   some FILE operations are more likely to fail than others.    e.g. f_mount() with no disk or f_open() with no file.

 

Once a file has been sucessfully opened,    most operations will be ok.    until you fill up your 32GB SDCard.

It is still wise to check.     After all,   it might be that you have been using a tiny 1MB Card.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

BTW I just deleted two more copies of your thread. The one I responded to was the one that was wrongly placed in the Xmega forum so I also moved it here. I have therefore delete the two further copies you had created in this tiny/mega forum.

 

Please don't cross post in future. If you realise you have posted in the wrong place in future contact a moderator who will move the thread for you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi david & clawson,

 

    Good day. Sorry for very late. 

 

 

    for this below code i am getting output as

                                                start

                                              fr_mount: 0

 fr = f_mount(0,&FatFs);
    if(fr == FR_OK)
    {
        printf("\nfr_mount: %d",fr);       //FR_OK=0
    }
    else
    {
        printf("\nmount returned error: %d",fr);
    }

    fr = f_open(&fil, "BOOTEX.txt", FA_READ);
    if(fr == FR_OK)
    {
        printf("\nfr: %d",fr);
    }
    else
    {
        printf("\nOPEN returned error: %d",fr);
    }

    f_close(&fil);

    puts("\nend");

 after removed this part

fr = f_mount(0,&FatFs);
    if(fr == FR_OK)
    {
        printf("\nfr_mount: %d",fr);       //FR_OK=0
    }
    else
    {
        printf("\nmount returned error: %d",fr);
    }

now output is

 

               start

               OPEN returned error: 12
               end

 

I am using 8GB micro SD card and more space also available.  but error  is no work area. how to overcome this problem.

FR_NOT_ENABLED,			/* (12) The volume has no work area */

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

Last Edited: Tue. Nov 18, 2014 - 12:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Args for f_mount are:

fs      Pointer to the new file system object to be registered. Null pointer unregisters the registered file system object.

path  Pointer to the null-terminated string that specifies the logical drive. The string with no drive number means the default drive.

opt    Initialization option. 0: Do not mount now (to be mounted later), 1: Force mounted the volume to check if the FAT volume is available.

So by passing 0 as the first argument are you are not mounting anything (does it even compile without warnings?).
/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Lars,

 

You sure? My ff.h has:

FRESULT f_mount (BYTE vol, FATFS* fs);                                                          /* Mount/Unmount a logical drive */

With only one volume the "vol" wil be 0. So:

 fr = f_mount(0,&FatFs);

seems reasonable to me. What ff.h also contains is:

typedef enum {
	FR_OK = 0,				/* (0) Succeeded */
	FR_DISK_ERR,			/* (1) A hard error occurred in the low level disk I/O layer */
	FR_INT_ERR,				/* (2) Assertion failed */
	FR_NOT_READY,			/* (3) The physical drive cannot work */
	FR_NO_FILE,				/* (4) Could not find the file */
	FR_NO_PATH,				/* (5) Could not find the path */
	FR_INVALID_NAME,		/* (6) The path name format is invalid */
	FR_DENIED,				/* (7) Access denied due to prohibited access or directory full */
	FR_EXIST,				/* (8) Access denied due to prohibited access */
	FR_INVALID_OBJECT,		/* (9) The file/directory object is invalid */
	FR_WRITE_PROTECTED,		/* (10) The physical drive is write protected */
	FR_INVALID_DRIVE,		/* (11) The logical drive number is invalid */
	FR_NOT_ENABLED,			/* (12) The volume has no work area */
	FR_NO_FILESYSTEM,		/* (13) There is no valid FAT volume */
	FR_MKFS_ABORTED,		/* (14) The f_mkfs() aborted due to any parameter error */
	FR_TIMEOUT,				/* (15) Could not get a grant to access the volume within defined period */
	FR_LOCKED,				/* (16) The operation is rejected according to the file sharing policy */
	FR_NOT_ENOUGH_CORE,		/* (17) LFN working buffer could not be allocated */
	FR_TOO_MANY_OPEN_FILES,	/* (18) Number of open files > _FS_SHARE */
	FR_INVALID_PARAMETER	/* (19) Given parameter is invalid */
} FRESULT;

So 12 is FR_NOT_ENABLED - "The volume has no work area". When you grep the source for FR_NOT_ENABLED you find:

	fs = FatFs[vol];					/* Get corresponding file system object */
	if (!fs) return FR_NOT_ENABLED;		/* Is the file system object available? */

in two places - these are the only places that return that code. So the conclusion must be that the pointer to FATFS struct is NULL.

 

That's curious as you create it as an automatic in main(). Could if be that Codevision does not have sufficient space on its data stack to hold the 560 (is it?) byte object?

 

Personally I'd always just make the FATFS struct a global anyway (yeah, yeah, I know all the arguments against this!).

 

EDIT sorry I was looking at the first code in the thread where the struct is an auto. Later I see it is a global (good choice). Now I don't know what CodeVision does if .bss overflows the allocation but could it be it just assigns the symbol 0? (I would have thought there'd be a linker error though?). What micro is this? Does it have enough RAM to even run FatFs?

 

EDIT: (again) - silly forum - while editing you cannot see the thread title. If I could have seen that I would have known the answer to my last question! So 2K SRAM should be OK. Perhaps CV needs to be configured to give more RAM to .bss?

 

Last Edited: Tue. Nov 18, 2014 - 01:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CV calculates how much room it needs on its data stack.   It will detect if you have any recursive calls.

 

It is wise to allow a little extra space for variadic functions like printf().

 

No,    I have not looked at the OP's code.

However,    CV comes with example projects for a mega128.    I would suggest that you try them first.

Most of them can be rebuilt for a mega32.

 

Quite honestly,    CV makes it very easy to add <ff.h> functionality to any project.

You just have to provide a 10ms ISR() that calls disk_timerproc()

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

CV calculates how much room it needs on its data stack.  

Yes, and IME does a fairly good job.  It is still up to the coder to set the project configurations for both values appropriately.

 

Re GREPing for stuff in CV+FatFs -- unfortunately, CV chose to make the FatFs integration a "black box" library, which makes certain explorations difficult.

 

I'd have to work through FatFs "installation" again, but perhaps it is simply something like "disk present" not properly configured.  Or SPI setup, or CS.  Or similar.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then can anyone here think how it can be that:

FATFS FatFs;   /* Work area (file system object) for logical drive */

void main(void)
{
    ...
       fr = f_mount(0,&FatFs);
    ...
       if(f_open(&fil, "sd.txt", FA_READ) == FR_OK)

would lead to  the f_open() returning a code to say it thinks the &FatFs passed in the mount was 0? The mount code is:

FRESULT f_mount (
	BYTE vol,		/* Logical drive number to be mounted/unmounted */
	FATFS *fs		/* Pointer to new file system object (NULL for unmount)*/
)
{
	FATFS *rfs;


	if (vol >= _VOLUMES)		/* Check if the drive number is valid */
		return FR_INVALID_DRIVE;
	rfs = FatFs[vol];			/* Get current fs object */

	if (rfs) {
#if _FS_LOCK
		clear_lock(rfs);
#endif
#if _FS_REENTRANT				/* Discard sync object of the current volume */
		if (!ff_del_syncobj(rfs->sobj)) return FR_INT_ERR;
#endif
		rfs->fs_type = 0;		/* Clear old fs object */
	}

	if (fs) {
		fs->fs_type = 0;		/* Clear new fs object */
#if _FS_REENTRANT				/* Create sync object for the new volume */
		if (!ff_cre_syncobj(vol, &fs->sobj)) return FR_INT_ERR;
#endif
	}
	FatFs[vol] = fs;			/* Register new fs object */

	return FR_OK;
}

so unless f_mount was called already (not seen in OP's test code) then FatFs[0] and hence rfs should be 0 so it should just drop through to set FatFs[0] = user's "FatFs" (how confusing!). Later in f_open() it calls to chk_mounted() and that's where it does:

	/* Check if the file system object is valid or not */
	*rfs = 0;
	if (vol >= _VOLUMES) 				/* Is the drive number valid? */
		return FR_INVALID_DRIVE;
	fs = FatFs[vol];					/* Get corresponding file system object */
	if (!fs) return FR_NOT_ENABLED;		/* Is the file system object available? */

which is where it find !fs (for FatFs[0] == 0) and returns the error the user is seeing.

 

Unless FatFs[] itself is corrupted along the way I don't see what potential there is for the pointer in the array to be zero?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Lars,

 

You sure? My ff.h has:

FRESULT f_mount (BYTE vol, FATFS* fs);                                                          /* Mount/Unmount a logical drive */


My ff.h from 2008 looks like that also, it is however not what the current version looks like:

http://elm-chan.org/fsw/ff/en/mo...

So it all depends on what version OP is using.

/Lars

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi all,

 

   Good day. 

 

    Data stack size : 1024  and Internal RAM size : 2048. I am not getting this point. Can you please explain me. sorry for asking again.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi david,

   Good day. Okay i will try with example project of atmega128.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried CodeVisionAVR's Example code of ATMEGA128 from help. but i this even without sd card circuit also output is same "mounted OK".

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So it all depends on what version OP is using.

Ooh, that's a bit nasty, changing the actual API that will break all existing code!? Not good.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry clawson. for atmega128 i created different .c file and what is OP means.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

OP means "original poster" (or sometimes just "original post"). It's talking about the person who started the thread and what they originally wrote. Lars point is that if you are using the "old" version of FatFs then your call to f_mount() is valid but if you are using the latest issued version that Chan now has on his website then the way you call f_mount() is wrong. To be honest I think you MUST have the old version (unless the new one is implemented with variadic parameters) because the old version had 2 parameters and the new one has 3. If you called the new one using the parameters for the old one you would get a compiler error about "too few parameters for function f_mount" (unless, as I say, it's been implemented as being variadic - but I doubt that).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

OP means "original poster" (or sometimes just "original post"). It's talking about the person who started the thread and what they originally wrote. Lars point is that if you are using the "old" version of FatFs then your call to f_mount() is valid but if you are using the latest issued version that Chan now has on his website then the way you call f_mount() is wrong. To be honest I think you MUST have the old version (unless the new one is implemented with variadic parameters) because the old version had 2 parameters and the new one has 3. If you called the new one using the parameters for the old one you would get a compiler error about "too few parameters for function f_mount" (unless, as I say, it's been implemented as being variadic - but I doubt that).

 

yes it may be older version. Version of CodeVision v2.05.3. And in ff.h only 2 parameters available. the function for f_mount is:

 

/* Mount/Unmount a logical drive */
FRESULT f_mount (unsigned char vol , FATFS* fs);

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The current CV implementation is based on an earlier Chan release.  (R0.07e)

 

Yes,   the API has been changed by Chan.     Yes,   this will give migration problems.

Which is probably why Pavel has stuck to the original API.     After all,    Pavel is supplying something that should work out of the box.     Even for 'older' CV projects.

 

I was intending to do something with CV,  Xmega, USART_MSPI and <ff.h> today.

 

I will probably try sasi's program on a Mega before I start with the Xmega.

 

David.

Last Edited: Wed. Nov 19, 2014 - 10:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

The current CV implementation is based on an earlier Chan release.

 

Yes,   the API has been changed by Chan.     Yes,   this will give migration problems.

Which is probably why Pavel has stuck to the original API.     After all,    Pavel is supplying something that should work out of the box.     Even for 'older' CV projects.

 

I was intending to do something with CV,  Xmega, USART_MSPI and <ff.h> today.

 

I will probably try sasi's program on a Mega before I start with the Xmega.

 

David.

 

 Thak you david. Thanks alot david.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

OP means "original poster" (or sometimes just "original post"). It's talking about the person who started the thread and what they originally wrote. Lars point is that if you are using the "old" version of FatFs then your call to f_mount() is valid but if you are using the latest issued version that Chan now has on his website then the way you call f_mount() is wrong. To be honest I think you MUST have the old version (unless the new one is implemented with variadic parameters) because the old version had 2 parameters and the new one has 3. If you called the new one using the parameters for the old one you would get a compiler error about "too few parameters for function f_mount" (unless, as I say, it's been implemented as being variadic - but I doubt that).

 

yes clawson it maybe work with new version. But if want to work with old version, then anyother option to do.

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Well,   I took the directory scan example from the Help file.

 

1.  Made a project for a ATmega328P

2.  enabled <ff.h> support.  selected CS pin.    no WP or CD pin

3.  copied the mega128 code and edited for <io.h>

4.  compiled.

5.  I had to edit TIMSK1 instead of TIMSK.

6.  adjusted data stack to 1500 bytes.    (it is recursive)

 

Ran the program on a UNO.     Ran fine.     Even with a deeply nested directory structure.

 

Note that for the mega32,    you need to edit the UART register names but TIMSK is probably ok.

 

I am sure that everything would build the same on v2.05.3

 

If you don't believe me,    I could build it for a Mega32 and email you the HEX file.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I took the directory scan example ...

Perhaps a good idea for OP as well.  The "failing" code is on the open of an existing file.  Perhaps it isn't where OP thinks it is on the card...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 Hi all,

 

      Good day. Thanks david.prentice and  theusch .  i  am believe you  david.prentice . Okay now i will do it and if there any doubt i will ask. Thank you for taking effort for me. 

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 Hi  david.prentice,

 

   If you don't mine, can you please send the code. I am not getting the output. my mail id is sasirekaece@gmail.com 

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please tell me the CS, CD, WP for your SDcard.

I assume it is a mega32 @ 8MHz.

 

I will email the CV project  and the HEX file produced by CV v3.15.

 

I am sure that your CV v2.05.3 will work exactly the same.

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Please tell me the CS, CD, WP for your SDcard.

I assume it is a mega32 @ 8MHz.

 

I will email the CV project  and the HEX file produced by CV v3.15.

 

I am sure that your CV v2.05.3 will work exactly the same.

 

David.

 

CS - pin no. 1

 

CD- pin no. 10

 

WP- pin no. 11

 

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok,   you are using PORTB.1 for CS

How can you have a pin #10 or pin#11 ?

 

David.
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sorry david. 

1- 

2- MISO

3- GND

4- SCK

5- VCC

6- MOSI

7- CS

8-

9- CD

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

Ok,   you are using PORTB.1 for CS

How can you have a pin #10 or pin#11 ?

 

David.
 

 

no PORTB.4 as CS

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sasireka wrote:

CS - pin no. 1

CD- pin no. 10

WP- pin no. 11

 

On your MPU not your SD card socket!

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Brian Fairchild wrote:

 

sasireka wrote:

 

CS - pin no. 1

CD- pin no. 10

WP- pin no. 11

 

 

 

 

On your MPU not your SD card socket!

 

 

yes it was in project ->configure->library->MMC/Sd card

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

Last Edited: Thu. Nov 20, 2014 - 01:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How can I set the <ff.h> port pins in the Project Configuration->Libraries  if you don't tell me how your AVR is connected.

My connections for my ATmega328P are:

SCK     PB5

MISO   PB4

MOSI   PB3

CS       PB2

CD       n/c

WP      n/c

 

I would expect to see a proper PORT pin for your CS (and possibly CD, WP)

Your connections for your ATmega32 are:

SCK     PB7

MISO   PB6

MOSI   PB5

CS       ?

CD       ?

WP      ?

 

 

 

David.

Last Edited: Thu. Nov 20, 2014 - 01:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

How can I set the <ff.h> port pins in the Project Configuration_>Libraries  if you don't tell me how your AVR is connected.

My connections for my ATmega328P are:

SCK     PB5

MISO   PB4

MOSI   PB3

CS       PB2

CD       n/c

WP      n/c

 

I would expect to see a proper PORT pin for your CS (and possibly CD, WP)

Your connections for my ATmega32 are:

SCK     PB7

MISO   PB6

MOSI   PB5

CS       ?

CD       ?

WP      ?

 

 

 

David.

 

 

SCK     PB7

MISO   PB6

MOSI   PB5

CS       PB4

CD       N/C  But in CV library PA0

WP   N/C     But in CV library PA1

-----------------------

Thanks & Regards,

Sasi

-----------------------

GO GREEN