Hi,
I am not able to read the data which i have written earlier to the EEPROM location.bit erros are occuring
Can any one give the sample code for the same.
Th device is R32C/153 it has on chip EEPROM emulation data flash
The sample code which i had tried is given below the compiler used is IAR
The for loop has been added for adding delay in this case only the read function is succeds.
Another case is that the status flag is not geeting set when we try to write the same location for next time without calling eEep_Erase()
uint8 EEpromdata1;
uint8 EEpromdata2;
void EepInit();
void Eep_Read();
void Eep_Write();
void Eep_Erase();
void main(void)
{
EEpromdata1=0;
EEpromdata2=0;
EepInit();
#if 1
Eep_Erase();
while(eerr_e2fs0==1)
{
Eep_Erase();
}
#endif
Eep_Write();
while(werr_e2fs0==1)
{
Eep_Write();
}
Eep_Read();
}
void EepInit()
{
e2fc=0;
prc41 = 1;
e2fm = 0x05;
e2fi = 0x0050;
}
void Eep_Erase()
{
uint8 count;
e2fi = 0x0050;
#if 1
for(count =0; count < 50;count++)
{
}
#endif
e2fa = 0x00062160;
#if 1
for(count =0; count < 50;count++)
{
}
#endif
e2fi = 0x0020;
#if 1
for(count =0; count < 50;count++)
{
}
#endif
e2fi = 0x00D0;
#if 1
for(count =0; count < 50;count++)
{
}
#endif
while(rdy_e2fs0 == 0)
{
}
}
void Eep_Write()
{
uint8 count;
e2fi = 0x0050;
for(count =0; count < 50;count++)
{
}
e2fa = 0x00062160;
for(count =0; count < 50;count++)
{
}
e2fi = 0x0040;
for(count =0; count < 50;count++)
{
}
e2fd = 0xB0F4;
while(rdy_e2fs0 == 0)
{
}
}
void Eep_Read()
{
uint8 count;
e2fi = 0x0050;
for(count =0; count < 50;count++)
{
}
e2fa = 0x00062160;
for(count =0; count < 50;count++)
{
}
e2fi = 0x00F3;
for(count =0; count < 50;count++)
{
}
while(rdy_e2fs0 == 0)
{
}
EEpromdata1=*((uint8 *)0x044FEC);
EEpromdata2=*((uint8 *)0x044FED);
}
I got it :>>>>>>>>>>>>>>>>>>>>>>>
#include "ior32c153.h"
#include "Std_Types.h"
uint16 EEpromdata1;
uint16 EEpromdata;
uint8 intflg;
#define INT_MODE
#define ENABLE_IRQ {asm(" FSET I");}
void EepInit();
void Eep_Read(uint32 Addr);
void Eep_Write(uint32 Addr,uint16 value);
void Eep_Erase(uint32 Addr);
#ifdef INT_MODE
#pragma vector = E2MOD
__interrupt void EepInterrupt_ISR(void)
{
intflg = 1;
}
#endif
int main( void )
{
EEpromdata1=0;
EEpromdata=0;
EepInit();
/********** 1st Operation Seq ******************/
Eep_Erase(0x062023);
while(eerr_e2fs0==1)
{
Eep_Erase(0x062023);
}
Eep_Write(0x62023,0x1567);
while(werr_e2fs0==1)
{
Eep_Write(0x62023,0x1567);
}
Eep_Read(0x062023);
/********** 2nd Operation Seq ******************/
Eep_Erase(0x062025);
while(eerr_e2fs0==1)
{
Eep_Erase(0x062025);
}
Eep_Write(0x062025,0x3421);
while(werr_e2fs0==1)
{
Eep_Write(0x062025,0x3421);
}
Eep_Read(0x062025);
/********** 3rd Operation Seq ******************/
Eep_Erase(0x062027);
while(eerr_e2fs0==1)
{
Eep_Erase(0x062027);
}
Eep_Write(0x062027,0x1234);
while(werr_e2fs0==1)
{
Eep_Write(0x062027,0x1234);
}
Eep_Read(0x062027);
Eep_Read(0x062025);
return 0;
}
void EepInit()
{
#ifdef INT_MODE
ENABLE_IRQ;
e2fic = 1;
#endif
e2fc=1;
prc41 = prc41|1;
e2fm = 0x05;
prc41 = prc41&0xFE;
}
void Eep_Erase(uint32 Addr)
{
intflg=0;
e2fi = 0x0050;
e2fa = Addr;
e2fi = 0x0020;
e2fi = 0x00D0;
while(intflg == 0);
}
void Eep_Write(uint32 Addr,uint16 val)
{
intflg=0;
e2fi = 0x0050;
e2fa = Addr;
e2fi = 0x0040;
e2fd = val;
while(intflg == 0);
}
void Eep_Read(uint32 Addr)
{
intflg=0;
e2fi = 0x0050;
e2fa = Addr;
e2fi = 0x00F3;
while(intflg == 0);
EEpromdata1=*((uint16 *)0x044FEC);
}
Sorry, but your code has one big and one small problem.
The big problem is that you try to erase byte wise. R32C can NOT erase byte wise, but it can erase only complete blocks of 32 byte.So erase instructions to 0x62023, 0x62025 or 0x62027 all erase the same block 1. Try reading the data of 0x62023 after you erase 0x62025. It should be gone.
The small problem is that erase should be done using the highest even address in one block (see erase flow chart in the manual). You erase using odd addresses inside a block. I know that also in the past for flash erase worked by writing to more or less any address inside a block. But it would be better to comply to the manual and erase a block using its highest even address (i.e. address 0x6201E for the first 32 byte block, 0x6203E for the second block).
©2003–2009 Renesas Technology Corp. All rights reserved. Using Our Website | Privacy
Contact us