EEPROM Memory Library
This library provides routines for accessing microcontroller's (internal) EEPROM memory. Only the STM32L and Tiva series have internal EEPROM memory.
STM32L Series Library Routines
- EEPROM_Unlock
- EEPROM_Lock
- EEPROM_EraseSector
- EEPROM_EraseAllSectors
- EEPROM_Write_Word
- EEPROM_Write_HalfWord
- EEPROM_Write_Byte
Tiva Series Library Routines
- EEPROM_Init
- EEPROM_BlockCountGet
- EEPROM_BlockHide
- EEPROM_BlockProtectGet
- EEPROM_BlockProtectSet
- EEPROM_BlockLock
- EEPROM_BlockUnlock
- EEPROM_BlockPasswordSet
- EEPROM_MassErase
- EEPROM_Program
- EEPROM_ProgramWord
- EEPROM_Read
EEPROM_Unlock
| Prototype |
void EEPROM_Unlock(); |
|---|---|
| Description |
This routine will unlock the EEPROM control register access. This routine is valid only for STM32L devices. |
| Parameters |
None. |
| Returns |
Nothing. |
| Requires |
Nothing. |
| Example |
EEPROM_Unlock(); |
| Notes |
This routine is valid only for STM32L devices. |
EEPROM_lock
| Prototype |
void EEPROM_lock(); |
|---|---|
| Description |
This routine will lock the EEPROM control register access. This routine is valid only for STM32L devices. |
| Parameters |
None. |
| Returns |
Nothing. |
| Requires |
Nothing. |
| Example |
EEPROM_lock(); |
| Notes |
This routine is valid only for STM32L devices. It is recommended that EEPROM lock is performed right after the EEPROM write is finished to avoid any unwanted subsequent EEPROM writing. |
EEPROM_EraseWord
| Prototype |
unsigned long EEPROM_EraseWord(unsigned long Address); |
|---|---|
| Description |
This routine will erase a word (32-bit) from the specified EEPROM address. This routine is valid only for STM32L devices. |
| Parameters |
|
| Returns |
|
| Requires |
Requires unlock procedure to be performed afterwards. |
| Example |
status = EEPROM_EraseWord(0); |
| Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Write_Word
| Prototype |
unsigned long EEPROM_Write_Word(unsigned long Address, unsigned long lData); |
|---|---|
| Description |
Writes a word (32-bit) at a specified address. The address has to be in the EEPROM address range or else the result can be unpredictable. This routine is valid only for STM32L devices. |
| Parameters |
|
| Returns |
|
| Requires |
Requires unlock procedure to be performed afterwards. |
| Example |
status = EEPROM_Write_Word(); |
| Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Write_HalfWord
| Prototype |
unsigned long EEPROM_Write_HalfWord(unsigned long Address, unsigned int lData); |
|---|---|
| Description |
Writes a half word (16-bit) at a specified address. The address has to be in the EEPROM address range or else the result can be unpredictable. This routine is valid only for STM32L devices. |
| Parameters |
|
| Returns |
|
| Requires |
Requires unlock procedure to be performed afterwards. |
| Example |
status = EEPROM_Write_HalfWord(); |
| Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Write_Byte
| Prototype |
unsigned long EEPROM_Write_Byte(unsigned long Address, unsigned char lData); |
|---|---|
| Description |
Writes a byte (8-bit) at a specified address. The address has to be in the EEPROM address range or else the result can be unpredictable. This routine is valid only for STM32L devices. |
| Parameters |
|
| Returns |
|
| Requires |
Requires unlock procedure to be performed afterwards. |
| Example |
status = EEPROM_Write_Byte(); |
| Notes |
This routine is valid only for STM32L devices. The address has to be in the EEPROM address range or else the result can be unpredictable. |
EEPROM_Init
| Prototype |
unsigned int EEPROM_Init(); |
|---|---|
| Description |
This routine will initialize the EEPROM. |
| Parameters |
None. |
| Returns |
|
| Requires |
Nothing. |
| Example |
value = EEPROM_Init(); |
| Notes |
This routine is valid only for Tiva devices. |
EEPROM_BlockCountGet
| Prototype |
unsigned int EEPROM_BlockCountGet(); |
|---|---|
| Description |
This routine will get the number of blocks in the EEPROM. |
| Parameters |
None. |
| Returns |
Total number of blocks in the device EEPROM. |
| Requires |
Nothing. |
| Example |
blockcount = EEPROM_BlockCountGet(); |
| Notes |
This routine is valid only for Tiva devices. |
EEPROM_BlockHide
| Prototype |
void EEPROM_BlockHide(unsigned int block); |
|---|---|
| Description |
This routine hides an EEPROM block until the next reset. |
| Parameters |
|
| Returns |
Nothing. |
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes #define HIDE_ADDRESS 128 #define HIDE_BLOCK_NUMBER HIDE_ADDRESS/BLOCK_SIZE // hide block containing written data this block is now inaccesible until next reset EEPROM_BlockHide(HIDE_BLOCK_NUMBER); |
| Notes |
|
EEPROM_BlockProtectGet
| Prototype |
unsigned long EEPROM_BlockProtectGet(unsigned int block); |
|---|---|
| Description |
This routine returns the current protection level for an EEPROM block. |
| Parameters |
|
| Returns |
|
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes #define LOCK_ADDRESS 256 #define LOCK_BLOCK_NUMBER LOCK_ADDRESS/BLOCK_SIZE // read the protection level selected for a block i = EEPROM_BlockProtectGet(LOCK_BLOCK_NUMBER); |
| Notes |
|
EEPROM_BlockProtectSet
| Prototype |
unsigned long EEPROM_BlockProtectSet(unsigned int block, unsigned long protect); |
|---|---|
| Description |
This routine sets the current protection options for an EEPROM block. |
| Parameters |
|
| Returns |
|
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes #define LOCK_ADDRESS 256 #define LOCK_BLOCK_NUMBER LOCK_ADDRESS/BLOCK_SIZE // This setting is the default. If there is no password, the block is not protected and is readable and writable. // If there is a password, the block is readable, but only writable when unlocked. EEPROM_BlockProtectSet(LOCK_BLOCK_NUMBER, 0x0); |
| Notes |
|
EEPROM_BlockLock
| Prototype |
unsigned long EEPROM_BlockLock(unsigned int block); |
|---|---|
| Description |
This routine locks a password-protected EEPROM block. |
| Parameters |
|
| Returns |
|
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes #define LOCK_ADDRESS 256 #define LOCK_BLOCK_NUMBER LOCK_ADDRESS/BLOCK_SIZE // lock block containing written data; this block is now inaccesible EEPROM_BlockLock(LOCK_BLOCK_NUMBER); |
| Notes |
|
EEPROM_BlockUnlock
| Prototype |
unsigned long EEPROM_BlockUnlock(unsigned int block, unsigned long *password, unsigned int count); |
|---|---|
| Description |
This routine unlocks a password-protected EEPROM block. |
| Parameters |
|
| Returns |
|
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes #define LOCK_ADDRESS 256 #define LOCK_BLOCK_NUMBER LOCK_ADDRESS/BLOCK_SIZE #define PASS_SIZE 2 unsigned long password[PASS_SIZE]; password[0] = 0x0a; password[1] = 0xc2; // unlock locked block EEPROM_BlockUnlock(LOCK_BLOCK_NUMBER, password, PASS_SIZE); |
| Notes |
|
EEPROM_BlockPasswordSet
| Prototype |
unsigned long EEPROM_BlockPasswordSet(unsigned int block, unsigned long *password, unsigned int count); |
|---|---|
| Description |
This routine sets the password used to protect an EEPROM block. |
| Parameters |
|
| Returns |
|
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes #define LOCK_ADDRESS 256 #define LOCK_BLOCK_NUMBER LOCK_ADDRESS/BLOCK_SIZE #define PASS_SIZE 2 unsigned long password[PASS_SIZE]; password[0] = 0x0a; password[1] = 0xc2; // lock block EEPROM_BlockPasswordSet(LOCK_BLOCK_NUMBER, password, PASS_SIZE); |
| Notes |
|
EEPROM_MassErase
| Prototype |
unsigned long EEPROM_MassErase(); |
|---|---|
| Description |
This routine erases the EEPROM and returns it to the factory default condition. |
| Parameters |
None. |
| Returns |
|
| Requires |
Nothing. |
| Example |
// delete entire EEPROM EEPROM_MassErase(); |
| Notes |
|
EEPROM_Program
| Prototype |
unsigned long EEPROM_Program(unsigned long *data_, unsigned int address, unsigned int count); |
|---|---|
| Description |
This routine writes data to EEPROM. |
| Parameters |
|
| Returns |
|
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes
#define DATA_SIZE BLOCK_SIZE/4 // block size in words (unsigned long)
#define HIDE_ADDRESS 128
#define LOCK_ADDRESS 256
unsigned long writeData[DATA_SIZE];
int i;
for (i = 0; i < DATA_SIZE; i++) {
writeData[i] = i;
}
// write data to EEPROM
EEPROM_Program(writeData, LOCK_ADDRESS, BLOCK_SIZE);
EEPROM_Program(writeData, HIDE_ADDRESS, BLOCK_SIZE);
|
| Notes |
|
EEPROM_ProgramWord
| Prototype |
unsigned long EEPROM_ProgramWord(unsigned long data_, unsigned int address); |
|---|---|
| Description |
This routine writes a word to EEPROM. |
| Parameters |
|
| Returns |
|
| Requires |
Nothing. |
| Example |
#define START_ADDRESS 0 // program one word EEPROM_ProgramWord(0xbb, START_ADDRESS); |
| Notes |
|
EEPROM_Read
| Prototype |
void EEPROM_Read(unsigned long *data_, unsigned int address, unsigned int count); |
|---|---|
| Description |
This routine reads data from EEPROM. |
| Parameters |
|
| Returns |
Nothing. |
| Requires |
Nothing. |
| Example |
#define BLOCK_SIZE 64 // block size in bytes #define DATA_SIZE BLOCK_SIZE/4 // block size in words (unsigned long) #define START_ADDRESS 0 unsigned long readData[DATA_SIZE]; // read DATA_SIZE words of data from EEPROM starting from START_ADDRESS EEPROM_Read(readData, START_ADDRESS, BLOCK_SIZE); |
| Notes |
|
Library Example
What do you think about this topic ? Send us feedback!




