AN1525 STMicroelectronics, AN1525 Datasheet - Page 4

no-image

AN1525

Manufacturer Part Number
AN1525
Description
I2C COMMUNICATION BETWEEN ST52X520 AND EEPROM
Manufacturer
STMicroelectronics
Datasheet
AN1525 - APPLICATION NOTE
In the example that has been proposed, bit b1 (that represents bit A8 of the memory address) wasn’t used
in the Device Select Code. The user can select only one range of addresses, which range from 0 to 255.
In order to address memory locations that exceed the quantity indicated, the program has to be modified.
The reading and writing phases are alternated based on the pressure exerted on the pushbutton (see Fig-
ure 2). During the reading phase, data read is seen in port B of the ST52x520 microcontroller. Seeing that
this is a demonstration program, the user will be responsible for adequately managing the program in the
data reception phase. In the example, the micro clock frequency is set to 5 MHZ, all port B pins are con-
2
figured as OUT, PA7 as INT and pin PA0 and PA1, respectively as SCL and SDA (pins of the I
C periph-
eral of the ST52x520 microcontroller).
2
Figure 5 shows the Device configuration window for the configuration of the I
C peripheral of the micro-
controller, where both the Acknowledgment generation and the Interrupt generation are set, in order to
allow the program to synchronize various events. Moreover, the Clock Divider Value (prescaler) is set to
14 in order to obtain a transmission frequency of approximately 98 KHz. The ST52x520 micro can also be
configured for communications in Fast Mode (400KHz).
4.1 Main Program Window
The window of the main program flow is shown in Figure 6. In the USER_VAR block, which is shown be-
side it, the user will be able to define the apposite variable memory address where to begin data writing
(W_ADD), reading (R_ADD), as well as the number of data to write and read (BYTE_N) and the initial val-
ue to be written in the first location (BASE). BASE will be incremented automatically by the program before
writing in the next location.
Figure 6. MAIN WINDOW
The ST52x520 ports and the indexes k and p are initialized in the INIT block. These indexes are used to
determine the inhibition of the last ACK during the reading phase and generate the STOP condition cor-
2
rectly, in accordance with the specifications of the I
C interface of the ST52x520 microcontroller. In case
the number of bytes to write and read (BYTE_N) is equal to one, the read/write operations in EEPROM
will be respectively that of Byte Write Operation and Random Address Read. The FLAG variable is used
to establish exactly which phases the micro ST52x520 has to read or write each time. All of these phases
2
are performed in the interrupt routine of the I
C described further ahead. The meaning of the single bits of
the FLAG variable is shown in Figure 7.
4/12

Related parts for AN1525