Writing to EEPROM token and send it to the UART

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

What do I need to save the "token-string" wsk to EEPROM or framework
and how to check whether you really saved?

It needs later send an wsk content on uart '
I write framework because it does not need to have these data permanently

 

<

void  analizuj_dane_id( char*buf )
{
	
	char* wsk;
	wsk=strtok(buf,"+");
	wsk = strtok(NULL,"\"");
       // wsk  need to save  ?//

 

>

==POLAND==

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

You are going to have to say which C compiler you are using for anyone to help.

 

If it happens to be avr-gcc then you need to #include <avr/eeprom.h> then use eeprom_update_block() to write the collection of bytes to the EEPROM.

 

(PS forgot to say that I deleted the duplicate post).

Last Edited: Wed. Aug 12, 2015 - 01:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use atmel studio
I write in C

1. Will could you show me a piece of code how to do it
2. Do I have to declare arrays

==POLAND==

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

Well buf[] holds a string of bytes on entry.

 

What strtok does is simply split the single string (n characters then 0) into a number of "sub-strings" that are x characters then 0, y characters then 0 and so on.

 

So say buf[] contains "hello+ goodbye:cruel:world" and you call:

wsk = strtok(buf, "+");

then the string will be "hello\000 goodbye:cruel:world" with wsk pointing to the h of hello. As such wsk points to a 5 character string that holds "hello". If you then used:

eeprom_update_block(wsk, 13, strlen(wsk));

then that would write the 5 bytes of "hello" to EEPROM location 13 onwards. If you now call:

wsk = strtok(NULL, ":");

then wsk will point to the space before "goodbye" and buf will now contain "hello\000 goodbye\000cruel:world". So wsk is the string " goodbye" and if you used:

eeprom_update_block(wsk, 27, strlen(wsk));

that would now write the 8 characters of " goodbye" to EEPROM location 27 onwards and so on...

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

there is progress :)

I did so

char * wsk;
wsk = strtok (buf, "*");
wsk = strtok (NULL, "*");
wsk = strtok (NULL, "*");
eeprom_write_block (wsk, eem_buf, strlen (WSK));
        

Saving is already running but

I'm looking for a way to protect the EEPROM

I have such a situation
Data is acquired using such a function

eeprom_write_block (wsk, eem_buf, strlen (WSK));

and now if you save for example. 123456789ABCD
I will read 123456789ABCD

next time I sign 987654321
a memory read

987654321ABCD

which are old from a previous record

how to get rid of them so that another record was no previous data if there is more than currently stored?

==POLAND==

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

how to get rid of them so that another record was no previous data if there is more than currently stored?

Isn't that pretty much basic programming, and not really EEPROM related?  It is up to you to define the contents of your storage area.  It is up to you to null-terminate it or not.

 

In this case, you build your buffer to the size of your storage area, and perhaps a few more for terminator and overflow, filled out with blanks or nulls or whatever you may decide.  Then you put the whole storage area width with "eeprom_update_block".

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hello,
I decided to slightly expand the program
but encountered an error, you can look at may be the reason
1. uart reads data from and writes them to the array
code

"<


void  analizuj_dane( char*buf ) 
{
	 
	
	 char* wsk;
	 wsk = strtok(buf,"\""); //odczytuje od małpy do zera 
	 wsk = strtok(NULL,"\""); //do zera

	 if(wsk) {
			
        eeprom_write_block(wsk, eem_buf, strlen(wsk) + 1);
		strcpy(globalna_tablica, wsk);
		 
			  }

and here it is OK :)

Now I would like to check if what's coming to uart is consistent with what is in the array

 


if (!strcmp(buf, globalna_tablica))
	  

 {
		
		zapal_led();	
		 
	 }

and I would like to compare what is in the buffer with what is in the table, unfortunately, I do not know how?
strcmp function as if she could not see the table
and now the question is whether strcmp can compare buffer array and the array must somehow convert?

 

Thx

==POLAND==