Difference between revisions of "EEPROM"
(11 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
==EEPROM_WriteByte== | ==EEPROM_WriteByte== | ||
− | {| | + | {|{{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | |Defination || void EEPROM_WriteByte(uint16_t | + | |Defination || void EEPROM_WriteByte(uint16_t var_eepromAddress_u16, uint8_t var_eepromDatarr_u8) |
|- | |- | ||
| Input Arguments || uint16_t: eeprom_address at which eeprom_data is to be written.<br />uint8_t: byte of data to be to be written in eeprom. | | Input Arguments || uint16_t: eeprom_address at which eeprom_data is to be written.<br />uint8_t: byte of data to be to be written in eeprom. | ||
Line 25: | Line 25: | ||
==EEPROM_WriteNBytes== | ==EEPROM_WriteNBytes== | ||
− | {| | + | {|{{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | |Defination || void EEPROM_WriteNBytes(uint16_t | + | |Defination || void EEPROM_WriteNBytes(uint16_t var_eepromAddress_u16, uint8_t *ptr_ramAddress_u8, uint16_t var_numOfBytes_u16) |
|- | |- | ||
| Input Arguments || uint16_t,: eeprom_address from where the N-bytes are to be written.<br /> | | Input Arguments || uint16_t,: eeprom_address from where the N-bytes are to be written.<br /> | ||
− | uint8_t*: Pointer | + | uint8_t*: Buffer(Pointer) containing the N-Bytes of data to be written in Eeprom..<br /> |
uint16_t : Number of bytes to be written | uint16_t : Number of bytes to be written | ||
|- | |- | ||
Line 46: | Line 46: | ||
==EEPROM_WriteString== | ==EEPROM_WriteString== | ||
− | {| | + | {|{{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | |Defination || void EEPROM_WriteString(uint16_t | + | |Defination || void EEPROM_WriteString(uint16_t var_eepromAddress_u16, char *ptr_stringPointer_u8) |
|- | |- | ||
| Input Arguments || uint16_t: eeprom_address where the String is to be written.<br /> | | Input Arguments || uint16_t: eeprom_address where the String is to be written.<br /> | ||
− | char*: Pointer to String which has to be written. | + | char*: String(Pointer to String) which has to be written in Eeprom. |
|- | |- | ||
| Return Value|| none | | Return Value|| none | ||
Line 66: | Line 66: | ||
==EEPROM_Erase== | ==EEPROM_Erase== | ||
− | {| | + | {|{{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
Line 86: | Line 86: | ||
==EEPROM_ReadByte== | ==EEPROM_ReadByte== | ||
− | {| | + | {|{{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | |Defination || uint8_t EEPROM_ReadByte(uint16_t | + | |Defination || uint8_t EEPROM_ReadByte(uint16_t var_eepromAddress_u16) |
|- | |- | ||
| Input Arguments || uint16_t: eeprom_address from where eeprom_data is to be read. | | Input Arguments || uint16_t: eeprom_address from where eeprom_data is to be read. | ||
Line 104: | Line 104: | ||
==EEPROM_ReadNBytes== | ==EEPROM_ReadNBytes== | ||
− | {| | + | {|{{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | |Defination || void EEPROM_ReadNBytes(uint16_t | + | |Defination || <syntaxhighlight>void EEPROM_ReadNBytes(uint16_t var_eepromAddress_16, uint8_t *ptr_ramAddress_u8, uint16_t var_numOfBytes_u16)</syntaxhighlight> |
|- | |- | ||
| Input Arguments || uint16_t,: eeprom_address from where the N-bytes is to be read.<br /> | | Input Arguments || uint16_t,: eeprom_address from where the N-bytes is to be read.<br /> | ||
− | uint8_t*: Pointer | + | uint8_t*: Pointer to copy the N-bytes read from Eeprom.<br /> |
uint16_t : Number of bytes to be Read | uint16_t : Number of bytes to be Read | ||
Line 122: | Line 122: | ||
EEPROM_ReadNBytes(1000,A_RamBuffer_U8,20); //Copies 20bytes of eeprom data(address 1000) into A_RamBuffer_U8 | EEPROM_ReadNBytes(1000,A_RamBuffer_U8,20); //Copies 20bytes of eeprom data(address 1000) into A_RamBuffer_U8 | ||
|} | |} | ||
− | |||
− | |||
− | |||
==EEPROM_ReadString== | ==EEPROM_ReadString== | ||
− | {| | + | {|{{Widget:LibCol}} |
{{#Widget:LibTable}} | {{#Widget:LibTable}} | ||
|- | |- | ||
− | |Defination || void EEPROM_ReadString(uint16_t | + | |Defination || void EEPROM_ReadString(uint16_t var_eepromAddress_u16, char *ptr_destStringAddress_u8) |
|- | |- | ||
| Input Arguments || uint16_t: eeprom_address from where the String is to be read.<br /> | | Input Arguments || uint16_t: eeprom_address from where the String is to be read.<br /> | ||
Line 148: | Line 145: | ||
==user guide== | ==user guide== | ||
<syntaxhighlight> | <syntaxhighlight> | ||
− | /* Program to | + | /* Program to illustrate the eeprom Read/Write */ |
+ | #include"uart.h" | ||
+ | #include"delay.h" | ||
+ | #include"eeprom.h" | ||
− | + | int main() | |
− | + | { | |
+ | uint8_t arr_writeBuffer_u8[5]={10,20,35,50,60}; | ||
+ | char str_readString_u8[20]; | ||
+ | uint32_t var_writeNumber_u32=123456789; | ||
+ | uint32_t var_readNumber_u32=0x00; | ||
+ | char var_readChar_u8; | ||
+ | uint8_t arr_readBuffer_u8[5]; | ||
+ | uint8_t i; | ||
+ | UART_Init(9600); //Initialize UART at 9600 baud | ||
− | + | UART_TxString("\n\rErasing the Eeprom"); | |
− | + | EEPROM_Erase(); | |
+ | UART_TxString("\n\rWriting below data into eeprom"); | ||
+ | UART_TxString("\n\rchar= A"); | ||
+ | UART_TxString("\n\r5-Bytes= 10,20,35,50,60"); | ||
+ | UART_TxString("\n\rString: hello, world"); | ||
+ | UART_Printf("\n\r32-bit number= %L",var_writeNumber_u32); | ||
+ | EEPROM_WriteByte(10,'A'); | ||
+ | EEPROM_WriteNBytes(100,arr_writeBuffer_u8,5); | ||
+ | EEPROM_WriteString(150,"hello, world"); | ||
+ | EEPROM_WriteNBytes(200,&var_writeNumber_u32,sizeof(var_writeNumber_u32)); | ||
− | + | UART_TxString("\n\r\n\rReading Data back from eeprom"); | |
− | + | var_readChar_u8 = EEPROM_ReadByte(10); | |
− | + | EEPROM_ReadNBytes(100,arr_readBuffer_u8,5); | |
− | + | EEPROM_ReadString(150,str_readString_u8); | |
− | + | EEPROM_ReadNBytes(200,&var_readNumber_u32,sizeof(var_readNumber_u32)); | |
− | + | UART_Printf("\n\rchar:%c",var_readChar_u8); | |
+ | UART_TxString("\n\r5-Bytes: "); | ||
+ | for(i=0;i<5;i++) | ||
+ | UART_Printf("%d ",arr_readBuffer_u8[i]); | ||
+ | UART_Printf("\n\rstring:%s",str_readString_u8); | ||
+ | UART_Printf("\n\r32bit Number:%L",var_readNumber_u32); | ||
− | |||
− | |||
− | |||
− | |||
− | + | while(1); | |
return 0; | return 0; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 08:58, 10 January 2015
Contents
EEPROM
EEPROM_WriteByte
Defination | void EEPROM_WriteByte(uint16_t var_eepromAddress_u16, uint8_t var_eepromDatarr_u8) |
Input Arguments | uint16_t: eeprom_address at which eeprom_data is to be written. uint8_t: byte of data to be to be written in eeprom. |
Return Value | none |
Description | This function is used to write the data at specified EEPROM_address.. |
Usage | EEPROM_WriteByte(1234,25); //Writes 25 at the eeprom address 1234. |
EEPROM_WriteNBytes
Defination | void EEPROM_WriteNBytes(uint16_t var_eepromAddress_u16, uint8_t *ptr_ramAddress_u8, uint16_t var_numOfBytes_u16) |
Input Arguments | uint16_t,: eeprom_address from where the N-bytes are to be written. uint8_t*: Buffer(Pointer) containing the N-Bytes of data to be written in Eeprom.. |
Return Value | none |
Description | This function is used to write N-bytes of data at specified EEPROM_address. |
Usage | uint8_t A_RamBuffer_U8[5]={10,20,30,40,50}; // Buffer containing the data to be written in Eeprom EEPROM_WriteNBytes(100,A_RamBuffer_U8,5); //Copies 5bytes of data from A_RamBuffer_U8 into eeprom location 100. |
EEPROM_WriteString
Defination | void EEPROM_WriteString(uint16_t var_eepromAddress_u16, char *ptr_stringPointer_u8) |
Input Arguments | uint16_t: eeprom_address where the String is to be written. char*: String(Pointer to String) which has to be written in Eeprom. |
Return Value | none |
Description | This function is used to Write a String at specified EEPROM_address.NOTE: Null char is also written into the eeprom. |
Usage | uint8_t A_StringBuffer_U8[20]="Hello, World"; // String to be written in eeprom EEPROM_WriteString(50,A_StringBuffer_U8); //Copies "Hello, World" along with NULL character into eeprom location 50. |
EEPROM_Erase
Defination | void EEPROM_Erase() |
Input Arguments | none |
Return Value | none |
Description | This function is used to erase the entire Eeprom memory. Complete Eeprom(C_MaxEepromSize_U16) is filled with 0xFF to accomplish the Eeprom Erase. |
Usage | EEPROM_Erase(); //Erases the complete(C_MaxEepromSize_U16 bytes) eeprom. |
EEPROM_ReadByte
Defination | uint8_t EEPROM_ReadByte(uint16_t var_eepromAddress_u16) |
Input Arguments | uint16_t: eeprom_address from where eeprom_data is to be read. |
Return Value | uint8_t: data read from Eeprom. |
Description | This function is used to read a byte of data from specified EEPROM_address. |
Usage | eeprom_data = EEPROM_ReadByte(100); reads the data from eeprom location 100 which is copied to eeprom_data |
EEPROM_ReadNBytes
Defination | void EEPROM_ReadNBytes(uint16_t var_eepromAddress_16, uint8_t *ptr_ramAddress_u8, uint16_t var_numOfBytes_u16) |
Input Arguments | uint16_t,: eeprom_address from where the N-bytes is to be read. uint8_t*: Pointer to copy the N-bytes read from Eeprom. |
Return Value | none |
Description | This function is used to Read N-bytes of data from specified EEPROM_address. The data read from the eeprom will be copied into the specified RamAddress . Note:Care should be taken to allocate enough buffer to read the data. |
Usage | uint8_t A_RamBuffer_U8[20]; // Buffer to read the Eeprom data EEPROM_ReadNBytes(1000,A_RamBuffer_U8,20); //Copies 20bytes of eeprom data(address 1000) into A_RamBuffer_U8 |
EEPROM_ReadString
Defination | void EEPROM_ReadString(uint16_t var_eepromAddress_u16, char *ptr_destStringAddress_u8) |
Input Arguments | uint16_t: eeprom_address from where the String is to be read. char*: Pointer into which the String is to be read. |
Return Value | none |
Description | This function is used to Read a String from specified EEPROM_address.The string read from eeprom will be copied to specified buffer along with NULL character. |
Usage | uint8_t A_StringBuffer_U8[20]; // Buffer to read the Eeprom data EEPROM_ReadString(200,A_StringBuffer_U8); //Copies a string from eeprom(address 200) along with NULL caharacter into A_StringBuffer_U8 |
user guide
/* Program to illustrate the eeprom Read/Write */ #include"uart.h" #include"delay.h" #include"eeprom.h" int main() { uint8_t arr_writeBuffer_u8[5]={10,20,35,50,60}; char str_readString_u8[20]; uint32_t var_writeNumber_u32=123456789; uint32_t var_readNumber_u32=0x00; char var_readChar_u8; uint8_t arr_readBuffer_u8[5]; uint8_t i; UART_Init(9600); //Initialize UART at 9600 baud UART_TxString("\n\rErasing the Eeprom"); EEPROM_Erase(); UART_TxString("\n\rWriting below data into eeprom"); UART_TxString("\n\rchar= A"); UART_TxString("\n\r5-Bytes= 10,20,35,50,60"); UART_TxString("\n\rString: hello, world"); UART_Printf("\n\r32-bit number= %L",var_writeNumber_u32); EEPROM_WriteByte(10,'A'); EEPROM_WriteNBytes(100,arr_writeBuffer_u8,5); EEPROM_WriteString(150,"hello, world"); EEPROM_WriteNBytes(200,&var_writeNumber_u32,sizeof(var_writeNumber_u32)); UART_TxString("\n\r\n\rReading Data back from eeprom"); var_readChar_u8 = EEPROM_ReadByte(10); EEPROM_ReadNBytes(100,arr_readBuffer_u8,5); EEPROM_ReadString(150,str_readString_u8); EEPROM_ReadNBytes(200,&var_readNumber_u32,sizeof(var_readNumber_u32)); UART_Printf("\n\rchar:%c",var_readChar_u8); UART_TxString("\n\r5-Bytes: "); for(i=0;i<5;i++) UART_Printf("%d ",arr_readBuffer_u8[i]); UART_Printf("\n\rstring:%s",str_readString_u8); UART_Printf("\n\r32bit Number:%L",var_readNumber_u32); while(1); return 0; }