avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] int to EEPROM


From: Ron Kreymborg
Subject: RE: [avr-gcc-list] int to EEPROM
Date: Sun, 9 Sep 2001 00:57:46 +1000

You could but you don't have to. If you have a look at eeprom.s you will see
that the code checks the EEWE bit and loops there until it is zero.

Ron

-------------------------------------------
Ron Kreymborg
Jennaron Research
Melbourne, Australia

> -----Original Message-----
> From: Gines Martinez [mailto:address@hidden
> Sent: Saturday, 8 September 2001 11:25 PM
> To: Ron Kreymborg; address@hidden
> Subject: Re: [avr-gcc-list] int to EEPROM
>
>
> One question:
> Don't you have to call after each eeprom_wb() to the function
> eeprom_is_ready() ?
> ie:
>
> void eWriteFloat(float *numPtr, void *addr)
> {
>     BYTE *ptr, *num;
>
>     ptr = (BYTE*)addr;
>     num = (BYTE*)numPtr;
>     eeprom_wb((int)ptr++, *num++);
>     while(!eeprom_is_ready());
>     eeprom_wb((int)ptr++, *num++);
>     while(!eeprom_is_ready());
>     eeprom_wb((int)ptr++, *num++);
>     while(!eeprom_is_ready());
>     eeprom_wb((int)ptr++, *num++);
>     while(!eeprom_is_ready());
> }
>
> ----- Original Message -----
> From: "Ron Kreymborg" <address@hidden>
> To: <address@hidden>
> Sent: Thursday, August 09, 2001 2:24 PM
> Subject: RE: [avr-gcc-list] int to EEPROM
>
>
> > >
> > > Saw nice example of storing float to eeprom, could some one
> please post
> > > the same kind of example of storing & retreiving and int type variable
> > > from/to eeprom ?
> > >
> > > With regards,
> > >
> > > Pasi
> > >
> >
> > Well here is one possible organisation. For the int case where (for
> example)
> > the variable in eeprom you are concerned with is called
> "TheVariable ". It
> > is declared in the usual way:
> >
> > #define EEPROM __attribute__((section(".eeprom")))
> >
> > int TheVariable EEPROM = 0;
> >
> > You extract it with:
> >
> >     int x = eInt(&TheVariable);
> >
> > and you can write it back with:
> >
> >     eWriteInt(&x, &TheVariable);
> >
> > Don't forget the ampersand! Here is a complete set...
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > float eFloat(float *ptr)
> > {
> >     float a;
> >
> >     eeprom_read_block(&a, (int)ptr, 4);
> >     return a;
> > }
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > long eLong(long *ptr)
> > {
> >     long a;
> >
> >     eeprom_read_block(&a, (int)ptr, 4);
> >     return a;
> > }
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > int eInt(int *ptr)
> > {
> >     int a;
> >
> >     eeprom_read_block(&a, (int)ptr, 2);
> >     return a;
> > }
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > BYTE eByte(BYTE *ptr)
> > {
> >     BYTE a;
> >
> >     eeprom_read_block(&a, (int)ptr, 1);
> >     return a;
> > }
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > void eWriteFloat(float *numPtr, void *addr)
> > {
> >     BYTE *ptr, *num;
> >
> >     ptr = (BYTE*)addr;
> >     num = (BYTE*)numPtr;
> >     eeprom_wb((int)ptr++, *num++);
> >     eeprom_wb((int)ptr++, *num++);
> >     eeprom_wb((int)ptr++, *num++);
> >     eeprom_wb((int)ptr++, *num++);
> > }
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > void eWriteLong(long *numPtr, void *addr)
> > {
> >     BYTE *ptr, *num;
> >
> >     ptr = (BYTE*)addr;
> >     num = (BYTE*)numPtr;
> >     eeprom_wb((int)ptr++, *num++);
> >     eeprom_wb((int)ptr++, *num++);
> >     eeprom_wb((int)ptr++, *num++);
> >     eeprom_wb((int)ptr++, *num++);
> > }
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > void eWriteInt(int *numPtr, void *addr)
> > {
> >     BYTE *ptr, *num;
> >
> >     ptr = (BYTE*)addr;
> >     num = (BYTE*)numPtr;
> >     eeprom_wb((int)ptr++, *num++);
> >     eeprom_wb((int)ptr++, *num++);
> > }
> >
> >
> //----------------------------------------------------------------
> ----------
> > ---
> > void eWriteByte(BYTE *numPtr, void *addr)
> > {
> >     BYTE *ptr, *num;
> >
> >     ptr = (BYTE*)addr;
> >     num = (BYTE*)numPtr;
> >     eeprom_wb((int)ptr++, *num++);
> > }
> >
> >
> > -------------------------------------------
> > Ron Kreymborg
> > Jennaron Research
> > Melbourne, Australia
> >
> >
> > _______________________________________________
> > avr-gcc-list mailing list
> > address@hidden
> > http://avr.jpk.co.nz/mailman/listinfo/avr-gcc-list
>
>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]