Using Eeprom of Atmega 32

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

Hii!
I want to Store and Read value from eeprom of Atmega32.I saw the tutorials Dean posted,but I am not able to apply.

I have to store the value of coordinate ex-(2,3) or (4,1) and than have to call it back in my program in later part.

Please provide help with code.

Thank you!

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

And are you working with assembler, BASIC, FORTH, C (which flavour)?

What does your code look like?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Ohh!Sorry
I am working in C(using Atmel studio 6).
I am making a Grid follower robot with some more features.As in it has to go to a Specified node sense the square cells colour around that node(for white or black patches)store number of white patches around that node and also has to store that node X coordinate.

Ex-if the initial node was (2,1).Bot would move to that coordinate,sense that coordinate surrounding squares and save number of white patches as Y1 and that coordinate X coordinate value as X1.Suppose it senses number of white patches as 3 than (X1,Y1)=(2,3).Now my bot has to do this for one more Node and get (X2,Y2) in similar fashion.

Than my bot has to move to (X1,Y1) and (X2,Y2).

Hope this information was useful.I know it's a bit confusing thou.

Please do tell me if you need any more information.

Thank you!

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

Quote:
I am working in C(using Atmel studio 6).
Then you should not have any problems using the built in AS6 toolchain's EEPROM functions.

What do you mean by

Quote:
I saw the tutorials Dean posted,but I am not able to apply.

Doesn't the code compile? Doesn't work as expected?

If you write a small program where you simply write something to EEPROM and then read it back the we can see what you mean, we have no idea on what problems you are having with just "I am not able to apply". :-)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

abhicoolhead wrote:
Please provide help with code.

Hello! What's your problem? :)
I recommend you to take a look at datasheet. There are simple examples of routines to write and read a bytes in/from EEPROM.

What's range of your coordinates? It may take more than a byte for a coordinate. For example, if your X is changing from 1 to 1000 you must take two bytes for one coordinate. So, you must take four bytes for a node (x, y).

You use C, so you can declare following structure

typedef struct
{
uint8_t x; // it may be uint16_t
uint8_t y; // it may be uint16_t as well, or they may be             int16_t
} TNode;

// Declaration of node's coordinate
TNode node1;
TNode node2;

// Using
node1.x = 50;

a = node2.y; // 'a' is declared somewhere else

To write and read them you should use these functions

void writeNode( TNode node, uint16_t addr )
{
// some code you write by yourself
}

TNode readNode( uint16_t addr )
{
// some code you write by yourself
}

The 'tutorial' I have written isn't related directly to your problem. You have to solve writing/reading first. But this information may be useful for you in future.

Good luck!

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

js wrote:
Quote:
I am working in C(using Atmel studio 6).
Then you should not have any problems using the built in AS6 toolchain's EEPROM functions.

What do you mean by

Quote:
I saw the tutorials Dean posted,but I am not able to apply.

Doesn't the code compile? Doesn't work as expected?

If you write a small program where you simply write something to EEPROM and then read it back the we can see what you mean, we have no idea on what problems you are having with just "I am not able to apply". :-)

Actually I am having problem in writing code itself.(havn't reached till compiling part).I am not able to understand how to write code for storing two numbers of a coordinate ex-(2,3) and than calling these numbers as coordinate in later part of my program,so that my bot moves to these coordinates.

I am taking variable in my program to follow grid as:

i=2,j=2,i_dest=3,j_dest=2

Where at the beginning my i=0 and j=0 while above two values are my two NODES coordinate.Now when it reaches (2,2),I want to store this node x coordinate(i.e value of i) and number of white patches around this node as my y coordinate of new node(as I explained earlier),so my new coordinate for bot to move is (2,1) supposing there were 1 white patch around the node (2,2)...similarly I want to so this for my other node specified at first i'e (3,2).

Please give an example taking any of these nodes and writing it's program to read and store those coordinates value in eeprom.

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

haker_fox wrote:

What's range of your coordinates?

To write and read them you should use these functions

void writeNode( TNode node, uint16_t addr )
{
// some code you write by yourself
}

TNode readNode( uint16_t addr )
{
// some code you write by yourself
}

Thank you! :D It was really helpfull,infact I guess this is the whole program for that.My coordinate range isn't too high it's from 0-9.I have few doubts thou:

1)void writeNode( TNode node, uint16_t addr )
In this I guess I have to just specify.
a)TNode node1 or node 2
b)uint16_t addr=uint16_t x or y

isn't? :?

I am cofused by "addr".

2)Can I take another structure in similar fashion for my other node too? :?

3)What did you exactly mean by "some code you write by yourself "?

Also you been of great help.So I am asking you for one more help here itseelf.

As you specified "a" in you code (a = node2.y; // 'a' is declared somewhere else).I am specifying it like following please check and give your valuable feed back if it's correct or not:

s1=read_adc(0)   /*I have put four sensors facing out on 
                   the four corners of my robot.On state 
                    shows black patch found.
                     (used digital sensor)*/
s2=read_adc(1)
s3=read_adc(2)
s4=read_adc(3)

if(s1==0&&s2==0&&s3==0&&s4==0)
{
a=4;                  //value of a=4 shows 4 white patch
}
else if(s1==1&&s2==0&&s3==0&&s4==0)
{
a=3;               //value of a=3 shows 3 white patch    
}
else if(s1==1&&s2==1&&s3==0&&s4==0)
{
a=2;                //2 white patch found
}
else if(s1==1&&s2==1&&s3==1&&s4==0)
{
a=1;                //1 white patch
else
{
a=0;                  //no patch found
}

Same can be done to find black patches.
Please correct me if I am wrong any where.

Thank you for all your help. :D

Last Edited: Wed. Dec 26, 2012 - 12:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Get a good book on C. You need to understand the difference between & and &&.

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

Kartman wrote:
Get a good book on C. You need to understand the difference between & and &&.
And the difference between = and ==.

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

snigelen wrote:
Kartman wrote:
Get a good book on C. You need to understand the difference between & and &&.
And the difference between = and ==.

Sorry about that.Please do tell me if there is any other mistakes. :oops:

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

I would guess the function 'read_adc' does more than just read the adc. Why not give it a more meaningful name?

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

Kartman wrote:
Why not give it a more meaningful name?

Like?:D

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

Quote:
Actually I am having problem in writing code itself
I'm really sorry but then you should NOT attempt to write code for something complicated as "so that my bot moves to these coordinates".

Maybe start with something a lot SIMPLER.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:

Maybe start with something a lot SIMPLER.

I am not having problem in writing code so that my bot moves to coordinate,but I am having problem in writing code for storing and reading value in eeprom for my next destination coordinate.

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

Maybe I don't understand your problem :-)

Writing and reading to/from the EEPROM is pretty simple, just a matter of adding

#include	

to your code.

Then use for example

uint8_t EEMEM Timeout_m, Timeout_s;
.
.
eeprom_write_byte((uint8_t*)(& Timeout_m),mm);	//Write Minutes to EEPROM
.
.
.
mm = eeprom_read_byte (& Timeout_m);

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

It seems to me like you are trying to figure out what data structures to use to store the data? The eeprom is sort of a serialized bunch of data, basically a big array or fifo. So if it were me, I'd design a convenient way to store the data in memory then serialize it out to eeprom as needed.

Am I understanding your question?

It should work - bot-thoughts.com

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

js wrote:
Maybe I don't understand your problem :-)

Thank you you got it this time...:D
but if you could see above,comments made by "haker_fox".I guess he gave me the proper answer to my queries,but I had few doubts in that,which I have mentioned in the second comment after his.

It would be great if you could answer those.

Also thank you for your reply.:D

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

shimniok wrote:
So if it were me, I'd design a convenient way to store the data in memory then serialize it out to eeprom as needed.

Am I understanding your question?

Yes you are.:D
Could you please see my question in above post and tell a way to do that?with example codes?

Thank you..:D