cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

ivkac_4155501
New Contributor

Dear Community,

How do I exactly use the EEPROM module?

When I search the internet I find some tutorials which use functions like Eeprom_WriteByte; Emprom_ReadByte but in my build there are no such functions at all (the tutorial use 5lp prototyping kit controller, like me though).

What I have is the function Eeprom_Write.

But I do not really understand what this function expect me to put in.

This is what the datasheet says:

Em_EEPROM_Write (const uint8 srcBuf[], const uint8 eepromPtr[], uint16/uint32 byteCount)

Is the srcBuff[] a pointer to the information I want to save in the Eeprom?

Is the eepromPtr[] a pointer to the location of the EEProm?

If this is true how can I define the location of EEProm or how can determinate this location?

How can I read the stored Data.

Sorry if I did unstand it completely wrong, but the datasheet looks pretty cryptic to me.

0 Likes
1 Solution
GeonaP_26
Moderator
Moderator

PSoC 5LP has two different components; the EEPROM component and the Emulated EEPROM component. The EEPROM component provides set of APIs to erase and write to non-volatile on-chip EEPROM memory. Whereas, the Emulated EEPROM component emulates an EEPROM device in the PSoC device flash memory. EEPROM_WriteByte and Em_EEPROM_Write are write API interfaces to EEPROM and Emulated EEPROM components respectively.

Please refer to PSoC Creator provided code examples to understand component usage. Please go to File > Code Example for EEPROM_Design and PSoC_EmEEPROM_PSoC5 code examples.

If you are using Em_EEPROM is your application, use EmEEPROM_Read (uint32 addr, void * eepromData, uint32 size) to read size units of data from logical address addr and write to array pointer eepromData. Please refer to Em_EEPROM component datasheet for more details on API.

View solution in original post

0 Likes
4 Replies
odissey1
Honored Contributor II

ivankatzer,

If you want to simply save/read some parameters into EEPROM, use example project and custom coomponent that does just that:

myEEPROM: component to save/recall application settings in EEPROM between power offs

For details of EEPROM access look into the myEEPROM component's API code.

/odissey1

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

Let me add my sample, too 😉

Schematic

001-schematic.JPG

main.c

===========================

#include "project.h"

#include "stdio.h"

char str[128] ; /* print buffer */

void print(char *str)

{

    UART_PutString(str) ;

}

void init_hardware(void)

{

    CyGlobalIntEnable; /* Enable global interrupts. */

    UART_Start() ;

  

    EEPROM_Start() ;

    EEPROM_UpdateTemperature() ;

}

void splash(void)

{

    sprintf(str, "EEPROM Test (%s %s)\n", __DATE__, __TIME__) ;

    print(str) ;

}

int main(void)

{

    unsigned int i ;

    int erase_after_test = 0 ; // if you want to clear EEPROM after test, set this to 1

  

    init_hardware() ;

  

    splash() ;

  

    sprintf(str, "EEPROM Size = %d\n", CY_EEPROM_SIZE) ;

    print(str) ;

  

    print("EEPROM Current Contents\n") ;

    for (i = 0 ; i < 0x100 ; i++ ) { /* show only the first 256 bytes */

        sprintf(str, "%02X ", EEPROM_ReadByte(i)) ;

        print(str) ;

        if (((i + 1) % 0x10) == 0) {

            print("\n") ;

        }

    }

    print("\n") ;

  

    print("Updating data ... \n") ;

    if (EEPROM_ReadByte(0) == 0) {

        for (i = 0 ; i < 0x100 ; i++ ) {

            EEPROM_WriteByte(0xFF - i, i ) ;

        }

    } else {

        for (i = 0 ; i < 0x100 ; i++ ) {

            EEPROM_WriteByte(i, i) ;

        }

    }

    print("Done\n") ;

  

    print("EEPROM Updated Contents\n") ;

    for (i = 0 ; i < 0x100 ; i++ ) { /* show only the first 256 bytes */

        sprintf(str, "%02X ", EEPROM_ReadByte(i)) ;

        print(str) ;

        if (((i + 1) % 0x10) == 0) {

            print("\n") ;

        }

    }

    print("\n") ;

  

    if (erase_after_test) {

        EEPROM_EraseSector(0) ;

        if (EEPROM_Query() != CYRET_SUCCESS) {

            print("Erasing EEPROM Sector 0 failed\n") ;

        }

  

        print("EEPROM Contents after erase\n") ;

        for (i = 0 ; i < 0x100 ; i++ ) { /* show only the first 256 bytes */

            sprintf(str, "%02X ", EEPROM_ReadByte(i)) ;

            print(str) ;

            if (((i + 1) % 0x10) == 0) {

                print("\n") ;

            }

        }

        print("\n") ;

    }

  

    for(;;)

    {

        /* Place your application code here. */

    }

}

===========================

TeraTerm log

000-TeraTerm-log.JPG

Note: If the first byte is 0, the update data from 0xFF to 0x00

else update data from 0x00 to 0xFF.

If you set the variable "erase_after_test" non zero value,

EEPROM will be erased after test.

moto

0 Likes
MotooTanaka
Esteemed Contributor

Hi,

I added my Em_EEPROM sample to

Emulated EEPROM what does ..._Write() function exactly do?

moto

0 Likes
GeonaP_26
Moderator
Moderator

PSoC 5LP has two different components; the EEPROM component and the Emulated EEPROM component. The EEPROM component provides set of APIs to erase and write to non-volatile on-chip EEPROM memory. Whereas, the Emulated EEPROM component emulates an EEPROM device in the PSoC device flash memory. EEPROM_WriteByte and Em_EEPROM_Write are write API interfaces to EEPROM and Emulated EEPROM components respectively.

Please refer to PSoC Creator provided code examples to understand component usage. Please go to File > Code Example for EEPROM_Design and PSoC_EmEEPROM_PSoC5 code examples.

If you are using Em_EEPROM is your application, use EmEEPROM_Read (uint32 addr, void * eepromData, uint32 size) to read size units of data from logical address addr and write to array pointer eepromData. Please refer to Em_EEPROM component datasheet for more details on API.

View solution in original post

0 Likes