Author Topic: Need to store data between pwr down and next pwr up?  (Read 6007 times)

barnacleBudd

  • Newbie
  • *
  • Posts: 21
Need to store data between pwr down and next pwr up?
« on: February 16, 2013, 10:59:25 pm »
Here is how to do it. Reading and writing to your EEPROM.
http://mypetdigispark.blogspot.com
 

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Need to store data between pwr down and next pwr up?
« Reply #1 on: February 17, 2013, 04:09:56 am »
Quote
I was able to learn that an Arduino had 512 bytes of EEPROM reserved for storage. It's like a tiny hard drive. I am not sure how much we get on our Digispark, but I know I  only need one byte to store the high score because the high score will never be as high as 255, the largest value you can store in a byte.


The digispark also has 512 bytes of eeprom  ;D

barnacleBudd

  • Newbie
  • *
  • Posts: 21
Re: Need to store data between pwr down and next pwr up?
« Reply #2 on: February 17, 2013, 02:23:46 pm »
Thanks, Bluebie. I was hoping someone would let us know.

Mark

  • Full Member
  • ***
  • Posts: 196
Re: Need to store data between pwr down and next pwr up?
« Reply #3 on: February 23, 2013, 12:54:22 am »

Some newcomers may not be aware that the EEPROM isn't cleared when uploading a new sketch.

This means if you want to clear it, you'll need to write 0 to each location.
The eeprom_clear sketch in examples does this very nicely.


Mark


semicolo

  • Full Member
  • ***
  • Posts: 137
Re: Need to store data between pwr down and next pwr up?
« Reply #4 on: February 23, 2013, 10:14:59 am »
Would be nice to have an option in the arduino ide to do it since avrdude can write the eeprom.

Bluebie

  • Sr. Member
  • ****
  • Posts: 486
Re: Need to store data between pwr down and next pwr up?
« Reply #5 on: February 24, 2013, 02:52:41 pm »
Digisparks aren't programmed via avrdude, and the bootloader doesn't support eeprom read or write - this is part of how the digispark manages to have a 2kb usb bootloader, where the previous smallest was about 2.8kb.


There is no USB bootloader for attiny85 with avrdude compatibility because the tiny85 chip cannot be compatible with USB if it needs to do flash erasing or writing as the chip freezes up for several milliseconds during those operations, crashing the USB connection. This is why the digispark uses a dedicated upload tool "micronucleus" which carefully manages the usb traffic of the host computer to keep it from doing any queries to the device while it's dead, so the computer doesn't realise there's anything wrong. During the 'connecting' stage the bootloader communicates to the host how much time it would like the host to wait after each write or erase operation before resuming USB traffic. It still bugs out and crashes half way through sometimes, but we are getting better at avoiding that and also automatically recovering from those errors in future versions. Leet hax! ;D


Aside from the USB crashing issue, the reason USBaspLoader cannot be 2kb on tiny85 chips but it can on mega328 is that the tiny85 doesn't have hardware bootloader support, so there are more leet hax in there to implement one purely in software which takes up extra memory.

semicolo

  • Full Member
  • ***
  • Posts: 137
Re: Need to store data between pwr down and next pwr up?
« Reply #6 on: February 24, 2013, 05:49:53 pm »
I think I'm going to shut up and learn. I'm too used to JTAG, ISP and the like.

Mark

  • Full Member
  • ***
  • Posts: 196
Re: Need to store data between pwr down and next pwr up?
« Reply #7 on: February 24, 2013, 06:00:59 pm »
Nah keep asking.
It saves me putting my foot into my mouth.....

Mark