You are on page 1of 8

Interfacing the internal serial EEPROM

Stacked into the AT8xEB5114


8051 Microcontrollers
1. Overview
The AT8xEB5114 contains an internal serial EEPROM (AT24C02) connected to the microcontroller via two standard ports. This application note aims to help developers take advantage of all the EEPROM characteristics. The AT8xEB5114 is connected to the EEPROM via two standard C51 bidirectional port bits. In order to have the equivalent to a standard TWI (Two Wire Interface) line (open drain with pull-up of few Ks) with a maximum speed, the bi-directional port bits must be controlled with particular care. The EEPROM and the microcontroller have their own internal brown-out protections, with different thresholds. This means that power supply disturbances can generate a reset on one die whereas the other is still running. The consequence can be a data corruption which can be avoided by implementing special subroutines described in this document.

Application Note

Rev. 7501A805112/05

2. AT24C02 Internal Connection


The internal connection of the EEPROM is shown on Figure 2-1. Figure 2-1. EEPROM and Microcontroller Connections

AT8xEBC5114
A0 A1 A2 WP Vcc

Vcc

AT24 C02

SDA SCL GND

P3.6 P3.7

Vss
The Vcc and ground pins of the EEPROM are directly connected to the Vcc and the Vss pins of the AT8xEB5114. The SCL and the SDA pins of the EEPROM are internally bonded to the P3.6 and P3.7 ports of the AT8xEB5114. The other pins (Device/page address and WP) are left unconnected. Internal pull-downs in AT24C02 drive A0, A1, A2 and WP to a Low level.

2.1

Standards TWI Line


Typically, a standard TWI bus is an open drain transistor connected to the Vcc via a pull-up resistor. The drain is also connected to the Vss pin via the parasitic capacitances. This RC association gives a time constant which gives the maximum speed reachable for the TWI line. This TWI line can be simplified as shown in Figure 2-2.

AT8xEB5114 Application Note


7501A805112/05

AT8xEB5114 Application Note


Figure 2-2. Typical TWI Output Stage

Vdd

Vcc AT24C02 SDA Control Cbus load GND Rpull-up SDA Bus Line

The pull-up resistor can be external or integrated on-chip. The Bus load capacitor is the sum of all the parasitic capacitances of all the chips connected to the line.

2.2

EEPROM Ports Characteristics


The EEPROM output ports are standard, with a maximum capacitance on SDA pin of 8pF.

2.3

AT8xEB5114 Port Characteristics


The AT8xEB5114 ports are standard C51 bidirectional ports. The SCL pin of the EEPROM is an input only, so the SCL pin of the microcontroller can be configured as a push-pull output port in order to obtain the fastest transient as possible. Concerning the SDA pin, it is not possible to configure the microcontroller port as a push-pull output, because SDA pin is sometimes an input and sometimes an output. There is no pull-up on the AT24C02, and there is no additional pull-up on the SDA line. So the SDA pull-up is only made by the AT8xEB5114 SDA port pin. When the AT8xEB5114 port pin is configured as a quasi-bidirectional port, the pull-up resistor is about 100-150Ks when the port pin is low and around 10K when the port pin is high. This means that for a low to high transition, while the level is less than the Vil level, the pull up is 10 times higher than when it has reached this level. It also means that the rising edge is spit into two phases as shown on Figure 2-3.

3
7501A805112/05

Figure 2-3.

Rising time of a bidirectional externally loaded with a 12pF capacitor

Medium pull-up activation (~10KOhms) Vil Weak pull-up (~100KOhms)

2.4

Potential Problem Description in Case of High Speed Transmission


On the TWI protocol, the low level can be driven either by the microcontroller or by the EEPROM. Nevertheless, the High level is only driven by the pull-up resistor. In the present case, the pull-up is integrated into the microcontroller. But as explained before, the pull-up value is quite high and the rising-time can be relatively slow. When the microcontroller drives the SDA data line there is absolutely no problem, because the 0 to 1 transition is helped during two clock periods of the microcontroller by a strong pull-up transistor with a resistor value of few tens of Ohms. When the microcontroller receives data from the EEPROM, the rising edge is guaranteed only by the pull-up resistor of the microcontroller. A problem that may occur is that the microcontroller reads a low level instead of a high level because the pull-up has not been able to raise the SDA pin as fast as expected by the EEPROM which relied on the pull-up to ensure the high level.

2.5

Software Solution
There is a software solution for the above problem. Each time the microcontroller has to proceed a Low to High transition on a pin, the pin is driven High thanks to the strong transistor of only few tenths of Ohms during two clock periods. Moreover, the microcontroller controls the clock of the protocol. Therefore, just before setting the clock in order to read the data, it can make a High to Low transition (because the port is constantly configured as a High level in bidirectional mode) followed by the Low to high transition which allows the strong transistor for a while. In case the EEPROM would like to transmit a low level, it has no effect, and in case the EEPROM would like to transmit an high level, it considerably helps the rising time. This software solution allows to use the EEPROM at its maximum frequency value.

AT8xEB5114 Application Note


7501A805112/05

AT8xEB5114 Application Note


3. EEPROM Brown Out and Microcontroller Power Fail Detect
3.1 AT8xEB5114 Power Fail Detect (PFD) Threshold Levels
The AT8xEB5114 is a typical 3.3V microcontroller. It provides Power On Reset and Power Fail Detect threshold levels defined as in Table 3-1. Table 3-1.
Symbol VPFDP VPFDM

AT8xEB5114 PFD levels


Parameter Power fail high level threshold Power fail low level threshold (default) Power fail hysteresis VPFDP - VPFDM Min 2.6 2.45 190 Typ 2.8 2.5 230 Max 2.95 2.7 260 Unit V V mV

This means that the microcontroller is under reset with a Vcc voltage value from 0 up to 2.7V.

3.2

AT24C02 Brown-Out Threshold Level


The EEPROM typical Power fail detect value is about 1.2V.

3.3

Potential Problem
Due to the difference of PFD level between the EEPROM and the Microcontroller, one part can be under reset while the other one is still running. As the PFD level of the EEPROM is lower than the AT8xEB5114, it appears necessary that the microcontroller resets the EEPROM each time it has itself been reset.

3.4

Resetting the EEPROM


Usually, the TWI protocol is reset when a start condition is applied on the TWI pins. A start sequence consists of a falling edge on the SDA line while the SCL line is high. To generate a start condition, it is necessary to set the SDA line to 1. This can be done by the weak pull-up of the port while the microcontroller is under reset. But, due to the high pull-up value of the AT8xEB5114 port, it can take a long time before having this condition satisfied, and in case the EEPROM is outputting a low level, it is absolutely impossible to have... even with the strong transistor which would only produce a a spike on the SDA line. In order to reset the EEPROM, the best solution is to proceed as follows: Make the clock toggles as long as there is not a high Level on the SDA pin while the SCL pin is high. As soon as this condition is satisfied (SDA High while SCL is also High), make a START by driving low the SDA pin while the SCL pin is still high. After this first start, which has reset the TWI line you can create a STOP (by making a transition from low a High level on the SDA pin while the SCL is High), then you are certain that your protocol has been properly reset, and that no untimely data can be transmitted to the EEPROM while no other START has been processed.

5
7501A805112/05

AT8xEB5114 Application Note


3.5 C-code
void TWI_Init_EEP(void) { // Init ports being sure there is no operation SDA_INT = 0; SCL_INT = 0; SDA_INT = 1; SCL_INT = 1; while (SDA_INT == 0){ // Check SDA is high while SCL is also high SCL_INT = 0; SDA_INT = 0; // Try to force SDA to High level... SDA_INT = 1; // ..thanks to the fast software pull-up SCL_INT = 1; } // Generate a START to reset the protocol SDA_INT = 0; SCL_INT = 0; // Generate a STOP to be sure no data can be untimely transmitted SCL_INT = 1; SDA_INT = 1; // The EEPROM protocol is now reset and waits for the next instruction }

3.6

Examples
The two following diagrams illustrate what happens when the microcontroller is reset while the EEPROM is still correctly operating. Figure 3-1. illustrates an example where the AT8xEB5114 has requested a read data, and the data contains several 0.

Figure 3-1.

Microcontroller reset while the EEPROM is sending 0

RST
Spikes generated by the strong pull-up activation

P3.6 = SDA
Standard bidirectional micrcontroller pull-up effect

P3.7 = SCL

0 START STOP EEPROM READY

EEPROM READING SEQUENCE RESET

6
7501A805112/05

AT8xEB5114 Application Note


The small spikes seen on the SDA pin correspond to the software pull-up which tries to rise the SDA pin. The special rising edge on the SCL pin during the AT8xEB5114 is reset is due the standard bidirectional port pull-up resistor. Just after the reset, the microcontroller has to transfer two dummy 0 data bits before being able to reset the EEPROM protocol. Figure 3-2. illustrates an example of AT8xEB5114 reset while the EEPROM does not hold the SDA line to 0. Figure 3-2. Microcontroller reset while the EEPROM is not driving a 0

RST

P3.6 = SDA

P3.7 = SCL

1 RESET START STOP EEPROM READY

MICROCONTROLLER SENDING DATA

There is no spike visible because in this case only the microcontroller is transmitting data to the EEPROM. The special rising edge of the SCL pin during the microcontroller is reset is due the standard bidirectional port pull-up resistor.

3.7

Remarks
The protocol mentioned allows to ensure a proper reset of the TWI protocol. Nevertheless, it is not exactly the same as if the EEPROM has been reset by a power lost. In case of loss of power, the internal pointer of the EEPROM is reset. In case of protocol reset, the internal pointer is not reset. If the application firmware starts with a sequential read, take care to reset the pointer thanks to a dummy write.

4. References
AT8xC5114 Datasheet 24C02 Serial EEPROM Datasheet.

7
7501A805112/05

Atmel Corporation
2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 487-2600

Atmel Operations
Memory
2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314

RF/Automotive
Theresienstrasse 2 Postfach 3535 74025 Heilbronn, Germany Tel: (49) 71-31-67-0 Fax: (49) 71-31-67-2340 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759

Regional Headquarters
Europe
Atmel Sarl Route des Arsenaux 41 Case Postale 80 CH-1705 Fribourg Switzerland Tel: (41) 26-426-5555 Fax: (41) 26-426-5500

Microcontrollers
2325 Orchard Parkway San Jose, CA 95131, USA Tel: 1(408) 441-0311 Fax: 1(408) 436-4314 La Chantrerie BP 70602 44306 Nantes Cedex 3, France Tel: (33) 2-40-18-18-18 Fax: (33) 2-40-18-19-60

Biometrics/Imaging/Hi-Rel MPU/ High Speed Converters/RF Datacom


Avenue de Rochepleine BP 123 38521 Saint-Egreve Cedex, France Tel: (33) 4-76-58-30-00 Fax: (33) 4-76-58-34-80

Asia
Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon Hong Kong Tel: (852) 2721-9778 Fax: (852) 2722-1369

ASIC/ASSP/Smart Cards
Zone Industrielle 13106 Rousset Cedex, France Tel: (33) 4-42-53-60-00 Fax: (33) 4-42-53-60-01 1150 East Cheyenne Mtn. Blvd. Colorado Springs, CO 80906, USA Tel: 1(719) 576-3300 Fax: 1(719) 540-1759 Scottish Enterprise Technology Park Maxwell Building East Kilbride G75 0QR, Scotland Tel: (44) 1355-803-000 Fax: (44) 1355-242-743

Japan
9F, Tonetsu Shinkawa Bldg. 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan Tel: (81) 3-3523-3551 Fax: (81) 3-3523-7581

Literature Requests
www.atmel.com/literature

Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN ATMELS TERMS AND CONDITIONS OF SALE LOCATED ON ATMELS WEB SITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically providedotherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. AtmelsAtmels products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.

Atmel Corporation 2005. All rights reserved. Atmel , logo and combinations thereof, are registered trademarks, and Everywhere You Are are the trademarks of Atmel Corporation or its subsidiaries. Other terms and product names may be trademarks of others.

Printed on recycled paper.


7501A805112/05

You might also like