Author Topic: about atmaga 328 EEPROM  (Read 1475 times)

0 Members and 1 Guest are viewing this topic.

Offline ranganatennakoonTopic starter

  • Contributor
  • Posts: 37
  • Country: lk
about atmaga 328 EEPROM
« on: April 29, 2020, 01:10:09 pm »
how to store 10 bit numbers in atmega328 eeprom :-//
 

Offline newbrain

  • Super Contributor
  • ***
  • Posts: 1719
  • Country: se
Re: about atmaga 328 EEPROM
« Reply #1 on: April 29, 2020, 01:16:15 pm »
As little-endian 16 bit numbers.  >:D
Nandemo wa shiranai wa yo, shitteru koto dake.
 
The following users thanked this post: ranganatennakoon

Offline ranganatennakoonTopic starter

  • Contributor
  • Posts: 37
  • Country: lk
Re: about atmaga 328 EEPROM
« Reply #2 on: April 29, 2020, 04:00:13 pm »
atmega328 has a  (bytes)
1024 eeprom it means can store 255 numbers X 1024
but i want to store 0 to 500 value of data. how can i do this ? :scared:
« Last Edit: April 30, 2020, 09:43:56 am by ranganatennakoon »
 

Offline senso

  • Frequent Contributor
  • **
  • Posts: 951
  • Country: pt
    • My AVR tutorials
Re: about atmaga 328 EEPROM
« Reply #3 on: April 29, 2020, 04:02:39 pm »
Use the already working eeprom read/write/update functions and just write an int16 or uint16, as easy as it can be.

I think it was eeprom_read_word/eeprom_write_word.
 
The following users thanked this post: I wanted a rude username, ranganatennakoon

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3367
  • Country: nl
Re: about atmaga 328 EEPROM
« Reply #4 on: April 29, 2020, 08:18:30 pm »
Last time I remember using the AVR Eeprom I just dumped all variables in a structure and used something like:
> Eeprom_update_block( Struct, sizeof( Struct));

 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2495
  • Country: gb
Re: about atmaga 328 EEPROM
« Reply #5 on: April 29, 2020, 08:33:49 pm »
1 KB not 1 Kb?

Is this data changing?  If not... you can always put it in flash (PROGMEM)?
 
The following users thanked this post: ranganatennakoon

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: about atmaga 328 EEPROM
« Reply #6 on: April 29, 2020, 09:38:37 pm »
atmega328 has a 1 kb eeprom it means can store 255 numbers X 1024 but i want to store 0 to 500 value of data. how can i do this ? :scared:

Well if you want to be more specific, it holds 8 bit values which can represent numbers 0-255. A number with a value of 500 will be represented in 16 bits, aka two 8 bit values side by side.

So you just have to break the number into it's two 8 bit values and store them individually.
 
The following users thanked this post: ranganatennakoon

Offline ranganatennakoonTopic starter

  • Contributor
  • Posts: 37
  • Country: lk
Re: about atmaga 328 EEPROM
« Reply #7 on: April 30, 2020, 09:41:13 am »

[/quote]

Well if you want to be more specific, it holds 8 bit values which can represent numbers 0-255. A number with a value of 500 will be represented in 16 bits, aka two 8 bit values side by side. So you just have to break the number into it's two 8 bit values and store them individually.
[/quote]

TomS_ can i give me an example cord ? thank you !
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: about atmaga 328 EEPROM
« Reply #8 on: April 30, 2020, 09:25:11 pm »
TomS_ can i give me an example cord ? thank you !

Well, the idea was to give you some information which you could then use to discover the answer yourself so that you can learn.

If you know that value X needs to be stored in 16 bits, and you need to be able to store that value into an EEPROM which only handles 8 bits at a time, and assuming there is no existing way to do this, then you need to discover how to split a 16 bit value into two 8 bit values.

I'll give you some hints: one of them is using logical shifts. The other could be pointers and casting (but I would start with shifts).
 

Offline sleemanj

  • Super Contributor
  • ***
  • Posts: 3025
  • Country: nz
  • Professional tightwad.
    • The electronics hobby components I sell.
Re: about atmaga 328 EEPROM
« Reply #9 on: April 30, 2020, 09:47:30 pm »
You want to use the eeprom_write_word function

https://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html

Provide address in the eeprom you want to store at, and the 16 bit number to store.  The inverse is of course eeprom_read_word

Code: [Select]
  uint16_t val = 500;
  uint16_t addr = 0;
  eeprom_write_word((uint16_t *)addr, val);

 ... time passes ...

  val = eeprom_read_word((uint16_t *)addr);

Remember that the address is a byte address in flash, if you store a 16 bit word at 0, don't then go storing something at 1

 
~~~
EEVBlog Members - get yourself 10% discount off all my electronic components for sale just use the Buy Direct links and use Coupon Code "eevblog" during checkout.  Shipping from New Zealand, international orders welcome :-)
 
The following users thanked this post: ranganatennakoon

Offline jackthomson43

  • Contributor
  • Posts: 38
  • Country: us
Re: about atmaga 328 EEPROM
« Reply #10 on: May 01, 2020, 12:29:38 pm »
Atmega328 has 1024 bytes of EEPROM thus you can save data of 256 x 1024, you should check Atmega328 Datasheet to get the details.
« Last Edit: March 09, 2021, 11:38:26 pm by jackthomson43 »
 
The following users thanked this post: ranganatennakoon

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: about atmaga 328 EEPROM
« Reply #11 on: May 01, 2020, 12:39:42 pm »
SD card is best, can save any amount of data.  :-DD

Well it can only store as much data as the size of the card.   You'd use a significant amount of the program memory in in a 328 with functions to use an SD card, plus the cost of the card and socket, the extra pins used on the micro, higher power consumption etc..

The on board EEPROM is extremely easy to use and perfect for the small amounts of NV data that you typically need on small micros.
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11654
  • Country: my
  • reassessing directives...
Re: about atmaga 328 EEPROM
« Reply #12 on: May 01, 2020, 01:22:21 pm »
atmega328 has a  (bytes)
1024 eeprom it means can store 255 numbers X 1024
but i want to store 0 to 500 value of data. how can i do this ? :scared:
you can store 10bits value in 16bits value if you want as others mentioned, its a lot hassle and trouble free and more readable. and hence can store 512 of your numbers in the eeprom in normal int16 array. but if you insist on 10bits shoulder to shoulder or running out of space, you can store 816 10bits numbers using packed bit-fields in struct (or union), but you have to make sure the struct is 8bits aligned, since we cant get around that machine architecture limitation/specification and cant do anything that we wish...

http://icarus.cs.weber.edu/~dab/cs1410/textbook/5.Structures/unions.html
https://stackoverflow.com/questions/17494853/using-bit-fields-for-avr-ports

eg:
Code: [Select]
struct my_data {
unsigned val1 : 10;
unsigned val2 : 10;
unsigned val3 : 10;
unsigned val4 : 10;
}; // 5 bytes data size, 4x 10bits values.
since the field-bit is more than 8 bits, you may do your homework, it may work it may not. or maybe you have to device fancier trick around that bit-field and union feature. ymmv.

SD card? yes basically unlimited storage size afa most mcu firmwares are concerned, but i suspect it will be much slower than eeprom access, and needs few other external components. ymmv.
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 
The following users thanked this post: ranganatennakoon

Offline jackthomson43

  • Contributor
  • Posts: 38
  • Country: us
Re: about atmaga 328 EEPROM
« Reply #13 on: May 02, 2020, 06:48:21 am »
ATmega328 EEPROM is of 255 bits, so saving 10 bit won't be an issue.  |O You should check Atmega328 Pinout first.
« Last Edit: March 07, 2021, 12:28:19 am by jackthomson43 »
 
The following users thanked this post: ranganatennakoon

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3240
  • Country: gb
Re: about atmaga 328 EEPROM
« Reply #14 on: May 02, 2020, 06:31:21 pm »
ATmega328 EEPROM is of 255 bits, so saving 10 bit won't be an issue.  |O

The ATmega328 EEPROM is 1024*8 bits.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf