Regarding EEPROM in PSOC5lp 059 kit

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
RaSh_3782726
Level 3
Level 3
10 replies posted 10 questions asked 5 replies posted

Hi all,

I need to write the uint16_t value in eeprom how to write? please give example.

Actually I want to enter the value using terminal and this value Rx pin getting this value and that value should be written in EEPROM. Please help me for that.

Thanks & regards

Rathang shah.

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

For uart i/o I cheated by using my sample from

tty_utils a utility sample for CLI type program

Schematic

001-schematic.JPG

Pins

002-pins.JPG

main.c

Note: I'm using my tty_utils.[ch]

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

#include "project.h"

#include "stdio.h"

#include "string.h"

#include "tty_utils.h"

uint16_t sector_number = 0 ;

void init_hardware(void)

{

    tty_init() ;

  

    EEPROM_Start() ;

    EEPROM_UpdateTemperature() ;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

}

void help(void)

{

    print("=== Usage ===\n") ;

    print("write <address> <value>\n") ;

    print("read <address>\n") ;

    print("dump <address> : dump 256 bytes from the row with <address>\n") ;

    print("erase : erase current sector\n") ;

    print("sector <sector_number> : set current sector to <sector_number>\n") ;

}

void do_read(char *opt)

{

    uint16_t address ;

    uint16_t value ;

    uint8_t data[2] ;

    sscanf(opt, "%hx", &address) ;

    data[0] = EEPROM_ReadByte(address) ;

    data[1] = EEPROM_ReadByte(address+1) ;

    value = (data[1] << 😎 | data[0] ; /* little endian */

    // value = (data[0] << 😎 | data[1] ; /* big endian */

    sprintf(str, "0x%02X\n", value) ;

    print(str) ;

}

void do_write(char *opt)

{

    cystatus status ;

    uint16_t address ;

    uint16_t value ;

    uint8_t data[2] ;

    sscanf(opt, "%hx %hx", &address, &value) ;

    // little endian

    data[0] = value & 0xFF ;

    data[1] = (value >> 😎 & 0xFF ;

    // big endian

    // data[0] = (value >> 😎 & 0xFF ;

    // data[1] = value & 0xFF ;

    EEPROM_UpdateTemperature() ;

    status = EEPROM_WriteByte(data[0], address) ;

    if (status == CYRET_SUCCESS) {

        status = EEPROM_WriteByte(data[1], address+1) ;

    }

    if (status == CYRET_SUCCESS) {

        print("OK\n") ;

    } else {

        print("Write Failed!\n") ;

    }

}

void do_dump(char *opt)

{

    int col = 0 ;

    int row = 0 ;

    uint8_t data ;

    uint16_t address, base ;

    sscanf(opt, "%hx", &base) ;

    base &= 0xFFF0 ;

    address = base ;

    for (row = 0 ; row < 16 ; row++) {

        sprintf(str, "%04X : ", base + 16 * row + col) ;

        print(str) ;

        for (col = 0 ; col < 16 ; col++ ) {

            address = base + 16 * row + col ;

            data = EEPROM_ReadByte(address) ;

            sprintf(str, "%02X ", data) ;

            print(str) ;

        }

        print("\n") ;

    }     

}

void do_erase(void)

{

    cystatus status ;

  

    status = EEPROM_EraseSector(sector_number) ;

    if (status == CYRET_SUCCESS) {

        print("OK\n") ;

    } else {

        sprintf(str, "Erasing Sector %d failed\n", sector_number) ;

        print(str) ;

    }

}

void do_sector(char *opt)

{

    sscanf(opt, "%hd", &sector_number) ;

    sprintf(str, "Sector Number = %d\n", sector_number) ;

    print(str) ;

}

  

int main(void)

{

    char cmd[32] ;

    int index ;

    char *opt = 0 ;

  

    init_hardware() ;

  

    splash("CY8CKIT-059 EEPROM TEST") ;

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

    print(str) ;

  

    prompt() ;

    for(;;) {

        if (get_line()) {

            sscanf(str, "%s", cmd) ;

            index = strlen(cmd) ;

            opt = &str[index] ;

 

            if (strcmp(cmd, "write") == 0) {

                do_write(opt) ;

            } else if (strcmp(cmd, "read") == 0) {

                do_read(opt) ;

            } else if (strcmp(cmd, "dump") == 0) {

                do_dump(opt) ;

            } else if (strcmp(cmd, "erase") == 0) {

                do_erase() ;

            } else if (strcmp(cmd, "sector") == 0) {

                do_sector(opt) ;

            } else {

                help() ;

            }

            prompt() ;

        }

    }

}

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

Tera Term log

000-TeraTerm-log.JPG

moto

P.S. I used "Little Endian" if you want to use "Big Endian" swap lines commented as "big endian" with "little endian."

View solution in original post

3 Replies
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

For uart i/o I cheated by using my sample from

tty_utils a utility sample for CLI type program

Schematic

001-schematic.JPG

Pins

002-pins.JPG

main.c

Note: I'm using my tty_utils.[ch]

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

#include "project.h"

#include "stdio.h"

#include "string.h"

#include "tty_utils.h"

uint16_t sector_number = 0 ;

void init_hardware(void)

{

    tty_init() ;

  

    EEPROM_Start() ;

    EEPROM_UpdateTemperature() ;

  

    CyGlobalIntEnable; /* Enable global interrupts. */

}

void help(void)

{

    print("=== Usage ===\n") ;

    print("write <address> <value>\n") ;

    print("read <address>\n") ;

    print("dump <address> : dump 256 bytes from the row with <address>\n") ;

    print("erase : erase current sector\n") ;

    print("sector <sector_number> : set current sector to <sector_number>\n") ;

}

void do_read(char *opt)

{

    uint16_t address ;

    uint16_t value ;

    uint8_t data[2] ;

    sscanf(opt, "%hx", &address) ;

    data[0] = EEPROM_ReadByte(address) ;

    data[1] = EEPROM_ReadByte(address+1) ;

    value = (data[1] << 😎 | data[0] ; /* little endian */

    // value = (data[0] << 😎 | data[1] ; /* big endian */

    sprintf(str, "0x%02X\n", value) ;

    print(str) ;

}

void do_write(char *opt)

{

    cystatus status ;

    uint16_t address ;

    uint16_t value ;

    uint8_t data[2] ;

    sscanf(opt, "%hx %hx", &address, &value) ;

    // little endian

    data[0] = value & 0xFF ;

    data[1] = (value >> 😎 & 0xFF ;

    // big endian

    // data[0] = (value >> 😎 & 0xFF ;

    // data[1] = value & 0xFF ;

    EEPROM_UpdateTemperature() ;

    status = EEPROM_WriteByte(data[0], address) ;

    if (status == CYRET_SUCCESS) {

        status = EEPROM_WriteByte(data[1], address+1) ;

    }

    if (status == CYRET_SUCCESS) {

        print("OK\n") ;

    } else {

        print("Write Failed!\n") ;

    }

}

void do_dump(char *opt)

{

    int col = 0 ;

    int row = 0 ;

    uint8_t data ;

    uint16_t address, base ;

    sscanf(opt, "%hx", &base) ;

    base &= 0xFFF0 ;

    address = base ;

    for (row = 0 ; row < 16 ; row++) {

        sprintf(str, "%04X : ", base + 16 * row + col) ;

        print(str) ;

        for (col = 0 ; col < 16 ; col++ ) {

            address = base + 16 * row + col ;

            data = EEPROM_ReadByte(address) ;

            sprintf(str, "%02X ", data) ;

            print(str) ;

        }

        print("\n") ;

    }     

}

void do_erase(void)

{

    cystatus status ;

  

    status = EEPROM_EraseSector(sector_number) ;

    if (status == CYRET_SUCCESS) {

        print("OK\n") ;

    } else {

        sprintf(str, "Erasing Sector %d failed\n", sector_number) ;

        print(str) ;

    }

}

void do_sector(char *opt)

{

    sscanf(opt, "%hd", &sector_number) ;

    sprintf(str, "Sector Number = %d\n", sector_number) ;

    print(str) ;

}

  

int main(void)

{

    char cmd[32] ;

    int index ;

    char *opt = 0 ;

  

    init_hardware() ;

  

    splash("CY8CKIT-059 EEPROM TEST") ;

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

    print(str) ;

  

    prompt() ;

    for(;;) {

        if (get_line()) {

            sscanf(str, "%s", cmd) ;

            index = strlen(cmd) ;

            opt = &str[index] ;

 

            if (strcmp(cmd, "write") == 0) {

                do_write(opt) ;

            } else if (strcmp(cmd, "read") == 0) {

                do_read(opt) ;

            } else if (strcmp(cmd, "dump") == 0) {

                do_dump(opt) ;

            } else if (strcmp(cmd, "erase") == 0) {

                do_erase() ;

            } else if (strcmp(cmd, "sector") == 0) {

                do_sector(opt) ;

            } else {

                help() ;

            }

            prompt() ;

        }

    }

}

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

Tera Term log

000-TeraTerm-log.JPG

moto

P.S. I used "Little Endian" if you want to use "Big Endian" swap lines commented as "big endian" with "little endian."

Thanks Moto.

odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

Rathan,

You can use custom component myEEPROM to write/read data to EEPROM

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

The component can save multiple sets of data of any types with CRC check in one line of code and restore it automatically on startup.

/odissey1