AN971
APPLICATION NOTE
I2C COMMUNICATION BETWEEN
ST7 AND M24Cxx EEPROM
by Microcontroller Division Applications
INTRODUCTION
The goal of this application note is to present an practical example of communication using the
2
C peripheral of the ST7. It shows a basic single master communication between a ST7 mi-
I
crocontroller and an M24C xx I
through the I
ment.
2
C interface, a write and a read to the external EEPROM without error manage-
2
C bus EEPROM. T he purpose i s to i mplem ent, from the ST7
AN971/0403 1/7
1
I2C COMMUNICATION BETWEEN ST7 AND M24Cxx EEPROM
1 ST7 I2C INTERF ACE
The ST7 I2C peripheral allows multi master and slave communication with bus error management. In this application, only single master mode is used without error management. As
polling mode i s the mos t d ifficult m ode to i mplemen t, t he applicati on is base d o n th is mo de,
but it can be easily adapted for interrupt management.
2
The I
(Serial data line). The corresponding port pins have to be configured as floating inputs.
Please refer to the ST7 datasheet for more details.
1.1 COMMUNICATION SPEED
The ST7 I
standard and fast I
In master mode the communication speed is given by the Clock Control Register (CCR). An
example is given in Table 1.
C synchronous communication needs only two signals: SCL (Serial clock line) and SDA
2
C peripheral allows a large range of com mun ication spee ds. It is ab le to work in
2
C modes.
2
Table 1. Example of Possible I
Speed [KHz] 15.5 25.00 50.00 70.00 100.00 167.00 190.00 333.00
CCR [hex] EC 9E 4E 37 26 8E 8C 86
C Communication Speeds (f
Standar d Mo de Fast Mod e
CPU
=8 MHz)
1.2 START, STOP CONDITION AND ACKNOWLEDGE GENERATION
In master mode, the Start and Stop c ondition s can be generated by setting the START and
STOP bits in the Control Register (CR).
An Acknowledge is sent after an address or a data byte is received when the ACK bit is set in
the Control Register (CR).
2/7
2
I2C COMMUNICATION BETWEEN ST7 AND M24Cxx EEPROM
2 ST7 / M24CXX I2C COMMUNICATION APPLICA T ION
2.1 HARDWARE CONFIGURATION
2
The ST7 / M24Cxx I
troller which communicates with an external M24C08 EEPROM through an I
Figure 1. ST7 / EEPRO M I2C Communications Application
C communication application hardware consists of a ST72264 microcon-
5V
V
SCL
SDA
DD
2x27KΩ
2x100Ω
M24C08
SCL
SDA
ST72264
I2C
2
C bus interface.
V
SS
2.2 ST7 I
In this chapter all registers refer to the ST7 I
2.3 INITIALIZE THE I
2
C PERIPHERAL BASIC DRIVERS
2
C PERIPHERAL
2
C peripheral (unless otherwise specified).
In this ap plicati on th e i nitial ization o f the ST7 I
2
C peripheral is done comp letely by softw are
E
Address=A0h
without taking into account the hardware reset status.
First the Control Register (CR) is cleared and the Data (DR) and Status (SR1,SR2) registers
are touched to clear any pending events.
Then, the peripheral is enabled through the Control Register (CR) . This action needs to write
twice in the register due to the fact that the Control Register (CR) bits can be set only when the
PE enab le bi t is alre ady set. To allow the pe riph eral to ack nowl edge th e re ceive d dat a the
ACK bit of the Control Register (CR) is set.
2
As the ST24C08 EEPROM is specified with a maximum I
2
I
C peripheral is set to this speed (CCR=26h) in the application.
C clock speed at 100KHz, the ST7
3/7