EEPROM with NRF24LE1
All good and bad incidents are stored in the brain memory of humans. Similarly, the controller uses EEPROM to save data or variables. In this article we will see how to use the NRF24LE1 EEPROM and what are its uses?
Do you know what memory does in electronics? Let's look at an example of a capacitor. It has the ability to retain voltage and is therefore treated as a memory component. There are two types of memories in electronics; Volatile and non-volatile. The volatile is erased if the power supplied to this memory is cut off. This means that the stored data will be erased in the event of a power failure. Non-volatile has the advantage of retaining data even when the power is off. The most common example of volatile memory is the RAM used in our computers. The examples of volatile memory are hard disk, SD cards, EEPROM, etc.
Fig. 1: NRF24LE1 and EEPROM interface prototype
In this article, we will focus on the EEPROM in our NRF module and its use. EEPROM stands for electrically erasable programmable read-only memory. It is a type of Non-Volatile. It can be programmed and erased by providing special programming signals. They are available in small sizes and can be easily interfaced with AVR, Arduino or PIC. Sometimes they are built into microcontrollers. But to expand the memory we have to use the external one.
The NRF24LE1, being an incredible component, has built-in EEPROM memory. It has 1.5 Kb of non-volatile data memory. This memory is useful when we connect sensors and want to retain the readings for future use. To utilize the read and write capabilities of this memory, we will use function in our code.
We will use the nrfsdk (software development kit) provided by Nordic Semiconductor Ltd.
Visit our previous article on NRF24LE1 for more help.
Some functions we will use to read and write EEPROM are:
• lib_eeprom_byte_write – This function takes the address location and a byte data to be written.
• lib_eeprom_bytes_write – This function takes several bytes of data along with the number of bytes and the starting address.
• lib_eeprom_byte_read – This function generates byte data from the given memory address.
FUNCTION | INPUT PARAMETER | EXIT | DESCRIPTION |
---|---|---|---|
lib_eeprom_byte_write | 8-bit address and 8-bit data | – | To write 8-bit data to the specified –bit address |
lib_eeprom_bytes_write | 8-bit address, 8-bit pointer to bytes to be written, and 8-bit value indicating the number of bytes to be written | – | To write multiple bytes to the specified starting address |
lib_eeprom_byte_read | 8-bit address | 8-bit data | To read 8-bit data from a specified 8-bit address |
lib_eeprom_bytes_read | 8-bit address, 8-bit pointer to bytes to be written, and 8-bit value indicating the number of bytes to be read | – | To read multiple bytes from the specified starting address. |
For a complete understanding, take a look at the implementation of these functions in the code. The code has been commented for greater understanding.
We will write some data to the EEPROM memory and then restart our system. We will then read the previously stored data to check the operation of the EEPROM.
Project source code
###
//Program to
/* Copyright (c) 2009 Nordic Semiconductor. All rights reserved.
**The information contained herein is the confidential property of Nordic* ASA Semiconductor. Terms and conditions of use are described in detail* in the NORDIC SEMICONDUCTORS STANDARD SOFTWARE LICENSE AGREEMENT.** Licensees are granted free and non-transferable use of the information. NO* WARRANTY OF ANY KIND is provided. This title should NOT be removed from the* the file.**$LastAmendedRevision: 133$*/#include "reg24le1.h" // I/O header file for NRF24LE1#include "lib_eeprom.h" // header file containing eeprom read/write functions#include "hal_delay.h" // header file containing delay functions// Main codemain void{P1DIR = 0; // define port1 as outputP1 = 0; // makes all Port1 pins lowP1 = lib_eeprom_byte_read(0x00); // load 8-bit data from eeprom at address 0x00delay_ms(2000); //2 second delaywhile(1) //infinite loop{P10 = 0; //make port1 pin0 lowP11 = 0; //make port1 pin1 lowlib_eeprom_byte_write(0x00, P1); // write data from register P1 to eepromdelay_ms(2000); //2 second delaylib_eeprom_byte_write(0x00, P1); // write data from register P1 to eepromP10 = 1; //make port1 pin0 highP11 = 0; //make port1 pin1 lowlib_eeprom_byte_write(0x00, P1); // write data from register P1 to eepromdelay_ms(2000); //2 second delayP10 = 0; //make port1 pin0 lowP11 = 1; //make port1 pin1 highlib_eeprom_byte_write(0x00, P1); // write data from register P1 to eepromdelay_ms(2000); //2 second delayP10 = 1; //make port1 pin0 highP11 = 1; //make port1 pin1 highlib_eeprom_byte_write(0x00, P1); // write data from register P1 to eepromdelay_ms(2000); //2 second delay}}###
Circuit diagrams
Circuit Diagram-NRF24LE1-EEPROM Interface |
Project video