Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
mzeu
PostPosted: Oct 04, 2010 - 03:47 PM
Hangaround


Joined: Mar 27, 2006
Posts: 153


Hello, I'm also trying to integrate this into my Xmega project and I'm running into following problem when I try to compile I get this :

Code:
../FF/rtc.h:12: error: expected ')' before '*' token
../FF/rtc.h:12: error: expected ')' before numeric constant
../FF/rtc.h:18: error: expected declaration specifiers or '...' before '(' token
../FF/rtc.h:19: error: expected ')' before numeric constant


and I don't know why. Has anyone else seen this before or can explain when and why this kind of errors occur ?

the rtc.h looks like this :
Code:

#include "integer.h"

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
line 12 }RTC;

//int iic_write (BYTE, UINT, UINT, const void*);   // Write to IIC device
//int iic_read (BYTE, UINT, UINT, void*);      // Read from IIC device

//int rtc_init (void);                  // Initialize RTC
line 18 int rtc_gettime (RTC*);               // Get time
line 19 int rtc_settime (const RTC*);            // Set time


and rtc.c like this :
Code:

#include <avr/io.h>
#include <string.h>
#include "rtc.h"


int rtc_gettime (RTC *rtc)
{
/*
   BYTE buf[8];


   if (!iic_read(0xD0, 0, 7, buf)) return 0;

   rtc->sec = (buf[0] & 0x0F) + ((buf[0] >> 4) & 7) * 10;
   rtc->min = (buf[1] & 0x0F) + (buf[1] >> 4) * 10;
   rtc->hour = (buf[2] & 0x0F) + ((buf[2] >> 4) & 3) * 10;
   rtc->wday = (buf[2] & 0x07);
   rtc->mday = (buf[4] & 0x0F) + ((buf[4] >> 4) & 3) * 10;
   rtc->month = (buf[5] & 0x0F) + ((buf[5] >> 4) & 1) * 10;
   rtc->year = 2000 + (buf[6] & 0x0F) + (buf[6] >> 4) * 10;
*/
    rtc->sec = 1;
   rtc->min = 2;
   rtc->hour = 3;
   rtc->wday = 4;
   rtc->mday = 5;
   rtc->month = 6;
   rtc->year = 2007;
   return 1;
}




int rtc_settime (const RTC *rtc)
{

   BYTE buf[8];


   buf[0] = rtc->sec / 10 * 16 + rtc->sec % 10;
   buf[1] = rtc->min / 10 * 16 + rtc->min % 10;
   buf[2] = rtc->hour / 10 * 16 + rtc->hour % 10;
   buf[3] = rtc->wday & 7;
   buf[4] = rtc->mday / 10 * 16 + rtc->mday % 10;
   buf[5] = rtc->month / 10 * 16 + rtc->month % 10;
   buf[6] = (rtc->year - 2000) / 10 * 16 + (rtc->year - 2000) % 10;

//   return iic_write(0xD0, 0, 7, buf);
   return TRUE;
}


Thank you very much.
Mat


Last edited by mzeu on Oct 05, 2010 - 08:00 AM; edited 1 time in total
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Oct 04, 2010 - 04:02 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

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:
Code:
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"

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
mzeu
PostPosted: Oct 04, 2010 - 04:08 PM
Hangaround


Joined: Mar 27, 2006
Posts: 153


that's what I did... or didn't I ?
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Oct 04, 2010 - 04:14 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

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.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
mzeu
PostPosted: Oct 04, 2010 - 06:09 PM
Hangaround


Joined: Mar 27, 2006
Posts: 153


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 ?
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Oct 04, 2010 - 07:24 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

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)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
mzeu
PostPosted: Oct 05, 2010 - 08:02 AM
Hangaround


Joined: Mar 27, 2006
Posts: 153


I edited the respective line numbers above in the code
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Oct 05, 2010 - 10:05 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

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:
Code:
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.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
mzeu
PostPosted: Oct 05, 2010 - 10:18 AM
Hangaround


Joined: Mar 27, 2006
Posts: 153


wow, great, that's it. Very good thinking, thank you very much once again !
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Oct 05, 2010 - 10:52 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

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.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
theseapalm
PostPosted: Nov 20, 2010 - 01:13 AM
Newbie


Joined: Nov 20, 2010
Posts: 1


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.

Code:

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!
 
 View user's profile Send private message  
Reply with quote Back to top
kubark42
PostPosted: Nov 21, 2010 - 10:23 PM
Hangaround


Joined: Jun 04, 2008
Posts: 254


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.
 
 View user's profile Send private message  
Reply with quote Back to top
netogodoy
PostPosted: Dec 23, 2010 - 07:46 PM
Newbie


Joined: Nov 09, 2008
Posts: 8
Location: Brazil

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:

Code:


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:

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.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Dec 23, 2010 - 07:59 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

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:
Code:
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.
Code:
      case 't' :   /* t [<year> <mon> <mday> <hour> <min> <sec>] */
         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:
Code:
/*---------------------------------------------------------*/
/* 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:
Code:
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.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Modeon
PostPosted: Dec 29, 2010 - 09:14 AM
Newbie


Joined: Nov 28, 2010
Posts: 7


Have someone edited this code for atmega8 ?
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Dec 29, 2010 - 11:36 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

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

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Modeon
PostPosted: Dec 30, 2010 - 01:04 AM
Newbie


Joined: Nov 28, 2010
Posts: 7


Damn, so i probably went for nothing through this tut ;/ Can petitFS create a file? I have read that it just can't ;/
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Dec 31, 2010 - 11:43 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62371
Location: (using avr-gcc in) Finchingfield, Essex, England

Suggest you read:

http://elm-chan.org/fsw/ff/00index_p.html

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

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Modeon
PostPosted: Jan 02, 2011 - 11:07 PM
Newbie


Joined: Nov 28, 2010
Posts: 7


So to do this working at atmega8 from attiny85 i just need to change the makefile and those lines in main.c ?
Code:
   PORTB = 0b101011;   /* u z H L H u */
   DDRB =  0b001110;
 
 View user's profile Send private message  
Reply with quote Back to top
Modeon
PostPosted: Jan 02, 2011 - 11:28 PM
Newbie


Joined: Nov 28, 2010
Posts: 7


so even when i compile for attiny the sample of pfFS has errors:
Code:
../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...
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits