First, you write twice the amount of data your Writebuffer contain.
Second, you read data from a different buffer than you used to write your data.
There is an example project in PSOC designer using the EEPROM,
Thanks Eric and Danaa,
@EricS: I thought that int type takes 4 bytes of data but when I checked the Compiler Guide and found out that the int type in psoc only takes 2 bytes, so I was wrong about it. Besides I made a mistake at "if (bError == E2PROM_1_NOERROR)".
About a different buffer, do you mean the address of the E2PROM I have written to or something? I learned from the app note which Danaa provided, they did the same, I found nothing wrong here.
Now my code works well, thank you very much!
You are right my second comment is wrong. I read your code too quickly.
Hi, I have another question about E2PROM.
In the example CE57347, the E2PROM is initialized with the StoredValues at address 0x7FC0 and there is only "U" in the flashsecurity.txt so I assume the StoredValues is saved at that address.
Then the WriteData struct is written to the E2PROM so is the StoredValues overwritten or not?
'U' stands for unprotected, so when the EEProm address is 0x7FC0 it will be overwritten. Note that this may fail depending on the PSoC you use, there might be different EEProm start addresses.
Some additional hints:
I usually put into my EEProm-structure a datafield to count the number of writes, when the value is zero (0) I assume that it has not been written yet and I initialize it by writing to it the first time. Later in the life of the device I have the opportunity to change the target address within the EEProm array when there have been too many writes (could be limited to 10K or 100K).
Hi, it's me again. I have a problem with reading an array in E2PROM.
After writing an array to E2PROM, I want to read each value in the array by its index.
The process I've done in the prj is read it back to a readbuffer, each time I push a button the index will be up (down) by one value, reflected by the readbuffer.address and then the LCD will display the value at the indexed value.
However, when I push button, the address value just goes up (or down) and doesn't stop, even after I release the button. I thought that would be debounce problem but it isn't.
(I followed the debounce example here: http://www.ece.drexel.edu/courses/ECE-C304/notes/PSoCDesigner_PSoC1_SleepTimer.txt One thing that in my project, I have already used a timer interrupt so I don't want another interrupt.)
Please take a look at my attached project and give me some advice, thank you very much
testGPIO.Archive2.zip 266.4 K
Normally you want to bounce a button on and then follow it by bouncing it off,
then execute the button function. Ie. a press and release approach before
executing the function.
Buttons come in many kinds of quality, some bounce several hundred mS.
Attached some approaches to debouncing.
Debounce13.zip 6.8 MB
Consider replacing this code -
writebuffer.buffer = 1;
writebuffer.buffer = 2;
writebuffer.buffer = 3;
writebuffer.buffer = 4;
writebuffer.buffer = 5;
writebuffer.buffer = 6;
writebuffer.buffer = 7;
writebuffer.buffer = 8;
writebuffer.buffer = 9;
writebuffer.buffer = 10;
writebuffer.buffer = 11;
writebuffer.buffer = 12;
writebuffer.buffer = 13;
writebuffer.buffer = 14;
writebuffer.buffer = 15;
writebuffer.buffer = 16;
writebuffer.buffer = 17;
writebuffer.buffer = 18;
writebuffer.buffer = 19;
writebuffer.buffer = 20;
writebuffer.buffer = 21;
writebuffer.buffer = 22;
writebuffer.buffer = 23;
writebuffer.buffer = 24;
for (i = 0; i < 25; writebuffer.buffer[ i ] = i + 1, i++);
For delay functions consider -
You set the variable "action" when a button is pressed, but you do not reset the action to not doing anything when the button is released.
I would suggest you to wait at the end of the loop for the button to be released.
Thanks for your answers :)
As Bob says, I put everything in the while loop and it runs like forever so I take the "action" out and check it out of the loop, then I used the delay() functions instead of sleep timer decrement, now everything works fine :)
Again, thank you very much!!!
You are always welcome !