EEPROM errors in ATTiny85

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am trying to make a dataloggre project. The data in the EEPROM is bieng written by the program, and then a programmer is connected to it and the EEPROM is read via the programmer. I do not know where the problem is, and it perplexes me.

When I fill the eeprom with a pattern, it always comes back with the first 255 bytes correct, but the second 255 bytes simply a duplicate of the first 225.

The code I am using is below.
It should compile with avr-gcc. I hope...

#define F_CPU 1000000UL
#include 
#include 

void delaynext(void);

uint16_t curaddr = 0;
uint16_t i = 0;

int main(void){
  DDRB = 0b00001000;
  PORTB = 0b00001000;
  _delay_ms(1000);
  PORTB = 0x00;

  ADMUX = 0b00100010;
  ADCSRA = 0b10001000;
  sei();

  while(1){

    ADCSRA |= 0b01000000;
    delaynext();


    }



}

ISR(ADC_vect){
  if(curaddr <= 511){

  PORTB = 0b00000000;
	


  EEAR = curaddr;


  EEDR = ADCH;
  EECR |= (1<<EEMPE);
  EECR |= (1<<EEPE);
  curaddr++;
  }

 else{
   PORTB = 0b00001000;
    while(1);
 }
}

void delaynext(void){
  for(i = 0; i < 337; i++){
    _delay_ms(1000);
  }
  _delay_ms(100);
}

Yes, i know my coding style is probably terrible...

If anyone has any sage advice, i would very much appreciate it.

Thanks in advance

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

Quote:
It should compile with avr-gcc. I hope...
I don't understand. Which compiler are you using?
You might want to read up on EEPROM write cycle timing, free running ADC conversions, the use of volatile and the down side of putting too much code in an ISR.
In short... read the Tutorials forum ;)
Oh, and my absolute favourite gripe... the use of magic numbers (without adequate comments). I assume you'd like me to download the appropriate datasheet for your chip and decode what...
 ADMUX = 0b00100010; 
 ADCSRA = 0b10001000;

means?

First post? Welcome to AVRFreaks :)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Quote:

EEAR = curaddr;


Who is that guy - EEAR? In a Tiny85 there are TWO EEPROM address registers - EEARL and EEARH, which hold the LSB and MSB of the address resp. You never use the EEARH, so you got two identical 256-byte copies then.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

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

If you are using avr-gcc (you are) then why on earth would you not use:

#include 

Manual here:

http://www.nongnu.org/avr-libc/u...

and there's a brilliant article in Tutorial Forum about using EEMEM.

  for(i = 0; i < 337; i++){
    _delay_ms(1000);
  }

That's 5.6 minutes - do you really that?

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

Wouldn't that get optimised out?
Edit: ignore me ;)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

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

Hello all!

 

I am using the e2prom on tiny45 as well. Sometimes it works, however, not all the times. The problem is that I am not sure WHY !

 

Tha idea is to store two values, when there is not supply. At that time the tiny holds two values, which are used by the tiny once the supply is back. 

 

I am working in Arduino IDE and programming works fine. Basically, I am using classical libraries #include <EEPROM.h> , namely its functions to read/write the value (see below for more information how this is done). However, I am wondering, if I am reading/writing or "removing power supply for testing", too quickly?

 

What would you say it is recommended time? Should I use some kind of delay before writing, etc?

 

Thank you in advance for your comments, ideas...

 

Best.

 

//the read procedure:

x = EEPROM.read(1);
y = EEPROM.read(2);

// I want to be sure that my values are not yet in e2prom... I could as well use the update function...

if (x == 0xFF || y == 0xFF) {
    x = 250;
    y = 1;
  }
  else {
    x = EEPROM.read(1);
    y = EEPROM.read(2);
  }

//and the write procedure :

// write to the eeprom at the address 1 the last x value
EEPROM.write(1, x);

// write to the eeprom at the address 2 the last y value
EEPROM.write(2, y);

 

 

Bravo!!!

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

Have you read the sections of the datasheet on EEPROM?

 

You must use the BOD to prevent write operations when the power supply voltage is too low for proper operation.

Hope that helps.

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

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

Thank you for your reply, suggestion!

 

Indeed, power supply can be the issue.

 

Best.

Bravo!!!

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

How do you know when the supply is "bad"? Is there still sufficient time while the supply is "bad but not off" to write to the EEPROM? Write to internal EEPROM takes quite a long time (milliseconds).

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Ok, it works. Somehow, I have a feeling the problem was in supply, namely I am using the BOD and it has no problems, at least for now :)

Bravo!!!

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

Thanks Jim, I guess the timing is ok, however, thank you for comment, best.

Bravo!!!