You are here

Problem of EEPROM in PSoC3 | Cypress Semiconductor

Problem of EEPROM in PSoC3

Summary: 11 Replies, Latest post by Bob Marlowe on 14 Jul 2013 10:25 AM PDT
Verified Answers: 3
Last post
Log in to post new comments.
user_119377051's picture
User
866 posts



Hi Everyone,

Now, I am trying EEPROM to read and write.

According to Knowledge base, EEPROM can read by two ways.

CY_GET_REG8
API
and Da style='font-size:11.0pt;color:#548DD4'>ta Pointer style='font-size:10.0pt;font-family:"Comic Sans MS";color:#A6A6A6'>

CY_GET_REG8
API
style='font-size:10.0pt;font-family:"Comic Sans MS";color:#A6A6A6'>was work
but,

Da style='font-size:11.0pt;color:#548DD4'>ta Pointer style='font-size:10.0pt;font-family:"Comic Sans MS";color:#A6A6A6'> was not
work.

What was wrong?

Let me know.

 

style='font-size:8.0pt;font-family:"Courier New";color:green'> href="/?id=4&rID=41079">http://www.cypress.com/?id=4&rID=41079

style='font-size:11.0pt;color:#548DD4'>1. Reading EEPROM using CY_GET_REG8 API

style='font-size:11.0pt;color:#548DD4'>   for (count = 0; count <
255;i++)

     EEPROM_Data[count] = CY_GET_REG8(CYDEV_EE_BASE +
count);

style='font-size:11.0pt;color:#548DD4'> 

style='font-size:11.0pt;color:#548DD4'>2. Reading EEPROM using data
Pointer     
                                

style='font-size:11.0pt;color:#548DD4'>A pointer can be defined for the EEPROM
address as follows:

style='font-size:11.0pt;color:#548DD4'>   #define EEPROM_ADDR
(unsigned char *) CYDEV_EE_BASE

   for (count = 0; count < 255; i++)

     EEPROM_Data[count] = EEPROM_ADDR[count];  

style='font-size:8.0pt;font-family:"Courier New";color:green'> 

style='font-size:8.0pt;font-family:"Courier New";color:green'>////////// style='font-size:10.0pt;font-family:"Courier New";color:fuchsia'>SAMPLE CODE style='font-size:8.0pt;font-family:"Courier New";color:green'>////////////////////////////////////////////////////////

style='font-size:8.0pt;font-family:"Courier New";color:blue'>#include style='font-size:8.0pt;font-family:"Courier New";color:black'> <Global.h>

style='font-size:8.0pt;font-family:"Courier New";color:blue'>#include style='font-size:8.0pt;font-family:"Courier New";color:black'> <Print.h>

style='font-size:8.0pt;font-family:"Courier New";color:green'>//////////////////////////////////////////////////////////////////////////////////

style='font-size:8.0pt;font-family:"Courier New";color:green'>//#define
CYDEV_EE_BASE 0x00008000u

style='font-size:8.0pt;font-family:"Courier New";color:green'>//#define
CYDEV_EE_SIZE 0x00000800u

style='font-size:8.0pt;font-family:"Courier New";color:blue'>#define style='font-size:8.0pt;font-family:"Courier New";color:black'> EPROM_ADDR
(unsigned char *) CYDEV_EE_BASE

style='font-size:8.0pt;font-family:"Courier New";color:green'>//////////////////////////////////////////////////////////////////////////////////

style='font-size:8.0pt;font-family:"Courier New";color:blue'>int style='font-size:8.0pt;font-family:"Courier New";color:black'> EPROM_Write(
byte rec[], int len )

style='font-size:8.0pt;font-family:"Courier New";color:black'>{ byte ss, *pp; style='font-size:8.0pt;font-family:"Courier New";color:blue'>int style='font-size:8.0pt;font-family:"Courier New";color:black'> i;

style='font-size:8.0pt;font-family:"Courier New";color:black'>  style='font-size:8.0pt;font-family:"Courier New";color:green'>//   QUERY
WRITE PERMISSION //

style='font-size:8.0pt;font-family:"Courier New";color:black'>       style='font-size:8.0pt;font-family:"Courier New";color:blue'>for style='font-size:8.0pt;font-family:"Courier New";color:black'>(i=0;;i++)

style='font-size:8.0pt;font-family:"Courier New";color:black'>       {      LCD_Printf(
0,0, "Query
Write=%d "
, i );

style='font-size:8.0pt;font-family:"Courier New";color:black'>              ss=
EEPROM_QueryWrite();

style='font-size:8.0pt;font-family:"Courier New";color:black'>              style='font-size:8.0pt;font-family:"Courier New";color:blue'>if style='font-size:8.0pt;font-family:"Courier New";color:black'>(
ss==CYRET_SUCCESS )

style='font-size:8.0pt;font-family:"Courier New";color:black'>              {      LCD_Printf(
1,0, "Query
OK %d "
, i );

style='font-size:8.0pt;font-family:"Courier New";color:black'>                     style='font-size:8.0pt;font-family:"Courier New";color:blue'>break style='font-size:8.0pt;font-family:"Courier New";color:black'>;       

style='font-size:8.0pt;font-family:"Courier New";color:black'>              }

style='font-size:8.0pt;font-family:"Courier New";color:black'>              style='font-size:8.0pt;font-family:"Courier New";color:blue'>else

style='font-size:8.0pt;font-family:"Courier New";color:black'>              {      LCD_Printf(
1,0, "Query
Err=%02x "
, ss );

style='font-size:8.0pt;font-family:"Courier New";color:black'>                     style='font-size:8.0pt;font-family:"Courier New";color:blue'>goto style='font-size:8.0pt;font-family:"Courier New";color:black'> p90;

style='font-size:8.0pt;font-family:"Courier New";color:black'>              }

style='font-size:8.0pt;font-family:"Courier New";color:black'>       }

style='font-size:8.0pt;font-family:"Courier New";color:green'>// WRITE TET DATA
(10 byte) //

style='font-size:8.0pt;font-family:"Courier New";color:black'>       style='font-size:8.0pt;font-family:"Courier New";color:blue'>for style='font-size:8.0pt;font-family:"Courier New";color:black'>(i=0;i<len;i++)

style='font-size:8.0pt;font-family:"Courier New";color:black'>       {      LCD_Printf(
0,0, "Write
index=%d "
, i );

style='font-size:8.0pt;font-family:"Courier New";color:black'>              ss=
EEPROM_ByteWrite( rec[i], 0, i );

style='font-size:8.0pt;font-family:"Courier New";color:black'>              style='font-size:8.0pt;font-family:"Courier New";color:blue'>if style='font-size:8.0pt;font-family:"Courier New";color:black'>(
ss!=CYRET_SUCCESS )

style='font-size:8.0pt;font-family:"Courier New";color:black'>              {      LCD_Printf(
1,0, "Write
Err=%02x "
, ss );

style='font-size:8.0pt;font-family:"Courier New";color:black'>                     style='font-size:8.0pt;font-family:"Courier New";color:blue'>goto style='font-size:8.0pt;font-family:"Courier New";color:black'> p90;           

style='font-size:8.0pt;font-family:"Courier New";color:black'>              }

style='font-size:8.0pt;font-family:"Courier New";color:black'>       }

style='font-size:8.0pt;font-family:"Courier New";color:green'>//     [1]
READ BYTE BY CY_GET_REG8  //

style='font-size:8.0pt;font-family:"Courier New";color:black'>       style='font-size:8.0pt;font-family:"Courier New";color:blue'>for style='font-size:8.0pt;font-family:"Courier New";color:black'>(i=0;i<len;i++)

style='font-size:8.0pt;font-family:"Courier New";color:black'>       {      ss=
CY_GET_REG8(CYDEV_EE_BASE + i);      style='font-size:8.0pt;font-family:"Courier New";color:green'>// GET BY
CY_GET_REG8  ß- THIS IS WORKING WELL

style='font-size:8.0pt;font-family:"Courier New";color:black'>              style='font-size:8.0pt;font-family:"Courier New";color:blue'>if style='font-size:8.0pt;font-family:"Courier New";color:black'>( rec[i]==ss )

style='font-size:8.0pt;font-family:"Courier New";color:black'>              {      LCD_Printf(
0,0, "Read
index=%d "
, i );

style='font-size:8.0pt;font-family:"Courier New";color:black'>              }

style='font-size:8.0pt;font-family:"Courier New";color:black'>              style='font-size:8.0pt;font-family:"Courier New";color:blue'>else

style='font-size:8.0pt;font-family:"Courier New";color:black'>              {      LCD_Printf(
0,0, "Read
Data=%02x "
, ss );

style='font-size:8.0pt;font-family:"Courier New";color:black'>                     LCD_Printf(
1,0, "Read
Error [1] "
);

style='font-size:8.0pt;font-family:"Courier New";color:black'>                     style='font-size:8.0pt;font-family:"Courier New";color:blue'>goto style='font-size:8.0pt;font-family:"Courier New";color:black'> p90;           

style='font-size:8.0pt;font-family:"Courier New";color:black'>              }

style='font-size:8.0pt;font-family:"Courier New";color:black'>       }

style='font-size:8.0pt;font-family:"Courier New";color:black'>       LCD_Print(
1,0, "Complete
[1] "
);

style='font-size:8.0pt;font-family:"Courier New";color:green'>//     [2]
READ BYTE BY Pointer //

style='font-size:8.0pt;font-family:"Courier New";color:black'>       pp=
(byte*)CYDEV_EE_BASE;

style='font-size:8.0pt;font-family:"Courier New";color:black'>       style='font-size:8.0pt;font-family:"Courier New";color:blue'>for style='font-size:8.0pt;font-family:"Courier New";color:black'>(i=0;i<len;i++)

style='font-size:8.0pt;font-family:"Courier New";color:black'>       {      ss=
pp[i];    // GET BY POINTER ß- THIS NOT WORK

style='font-size:8.0pt;font-family:"Courier New";color:black'>              style='font-size:8.0pt;font-family:"Courier New";color:blue'>if style='font-size:8.0pt;font-family:"Courier New";color:black'>( rec[i]==ss )

style='font-size:8.0pt;font-family:"Courier New";color:black'>              {      LCD_Printf(
0,0, "Read
index=%d "
, i );

style='font-size:8.0pt;font-family:"Courier New";color:black'>              }

style='font-size:8.0pt;font-family:"Courier New";color:black'>              style='font-size:8.0pt;font-family:"Courier New";color:blue'>else

style='font-size:8.0pt;font-family:"Courier New";color:black'>              {      LCD_Printf(
0,0, "Read
Data=%02x "
, ss );  ß- ERROR RESULT IS 0x80

style='font-size:8.0pt;font-family:"Courier New";color:black'>                     LCD_Printf(
1,0, "Read
Error [2] "
);

style='font-size:8.0pt;font-family:"Courier New";color:black'>                     style='font-size:8.0pt;font-family:"Courier New";color:blue'>goto style='font-size:8.0pt;font-family:"Courier New";color:black'> p90;           

style='font-size:8.0pt;font-family:"Courier New";color:black'>              }

style='font-size:8.0pt;font-family:"Courier New";color:black'>       }

style='font-size:8.0pt;font-family:"Courier New";color:black'>       LCD_Print(
1,0, "Verify
Complete "
);

style='font-size:8.0pt;font-family:"Courier New";color:black'>p90:

style='font-size:8.0pt;font-family:"Courier New";color:black'>       style='font-size:8.0pt;font-family:"Courier New";color:blue'>while style='font-size:8.0pt;font-family:"Courier New";color:black'>(1) GLed_ON;

style='font-size:8.0pt;font-family:"Courier New";color:black'>}

style='font-size:8.0pt;font-family:"Courier New";color:black'> 

style='font-size:8.0pt;font-family:"Courier New";color:green'>//////////////////////////////////////////////////////////////////////////////////

style='font-size:8.0pt;font-family:"Courier New";color:blue'>void style='font-size:8.0pt;font-family:"Courier New";color:black'> EPROM_TEST()

style='font-size:8.0pt;font-family:"Courier New";color:black'>{      EEPROM_Start();      style='font-size:8.0pt;font-family:"Courier New";color:green'>// Starts the
EEPROM. This has to be called before using write/erase APIs and reading the

style='font-size:8.0pt;font-family:"Courier New";color:black'>       EPROM_Write(
"THE
QUICK SILVER FOX JUMPS "
, 10 );

style='font-size:8.0pt;font-family:"Courier New";color:black'>       style='font-size:8.0pt;font-family:"Courier New";color:blue'>while style='font-size:8.0pt;font-family:"Courier New";color:black'>(1) GLed_ON;

style='font-size:8.0pt;font-family:"Courier New";color:black'>}

style='font-size:8.0pt;font-family:"Courier New";color:green'>/////////////////////////////////////////////////////////////////////////////////

style='font-size:8.0pt;font-family:"Courier New";color:green'> 

H L
user_460349's picture
User
1362 posts

 We used EEPOM for projects with PSoC3 and 5 without problem witht the 1st method. Should check if that works with the 2nd one next week.

user_119377051's picture
User
866 posts

Hi HL-san Do More Alligator,
I was not complain, I want to just informing.
I'm OK with method 1, I will make a Read routine for now.
Thank you.

user_1377889's picture
User
10803 posts

pp= (byte *)CYDEV_EE_BASE;

gives a warning concerning memory areas. Cypress's example for EEPROM access shows a bit different cast as

pp= (reg8 *)CYDEV_EE_BASE;

will give you the correct cast into the right memory-area.

 

Bob

 

user_1377889's picture
User
10803 posts

Will you please post (attach) complete projects, not all of your code is visible and it cannot be copied into Creator.
Bob (Small window, good start of a day...)

user_119377051's picture
User
866 posts

Ok but that is a small part of in big design. I could be simplified it. take a few hour, please wait.

user_119377051's picture
User
866 posts

Here it go !

user_1377889's picture
User
10803 posts

Sorry, but your project does not compile. But I could see:

 

s2= *(EEPROM_ADDR+i);

cannot run: The warning shows why: the memory area is wrong! This way has never been shown for a PSoC3 by Cypress.

The statement says: Take EEPROM_ADR as an integer and add i and use the result as a pointer into sram (which is wrong).

 

 

The 8051 has several different options to specify addressing of one of the memory areas. So when building your own access paths you must know at first in which memory-area EEProm is implemented (register-area) in PSoC3.

 

Bob

user_119377051's picture
User
866 posts

humm why?
Project bundle is copy also project properties, Compile option was different? Anyway, Comment out no.2

user_119377051's picture
User
866 posts

Man, I recall something!
The original system was using SD/emFile system and refer additional include and link-lib.
That could cause of error. It's already not use it but refer it, It's work on my environment but not on others. regards.

user_1377889's picture
User
10803 posts

Yeah, I found it meanwhile. It was a linker error, so no matter. The resulting warnings where a bunch of unreferenced vars, so nothing of interest still.

 

You should use number 2 as

 

s2  = *(reg8*)(CYDEV_EE_BASE + i);

which only uses type-casts, nothing needing additional CPU-instructions.

 

Bob

Log in to post new comments.