This section covers the 47xxx EERAM devices.
The 47xxx EERAM device is a memory device organized as 512 x 8 bits or 2,048 x 8 bits of memory, and it uses the I2C serial interface.
The 47xxx provides infinite read and write cycles to the SRAM, while its EEPROM cells provide high-endurance non-volatile storage of data with more than one million store cycles to EEPROM and a data retention of more than 200 years.
With an external capacitor (~10uF), SRAM data is automatically transferred to the EEPROM upon loss of power, giving the advantages of NVRAM while eliminating the need for backup batteries.
Data can also be backed up manually using either the hardware store pin (HS) or software control.
On power-up, the EEPROM data is automatically recalled to the SRAM. EEPROM data recall can also be initiated through software control.
Connectivity is shown below:
__ __
Vcap-->| U |<-- Vcc
A1 -->| |<-- HS
A2 -->| |<-> SCL
Vss -->|_____|<-> SDAModes of Operation
The SRAM allows for fast reads and writes and unlimited endurance. As long as power is present, the data stored in the SRAM can be updated as often as desired.
To preserve the SRAM image, the AutoStore function copies the entire SRAM image to an EEPROM array whenever it detects that the voltage drops below a predetermined level. Power for the AutoStore process is provided by the externally connected VCAP capacitor. Upon power-up, the entire memory contents are restored by copying the EEPROM image to the SRAM. This automatic restore operation completes in milliseconds after power-up, at the same time other device peripherals are initialising.
There is no latency in writing to the SRAM. The SRAM can be written to starting at any random address, and can be written continuously throughout the array, wrapping back to the beginning after the end is reached. There is a small delay, specified as TWC in the datasheet, when writing to the non-volatile configuration bits of the STATUS Register (SR).
Besides the AutoStore function, there are two other methods to store the SRAM data to EEPROM:
- One method is the hardware store, initiated by a rising edge on the HS pin.
- The other method is the software store, initiated by writing the correct instruction to the command register via I2C.
The_paragraph_above_is_copyright_Microchip:_AN2047
Explanation
The GCBASIC constants and commands shown below control the configuration of the 47xxx EERAM device. GCBASIC supports both I2C hardware and software connectivity — this is shown in the tables below.
To use the 47xxx driver, simply include the following in your user code. This initialises the driver.
#include <47xxx_EERAM.H>
; ----- Define Hardware settings for EERAM Module
#define I2C_Adr_EERAM 0x30 ; EERAM base Address
#define EERAM_HS PortB.1 ; Optional hardware Store Pin
Dir EERAM_HS Out ; Rising edge initiates Backup
EERAM_AutoStore(ON) ; Enable Automatic Storage on power loss ' <<< the initialisation instruction
'EERAM_AutoStore(OFF) ; Disable Automatic Storage on power lossKey line: EERAM_AutoStore(ON) — enables the device’s own AutoStore feature, so a power failure alone (with the VCAP capacitor fitted) is enough to preserve
the SRAM contents into EEPROM without any further code.
The device parameters are shown in the table below.
| Part Number | Density (bits) | VCC Range | Max. I2C Frequency | Tstore Delay | Trecall Delay |
|---|---|---|---|---|---|
|
47L04 |
4K |
2.7-3.6V |
1 MHz |
8ms |
25ms |
|
47C04 |
4K |
4.5-5.5V |
1 MHz |
8ms |
2ms |
|
47L16 |
16K |
2.7-3.6V |
1 MHz |
25ms |
5ms |
|
47C16 |
16K |
4.5-5.5V |
1 MHz |
25ms |
5ms |
The GCBASIC constants for control of the device are:
| Constant | Context | Example | Default |
|---|---|---|---|
|
EERAM_I2C_Adr |
8-bit I2C address of the device |
#define I2C_Adr_EERAM 0x30 |
Default is 0x30. This is mandated. |
|
EERAM_HS |
Optional hardware store pin |
#define EERAM_HS portb.1 |
No default — this is not mandated. |
|
EERAM_Tstore |
Delay period for writing to the device |
#define EERAM_Tstore 25 |
25 (ms) |
|
EERAM_Trecall |
Delay period for reading from the device |
#define EERAM_Trecall 5 |
5 (ms) |
The GCBASIC commands for control of the device are:
| Command | Context | Example |
|---|---|---|
|
EERAM_AutoStore |
Enable or disable automatic storage on power loss |
EERAM_AutoStore(ON), or EERAM_AutoStore(OFF) |
|
EERAM_Status |
Read the status register |
User_byte_variable = EERAM_Status() |
|
EERAM_Backup |
Backup / store now |
EERAM_Backup() |
|
EERAM_Recall |
Restore now |
EERAM_Recall() |
|
EERAM_HWStore |
Force backup with the HS pin |
EERAM_HWStore() |
|
EERAM_Write |
Write a byte of data to the specified address. The address must be a word value and the data must be a byte value. |
EERAM_Write( EERAM_Address_word, EERAM_Data_byte) |
|
EERAM_Read |
Read a byte of data from an address. The address must be a word value and the returned data is a byte value. |
User_byte_variable = EERAM_Read(EERAM_Address_word) |
This example shows how to use the device.
Example:
#CHIP 16F18855,32
#OPTION EXPLICIT
#INCLUDE <47XXX_EERAM.H>
#startup InitPPS, 85
Sub InitPPS
'PPS is explicit to a specific chip. Use PPSTool to ensure the PPS settings are correct.
'Module: EUSART
RC0PPS = 0x0010 'TX > RC0
TXPPS = 0x0008 'RC0 > TX (bi-directional)
'Module: MSSP1
SSP1DATPPS = 0x0013 'RC3 > SDA1
RC3PPS = 0x0015 'SDA1 > RC3 (bi-directional)
RC4PPS = 0x0014 'SCL1 > RC4
SSP1CLKPPS = 0x0014 'RC4 > SCL1 (bi-directional)
End Sub
; ----- Define Hardware Serial Print
#DEFINE USART_BAUD_RATE 115200
#DEFINE USART_TX_BLOCKING
; ----- Define Hardware settings for hwi2c
#DEFINE HI2C_BAUD_RATE 400
#DEFINE HI2C_DATA PORTC.3
#DEFINE HI2C_CLOCK PORTC.4
'I2C pins need to be input for legacy I2C modules
DIR HI2C_DATA IN
DIR HI2C_CLOCK IN
'Initialise I2C Master
hi2cMode Master
; ----- Define Hardware settings for EERAM Module
#define EERAM_I2C_Adr 0x30 ; EERAM base Address
#define EERAM_HS PortB.1 ; Optional hardware Store Pin
Dir EERAM_HS Out ; Rising edge initiates Backup
'Library function
EERAM_AutoStore(ON) ; Enable Automatic Storage on power loss
; ----- Main body of program commences here.
dim Idx as Byte
HserPrintCRLF 2
HserPrint "Hardware I2C EERAM Read Test at I2C Adr 0x"
HserPrint Hex(EERAM_I2C_Adr)
HserPrint " Reading RAM addresses 0x0 to 0xF" : HserPrintCRLF 2
for Idx = 0x0 to 0xF
HserPrint hex(Idx) + " = " : HserPrint Hex(EERAM_Read(Idx))
If Idx = 7 or Idx = 0xf then
HserPrintCRLF
Else
HserPrint " : "
End if
next
HserPrintCRLF : HserPrint "Control Byte = " Hex(EERAM_Status()) : HserPrintCRLF 2
wait 100 ms ; time for serial operations to complete
endSee Also:
- Software I2C
- Hardware I2C
- Dataset for EEPROM — the microcontroller’s own on-chip EEPROM, for comparison

