[TUT] [C] Getting SD/MMC card working painlessly with FatFS

Go To Last Post
354 posts / 0 new

Pages

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

Surely this was discussed earlier in the thread? Anyway most AVRs don't have an RTC so there's no way to give accurate timestamps to the files that are created. The only function ff.c actually calls is get_fattime() so in your own main.c (or some appropriate .c file) just use:

typedef struct {
	WORD	year;	/* 2000..2099 */
	BYTE	month;	/* 1..12 */
	BYTE	mday;	/* 1.. 31 */
	BYTE	wday;	/* 1..7 */
	BYTE	hour;	/* 0..23 */
	BYTE	min;	/* 0..59 */
	BYTE	sec;	/* 0..59 */
} RTC;

...

/*---------------------------------------------------------*/
/* User Provided Timer Function for FatFs module           */
/*---------------------------------------------------------*/
/* This is a real time clock service to be called from     */
/* FatFs module. Any valid time must be returned even if   */
/* the system does not support a real time clock.          */
/* This is not required in read-only configuration.        */
/*---------------------------------------------------------*/
/* Dummy time function as no rtc.c                         */
/*---------------------------------------------------------*/
DWORD get_fattime ()
{
	RTC rtc;


	/* Get local time */
//	rtc_gettime(&rtc);

	rtc.year = 2009;
	rtc.month = 1;
	rtc.mday = 1;
	rtc.wday = 1;
	rtc.hour = 12;
	rtc.min = 0;
	rtc.sec = 0;

	/* Pack date and time into a DWORD variable */
	return	  ((DWORD)(rtc.year - 1980) << 25)
			| ((DWORD)rtc.month << 21)
			| ((DWORD)rtc.mday << 16)
			| ((DWORD)rtc.hour << 11)
			| ((DWORD)rtc.min << 5)
			| ((DWORD)rtc.sec >> 1);
}

then remove any other references to "RTC". The above just arranges for all files to have a time stamp of "12:00:00 1/1/2009"

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

that's what I did... or didn't I ?

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

Read again. The function I'm talking about is get_fattime() not rtc_gettime() or rtc_settime(). Just leave rtc.c out of the list of files to build in the makefile and the only "Undefined reference" you'll see is to get_fattime(). So now just provide that dummy function I showed in one of the .c files that IS still being built.

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

ah, yes, ok. Will do, thank you.
Taking the risk to annoy you, but let's assume I have an RTC and I just give dummy values here as a start so that the rtc function returns something, where does that error actually come from ?

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

Which line is line 12 in rtc.h ? The error messages say you have errors on lines 12, 18 and 19.

(note however that sometimes you get an error on line N because of a fault on a prior line)

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

I edited the respective line numbers above in the code

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

Well that is VERY odd - line 12 does not have a '*' token as suggested in the error message? Could "RTC" have been defined as a macro prior to this somewhere?

(Oh, just a minute, you said Xmega - could their .h files have something called "RTC" by any chance?)

EDIT: just checked - guess what:

C:\WinAVR-20100110\avr\include\avr>grep "#define RTC " iox*
iox128a1.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox128a3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox128d3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox16a4.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox16d4.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox192a3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox192d3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox256a3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox256d3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox32a4.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox32d4.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox64a1.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox64a3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */
iox64d3.h:#define RTC    (*(RTC_t *) 0x0400)  /* Real-Time Counter */

So rename this typedef to FS_RTC rather than just RTC.

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

wow, great, that's it. Very good thinking, thank you very much once again !

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

But as a programmer you could have worked this out too. If line 12 was the point of the error (it was) then you have to ask yourself how was the C compiler seeing a "*" on that line. Using the -E option on the compiler is always a good idea to see what the code looks like with any macros expanded. But it was a fair bet that it was a macro. So then you ask yourself "have I defined a macro called RTC?", if not then it must have come from system header files. At which point you use your programmer's experience to guess where/why a macro called "RTC" might be defined.

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

I made an account just to thank you kubark42. I wasted one day trying to port the sample code from FATfs on my own. Then I got serious and wasted another half day before I found your TUT which fixed a lot of the other things I wasn't noticing. I was able to get it up and running in a few hours with your TUT. I originally had the card powered straight from my 3.3V but noticed your comment to connect it to an output on the AVR and this had me going in circles for a bit till I noticed another post said not to do that.

I am porting for ATMEGA1284p. WinAVR-20100110, FATfs sample code of October 14, 2010.

I wasn't able to use the mmc.c function for select() that you had because my version of the sample code required a return value. So I tried my best to merge your function with the original.

static
int select (void)	// 1:Successful, 0:Timeout //
{
	SD_CS_PORT &= ~(1<<SD_CS_PIN);      /* MMC CS = L */ 
	if (!wait_ready()) {
		DESELECT();
		return 0;
	}
	return 1;
}

Also, I believe chk_power(void) was renamed to power_status(void) in my version of the sample code. I left both in just in case, but the compiler let me know chk_power() was not used.

I also changed the rtc.c return data types to int instead of BOOL. Because the compiler was complaining.

Thanks again for your help and work!

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

Glad to hear it! Sometime in the future, when I need to use SD cards again, I'll update the tutorial to reflect Chen's new code. I wouldn't count on that anytime soon, though.

Thanks for publishing your modifications here. I'm sure they'll be put to good use by others.

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

Hi, I'm trying to use this lib into my mega644 to build a simple data logger, but I'm stuck with all this libs, codes and functions.

I've read the tutorial and made all the changes that kubark42 said to be done, but the code still don't compile. Here is the log:


avr-gcc  -mmcu=atmega644 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT main.o -MF dep/main.o.d  -c  ../main.c
avr-gcc  -mmcu=atmega644 -Wall -gdwarf-2 -Os -std=gnu99 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -MD -MP -MT rtc.o -MF dep/rtc.o.d  -c  ../rtc.c
../rtc.c:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rtc_gettime'
../rtc.c:35: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rtc_settime'
../rtc.c:52: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'rtc_init'

When double clicking the error, it points to these lines of the code:

.
.
BOOL rtc_gettime (RTC *rtc) 
.
.
BOOL rtc_settime (const RTC *rtc) 
.
.
BOOL rtc_init (void)
.
.

I can't figure out what problem is going on.

Another thing that i would like to ask:

- What are the .h and .c files needed to make a data logger ? There are many files like: mmc.c, diskio.h , ff.h, etc. Wich ones are the essentials to the FATFS lib run like the original one ?

Sorry for any mistake in my english.

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

You can drop rtc.c all together. The only calls made to rtc.c are from the example program in main.c. It calls to rtc_init(), rtc_settime() and rtc_gettime(). It does that in:

static
void IoInit ()
{
	PORTA = 0b11111111;	// Port A

	PORTB = 0b10110000; // Port B
	DDRB  = 0b11000000;

	PORTC = 0b11111111;	// Port C

	PORTD = 0b11111111; // Port D

	PORTE = 0b11110010; // Port E
	DDRE  = 0b10000010;

	PORTF = 0b11111111;	// Port F

	PORTG = 0b11111; 	// Port G

	uart_init();		// Initialize UART driver

/*
	OCR1A = 51;			// Timer1: LCD bias generator (OC1B)
	OCR1B = 51;
	TCCR1A = 0b00010000;
	TCCR1B = 0b00001010;
*/
	OCR2 = 90-1;		// Timer2: 100Hz interval (OC2)
	TCCR2 = 0b00001101;

	TIMSK = 0b10000000;	// Enable TC2.oc, interrupt

	rtc_init();			// Initialize RTC

Just remove this call.

		case 't' :	/* t [     ] */
			if (xatoi(&ptr, &p1)) {
				rtc.year = (WORD)p1;
				xatoi(&ptr, &p1); rtc.month = (BYTE)p1;
				xatoi(&ptr, &p1); rtc.mday = (BYTE)p1;
				xatoi(&ptr, &p1); rtc.hour = (BYTE)p1;
				xatoi(&ptr, &p1); rtc.min = (BYTE)p1;
				if (!xatoi(&ptr, &p1)) break;
				rtc.sec = (BYTE)p1;
				rtc_settime(&rtc);
			}
			rtc_gettime(&rtc);
			xprintf(PSTR("#u/#u/#u #02u:#02u:#02u\n"), rtc.year, rtc.month, rtc.mday, rtc.hour, rtc.min, rtc.sec);
			break;

Just remove this entire "case 't'". Finally:

/*---------------------------------------------------------*/
/* User Provided Timer Function for FatFs module           */
/*---------------------------------------------------------*/
/* This is a real time clock service to be called from     */
/* FatFs module. Any valid time must be returned even if   */
/* the system does not support a real time clock.          */
/* This is not required in read-only configuration.        */


DWORD get_fattime ()
{
	RTC rtc;


	/* Get local time */
	rtc_gettime(&rtc);

	/* Pack date and time into a DWORD variable */
	return	  ((DWORD)(rtc.year - 1980) << 25)
			| ((DWORD)rtc.month << 21)
			| ((DWORD)rtc.mday << 16)
			| ((DWORD)rtc.hour << 11)
			| ((DWORD)rtc.min << 5)
			| ((DWORD)rtc.sec >> 1);
}

This is the only one of any importance. The value returned from this function is used to time stamp the files when they are created/written. What I've done is:

typedef struct {
	WORD	year;	/* 2000..2099 */
	BYTE	month;	/* 1..12 */
	BYTE	mday;	/* 1.. 31 */
	BYTE	wday;	/* 1..7 */
	BYTE	hour;	/* 0..23 */
	BYTE	min;	/* 0..59 */
	BYTE	sec;	/* 0..59 */
} RTC;

DWORD get_fattime ()
{
	RTC rtc;


	/* Get local time */
//	rtc_gettime(&rtc);

	rtc.year = 2009;
	rtc.month = 1;
	rtc.mday = 1;
	rtc.wday = 1;
	rtc.hour = 12;
	rtc.min = 0;
	rtc.sec = 0;

	/* Pack date and time into a DWORD variable */
	return	  ((DWORD)(rtc.year - 1980) << 25)
			| ((DWORD)rtc.month << 21)
			| ((DWORD)rtc.mday << 16)
			| ((DWORD)rtc.hour << 11)
			| ((DWORD)rtc.min << 5)
			| ((DWORD)rtc.sec >> 1);
}

That just means all files are stamped "12:00 1-1-2009".

Either provide your own RTC functionality and arrange for the result to be given in response to get_fattime() or do what I've done and all files will have a fixed date/time.

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

Have someone edited this code for atmega8 ?

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

You won't get FatFs to fit in a mega8 bit petitFs will - the smallest build is something like just 4K

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

Damn, so i probably went for nothing through this tut ;/ Can petitFS create a file? I have read that it just can't ;/

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

Suggest you read:

http://elm-chan.org/fsw/ff/00ind...

Rather than believing every bit of tittle-tattle you read on the Internet.

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

So to do this working at atmega8 from attiny85 i just need to change the makefile and those lines in main.c ?

	PORTB = 0b101011;	/* u z H L H u */
	DDRB =  0b001110;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

so even when i compile for attiny the sample of pfFS has errors:

../usi.S: Assembler messages:
../usi.S:19: Error: constant value required
../usi.S:19: Error: number must be positive and less than 64
../usi.S:64: Error: constant value required
../usi.S:64: Error: number must be positive and less than 64
../usi.S:71: Error: constant value required
../usi.S:71: Error: number must be positive and less than 64
make: *** [usi.o] Error 1
Build failed with 1 errors and 0 warnings...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Thank you a lot, that's what I needed

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

As I think I told you via PM. John Samperi and I have modified the PetitFs code to work on Megas that don't have USI but that do have real UARTs and SPIs. Search out the threads and download the code.

BTW this is not an appropriate thread to continue the diagnose of your PetitFs porting problems - take it to "AVR Forum".

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

Many thanks to everyone that has contributed to this TUT.
I now have FatFS running on a 644p and can:
1) Initialize the disk
2) List directories
3) Open and close a file, with a valid time stamp
But, writing to a file seems to have me stumped. I assume the following process is about right, so correct me please:
a) Open a file for write
b) Write to the “buff” until you have 512, or more bytes
c) Write the first 512 to a sector, using “disk_write”
d) When done, flush the buffer
e) Close the file
My hang-up is that the disk_write function wants to know the “sector”. That’s where I’m stuck. Can anyone help me across this knowledge gap?

Tom

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

The sector it's asking for is the memory location of the 512-byte page that you want to write. I haven't used FatFS since I wrote the tutorial, and subsequently rewrote many of the functions to minimize the size and maximize write performance for a very specific task, so I no longer recall exactly how with FatFS you get the sector location after you open the file.

However, I'm certain it will be instantly obvious if you spend a couple minutes looking in the right places. Try backtracking using the example code to see where it gets the sector from.

In any case, this is important, as if you write to the beginning of the file, you're overwriting it, whereas if you're writing to the end you're appending to it. I'm certain you can appreciate the nuance!

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

I successfully followed this tutorial in April 2009 using same ucontroller as the OP, I did have just some issues with pull ups, but not a big deal as I posted.

Now, based on that the code reported for other members seemed to be just below 32 K . I've attemped to get the FaTFs with an ATMEGA328.

I've downloaded the latest version from elm-chang R08b April 2011 and found out same name changes that clash with the tutorial posted at the beginning of the thread.

For example the chk_power() function in old version is now called power_status(). I am not sure if there are other things.

The problem is that after it compiled with zero errors this is the result:

AVR Memory Usage
----------------
Device: atmega328p

Program:   47490 bytes (144.9% Full)
(.text + .data + .bootloader)

Data:       2467 bytes (120.5% Full)
(.data + .bss + .noinit)

I've attempted to use the _FS_MINIMIZE parameter but it seems to be there is a bug on the automatization directives as plenty of errors shows up from the calling of the functions supposed to be suppressed in case of using 1,2 or 3, so it only compiles OK with this parameter set to ZERO. I attempted to remove the terminal functions related , but errors still come from other terminal functions not supposed to be suppressed...

So, my question is if anyone know whether this last version may have more functions or what I am doing wrong?

I have attached the complete project. It has the modified rtc.c , however it uses the original uart.c and uart.h from Chang.

Based on the answers if this is not possible to run on an ATMEGA328, then I will look around your modified Petit_FS
posted before as well as the Roland Riegel that is for an ATMEGA168.

Last but not least, the application I am aiming to is to play WAV files from SD card using the PWM. So I just need to read . However,as a side effect I wanted to see if I could fit the whole nine yards on the 328.

Thanks in advance for any advice.

Jose

Attachment(s): 

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

I've successfully run the Petit FS from Cliff / JS on the Atmega328


Device: atmega328p

Program:    8810 bytes (26.9% Full)
(.text + .data + .bootloader)

Data:        139 bytes (6.8% Full)
(.data + .bss + .noinit)

Biiiig difference. Not even a 328 is needed.

Please disregard previous crazy post. The only modifications done on the code posted was on the SPI pins as the TX RX on the m164 are the same as on m/168/328.

I like the UART implementation in asm. The only question I have for this post is about the comment from JS

//The comms is duplex,38.4kbps, but there is no echo and local 
// echo needs to be enabled on the terminal.

What does this mean ? no echo as well as "local echo" ?

Thanks a million in advance,

Jose v.

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

In the terminal mode you will not see what you are typing unless you enable echo mode in your terminal progam. If you are using Hyperterminal

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Js,
Thanks, I used Bray's terminal and it has a separated tx rx input display.

But, forgive my ignorance on this, how a Hyperterminal feature is related to the USART firmware?

Does this means that the atmega built-in USART automatically echoes on TX what is coming on RX ?and that was no available in Chang's implementation ?

I was playing with single line USART some time ago and I disabled RX when transmitting to avoid self receiving , but I did not verified the opposite.

Thanks for any input. Regards,

Jose v.

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

What happened when you typed the message above? Did you see what you were typing?

If you type a line into petitfs you would NOT see anything on a terminal that has a single screen instead of a split send and receive screen, well pretty much like the screen you are reading now. This is the reason for local echo.

Local echo will let you see what you type so that, if you make a mistake and you see it you can edit the line.

I don't remember ever having used a split display terminal program, I always use character echo in my programs that needs input ie the USART receives a char from the keyboard, puts it into a buffer and then sends it back to the terminal.

In rare cases where this doesn't happen in a program (not written by me) I use local echo.

Do you have the ability to have a single screen with Brays instead of 2? If so use it and you will see what I mean.

This is as conprehensive an explanation as I can provide. :)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

John,

Thanks a lot I have the correct picture now as I also write the USART routines like in Petit that do the same thing just plain send and plain receive but I always use Bray's terminal ( attached) because you can send and receive in Hexadecimal and you can make some macros that are convenient.
[url]
http://hw-server.com/software/te...
[/url]
This is why I've got in trouble most of the time with the Hyperterminal. :oops:

Thanks again,

Jose v.]

Attachment(s): 

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

if someone can share with me any code that can be used with an atmega32 I will be very happy after losing already a week(24 hour a day) trying to have something working on a sd card.

I have read the tutorials, this thread also. I see how the people has succed but I am UNABLE. I started with an atmega16 and changed to atmega32 thinking that atmega16 was insufficient. now I see the code is still to big.

also it seems that the files that were used for this tutorial already changed.

I got this with the elmchan full module. how the... people is getting 10kb codes...

AVR Memory Usage
		----------------
		Device: atmega32
		Program:   56266 bytes (171.7% Full)
		(.text + .data + .bootloader)
		Data:       2835 bytes (138.4% Full)
		(.data + .bss + .noinit)

thankyou.

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

Quote:
how the... people is getting 10kb codes...
Most likely by using PetitFs (just over 8K) rather than the full FatFs (at least 48K)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

I try to do with the petitfs code but there is always something missing that make me include files from the full module... and I end up will errors and more errors. may be the full version code is ready to run but this small one...I compile the file and I get thousand of errors. If someone has succed with a code smaller than 32kb please share it with me. I am suffering.:-(

what I am doing wrong??

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

Quote:

but there is always something missing that make me include files from the full module..

Tell us more about "something missing"?!?

For me pfsample\avr builds right after download:

E:\pfsample\avr[i386_vc]>make
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=attiny85 -DF_CPU=8000000   -c -o main.o main.c
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=attiny85 -DF_CPU=8000000   -c -o pff.o pff.c
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=attiny85 -DF_CPU=8000000   -c -o mmc.o mmc.c
avr-gcc -c -mmcu=attiny85 -I. -x assembler-with-cpp -Wa,-adhlns=suart.lst,-gstabs -DF_CPU=8000000 suart.S -o suart.o
avr-gcc -c -mmcu=attiny85 -I. -x assembler-with-cpp -Wa,-adhlns=xitoa.lst,-gstabs -DF_CPU=8000000 xitoa.S -o xitoa.o
avr-gcc -c -mmcu=attiny85 -I. -x assembler-with-cpp -Wa,-adhlns=usi.lst,-gstabs -DF_CPU=8000000 usi.S -o usi.o
avr-gcc -gdwarf-2 -Wall -Os -mcall-prologues -mmcu=attiny85 -DF_CPU=8000000 -Wl,-Map,pfftest.map -o pfftest.elf main.o p
ff.o mmc.o suart.o xitoa.o usi.o
avr-objdump -h -S pfftest.elf > pfftest.lst
avr-objcopy -j .text -j .data -O ihex pfftest.elf pfftest.hex
avr-size -C --mcu=attiny85 pfftest.elf
AVR Memory Usage
----------------
Device: attiny85

Program:    8066 bytes (98.5% Full)
(.text + .data + .bootloader)

Data:        139 bytes (27.1% Full)
(.data + .bss + .noinit)

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

Post the first error that you see.

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

I downloaded the petit module examples file. I choise AVR folder and I try to compile it.I know I can get some error regarding with the pinout but...

134 errors

undefined reference to 'xmit'
'xfunc_out'
'xputs'
'crvr'
'xmit_spi'.....

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

What were you compiling it with? I have WinAVR20100110 installed which is what runs when I typed "make" above.

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

I am using avrstudio5. I have done all kind of small projects with this software. All successfull till this.
BTW, I am a bit confused with the make file. Do I need to handle son makefile? I didn't in the previous projects.

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

Quote:

I am using avrstudio5.

The you kind of deserve everything that you get ;-)

Obviously if you DO want to use AS5 and don't want to use it's option to "use external makefile" (I assume it has one like AS4?) then at least start by adding all the .c files from the pfsample/avr to a project set to build for tiny85 and see what errors remain. Once you can get it working for the tiny85 it's designed to build for THEN consider what needs to be done to port it to some other model of AVR.

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

Quote:
If someone has succed with a code smaller than 32kb please share it with me
But if you had looked at the links I have posted above you would also find this
http://www.avrfreaks.net/index.p...
and also this from above
http://www.avrfreaks.net/index.p...

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

thank you guys, I run out of time. the gf hijacks me for holidays, so no more chips.

thank you again.

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

Hi,

Im trying to use fatfs on an mp3 player project I am doing.

I am having trouble with the f_readdir function.

Im trying to find a way of finding a file with the MP3 extension.

However I can't seem to even open a file from the FILINFO fname[], and I am unsure if I am doing it right...

The following code is my attempt

			
             FILINFO fno;
    			DIR dir;
    			int i;
    			char *fn;

			if(f_opendir(&dir, "")!=FR_OK)
			{
				PORTB.OUT=0xFF;
			}



			if(f_readdir(&dir, &fno)!=FR_OK)
			{
				PORTB.OUT=0xFF;
			}
			
			if(f_readdir(&dir, &fno)!=FR_OK)
			{
				PORTB.OUT=0xFF;
			}

			if(f_readdir(&dir, &fno)!=FR_OK)
			{
				PORTB.OUT=0xFF;
			}

			if(f_readdir(&dir, &fno)!=FR_OK)
			{
				PORTB.OUT=0xFF;
			}

			fn = fno.fname;

			if(f_open(&mp3, "fn", FA_READ)!=FR_OK) 
			{
				if(f_open(&mp3, "default.mp3", FA_READ)!=FR_OK) 
				{
				PORTB.OUT = 0xFF;
				}
			}

I repeat the readdir 4 times because from what I saw on the fatfs website it looked like it returned:
.
..
firstfile
secoundfile

or similar format, so I readdir 4 times to hopefully get past any invalid fname[]s

I realise running it 4 times is not ideal, but I like to keep things as basic as I can till its actually working, as im not very adept at coding.

There are multiple mp3 files in the root of the sdcard, and I can play them if I put the file name in the code.

In the code above the default.mp3 plays, so when there is an error when I try playing the current fname[].

I also tried sending the fname[] to an lcd, however it just displayed blanks(im not sure if I have the timing 100% correct for the lcd yet either).

So if anyone can explain what I am doing wrong or offer a solution, I would appreciate that. I am not looking for anyone to write code for me or anything, I just need a little help.

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

Quote:

I also tried sending the fname[] to an lcd, however it just displayed blanks(im not sure if I have the timing 100% correct for the lcd yet either).

You definitely need some kind of "debug channel" - either verify that the LCD can be trusted or consider a UART link to a PC.

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

Oh man this is embarrassing, feel like a total retard now

if(f_open(&mp3, "fn", FA_READ)!=FR_OK) 

had quotes around fn...

Got the LCD working properly too, pretty new to this stuff. Realized I need to use sprintf to convert it to a char array...

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

Retrosexual, instead of FOUR readdir(), just get the file_name and check the extension for "mp3", and if it is continue, else loop up and do ONE readdir() / file from the start.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

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

I get the initialization appearing in the serial terminal, but after that the commands just echo themselves?
FatFs module test monitor for AVR
LFN Disabled, Code page: 1
>di 0
di 0fi 0
fi 0fl
fl
Any ideas why?

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

Quote:

Any ideas why?

Ad printf()s to the control loop and find out. That's what debugging is all about!

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

I have a tiny question about Makefile_mmc -- something I sort of fixed already, but I'd like to know incase I broke something. The makefile included with the FATFS library for the AVR had the following line:

CSRC    = main.c uart.c ff.c mmc.c rtc.c sound.c cc932_avr.c

I understand why all the files are included except sound.c. What is sound.c? I don't have it in the AVR folder and so my project wouldn't compile. I ditched the makefile and I'm now using AVR Studio 4's makefile. I included the usual files for the project [uart.c, ff.c, mmc.c, rtc.c and cc932_avr.c] and after some changes (like the one's described in this TUT) the project compiles fine.

I can't upload it to my AVR as my board is being assembled so I thought I'd ask here. It's a small question so I didn't feel the need for an entirely new thread. If a MOD feels I'm wrong regarding this, please let me know and I'll create a new thread.

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

Quote:

and cc932_avr.c

You seriously don't want that! Edit the ffconf.h and change the code page to be plain ascii. You don't want 10K of Kanji Japanese built into your program.

The sound.c things sounds(sic!) like an error. There is no sound.c in the ffsample.zip\avr directory.

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

Quote:
The sound.c things sounds(sic!) like an error
sound.c was not in the previous makefile for R0.8a but snack in in R0.09 even though the file is not provided.

I think there is a project for a MP3 player around which MAY use that file.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Pages