CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

write_eeprom and read_eeprom

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Picmicro_man



Joined: 01 Jan 2022
Posts: 13

View user's profile Send private message

write_eeprom and read_eeprom
PostPosted: Mon Jan 10, 2022 6:10 am     Reply with quote

Hi Guys
Simple query related to eeprom. I am unable to write and then read from eeprom. values displaying on LCD is 0.
Following is my code
Code:

#include <16F877A.h>
#device adc=8

#FUSES NOWDT,HS,PUT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT

#use delay(clock=20000000,RESTART_WDT)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include "Flexlcd.c"

#define ADDRESS 50

void main()
{
   lcd_init();
   
   write_eeprom(ADDRESS,2);
   delay_ms(10);
   
   printf(lcd_putc,"%d",read_eeprom(ADDRESS));
   
   while(TRUE)
   {
     
   }
}


Kindly guide me
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 8:13 am     Reply with quote

What compiler version?.
The code as posted works correctly for me. Displays 2.
Is it possible that you ran code before this, which has worn out the EEPROM?.
Can be done in less than 5 minutes by repeated writes.
Beware if you do enable the watchdog. Remember timeout by
default is just 18mSec, and can be as short as 7mSec. It'd keep resetting
and writing to the EEPROM, which would kill the chip very quickly.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 8:28 am     Reply with quote

hmm
'fuse' says NOwdt...
then 'delay' says 'restart_wdt'
has me wondering IF code to restart the WDT will be created and run ?

generally speaking though, WDT should never,ever be enabled until 100% of the program is correctly running and project is ready to be shipped to client.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 8:42 am     Reply with quote

I actually wondered if he originally tried with the WDT enabled, hence the
restart_wdt. Then since the eeprom write itself can take up to 8mSec, and
the lcd_init normally has a delay in it, could easily result in the code
rapidly and repeatedly writing to the EEPROM, till it is destroyed.... Sad
Picmicro_man



Joined: 01 Jan 2022
Posts: 13

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 11:21 pm     Reply with quote

Hi Guys

@Ttelmah @temtronic

Quote:

What compiler version?

The version I am working on is 4.124

Quote:

I actually wondered if he originally tried with the WDT enabled


No I didn't enabled the WDT. it is disable.

what I was tried before

Code:

#include <16F877A.h>
#device adc=8

#FUSES NOWDT,HS,PUT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT

#use delay(clock=20000000,RESTART_WDT)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include "Flexlcd.c"

#define ADDRESS 50

void main()
{
   lcd_init();
   
   write_eeprom(48,_BATTERY_VOLT);
   write_eeprom(ADDRESS,2);
   delay_ms(10);
   
   printf(lcd_putc,"%d",read_eeprom(ADDRESS));
   
   while(TRUE)
   {
     
   }
}


Is my controller EEPROM damaged?
Is there any way to check if EEPROM still alive?
Picmicro_man



Joined: 01 Jan 2022
Posts: 13

View user's profile Send private message

PostPosted: Mon Jan 10, 2022 11:27 pm     Reply with quote

another question.

If the EEPROM is damaged then all the part of EEPROM will be damage or only the address will be effected which we are writing?
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Jan 11, 2022 3:36 am     Reply with quote

Ouch.
Seriously, that is an ancient compiler. About 2007!...
At that age it could be a compiler fault. However, I don't remember there
being faults with the EEPROM at that time. However this thread had exactly
the same behaviour:
[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=50536&highlight=writeeeprom
[/url]

Big question, what is your power supply?. The EEPROM is one of the most
critical components on supply voltage. Enable BROWNOOUT. The EEPROM
write will fail if the voltage falls below 4v. The BROWNOUT fuse will make
the chip reset if this happens. The EEPROM write draws quite a spike on
the supply rail, and if your supply is not adequate the write could fail.

It would be the individual cell that gets destroyed. Unlike flash, where the
memory is 'page' based, the EEPROM works cell by cell.
Picmicro_man



Joined: 01 Jan 2022
Posts: 13

View user's profile Send private message

PostPosted: Tue Jan 11, 2022 6:59 am     Reply with quote

I am using adaptor of 12V 300mA (I have to check if this really gives 300mA or not) then 5v regulator. 100uF is on input and 10uF is on output of regulator.

Let me try BROWNOUT Fuses enabled and check the result.
Meanwhile anyother suggestion what i can do or check?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 11, 2022 7:24 am     Reply with quote

Try another address, other than 48 or 50. Maybe you just burnt out
those two addresses. Maybe the others are OK.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Jan 11, 2022 7:54 am     Reply with quote

and, have you got something like a 0.1uF ceramic capacitor right by the
actual processor supply pins, and all the supply pins connected?. Both
supply pins and both grounds are needed.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 11, 2022 8:20 am     Reply with quote

re:
Quote:
Seriously, that is an ancient compiler. About 2007!...

Thanks, now I really DO feel like a dinosaur !!!
I started with PCM v2.534......
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Tue Jan 11, 2022 12:26 pm     Reply with quote

I too started well before this, but individual faults were common on
older compiler versions.The late V4 versions like 4.141 were very good,
but versions like the one here, were often flakey.
I tended not to keep versions that had problems. Did not keep 4.124, which
suggests I had found it had issues...
Picmicro_man



Joined: 01 Jan 2022
Posts: 13

View user's profile Send private message

PostPosted: Wed Jan 19, 2022 4:11 am     Reply with quote

Hi Guys
I am still unable to read/write to/from EEPROM.

I added 0.1uF capacitors on the Vss and Vdd pins of microcontroller, also I added BROWNOUT fuse
following is the code

Code:

#include <16F877A.h>
#device adc=8

#FUSES NOWDT,HS,PUT,BROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT

#use delay(clock=20000000,RESTART_WDT)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

//#include "Flexlcd.c"

#define ADDRESS 61

void main()
{
   //lcd_init();
   delay_ms(100);
   write_eeprom(ADDRESS,2);
   delay_ms(100);
   
   //printf("HELLO");
   printf("value = %d",read_eeprom(ADDRESS));
   
   while(TRUE)
   {
     
   }
}
Picmicro_man



Joined: 01 Jan 2022
Posts: 13

View user's profile Send private message

PostPosted: Wed Jan 19, 2022 5:24 am     Reply with quote

i also tried to do this but same result

Code:

#include <16F877A.h>
#device adc=8

#FUSES HS,PUT,BROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT

#use delay(clock=20000000)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

//#include "Flexlcd.c"

#define ADDRESS 101

int variable_a = 0;

void main()
{
   
   printf("HELLO");
   
   while(TRUE)
   {
      if(!input(PIN_D2))
      {
         while(!input(PIN_D2)) delay_ms(1);
         
         delay_ms(100);
         write_eeprom(ADDRESS,2);
         delay_ms(100);
         variable_a = read_eeprom(ADDRESS);
         delay_ms(100);
         printf("value = %d",variable_a);
      }
   }
}


Is the whole EEPROM corrupt or am I missing something? Confused
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Jan 19, 2022 8:10 am     Reply with quote

Try something different:
Code:

#include <16F877A.h>
#device adc=8

#FUSES NOWDT,HS,PUT,NOBROWNOUT,NOLVP,NOCPD,NOWRT,NODEBUG,NOPROTECT

#use delay(clock=20000000,RESTART_WDT)
#use rs232(baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#ROM 0x2100 = {0xAA}

#include "Flexlcd.c"

#define ADDRESS 0

void main()
{
   lcd_init();
   
   delay_ms(10);
   
   printf(lcd_putc,"%d",read_eeprom(ADDRESS));
   
   while(TRUE)
   {
     
   }
}


This will make your programmer write 0xAA to the first byte of the
EEPROM. If this reads back correctly, then we know this cell at least
of the EEPROM does work correctly.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group