AN1328 STMicroelectronics, AN1328 Datasheet - Page 6

no-image

AN1328

Manufacturer Part Number
AN1328
Description
I2C COMMUNICATION PROTOCOL WRITTEN IN FUZZYSTUDIOTM4.0 FOR ST52X430
Manufacturer
STMicroelectronics
Datasheet
AN1328 - APPLICATION NOTE
5. SOFTWARE DESCRIPTION
We analyze each procedure for reading and writing a byte, separately, although they use some subrou-
tines that are commons. In fact, as every operation in the memory begins with a write command (to specify
the device selector byte and the address), the Read Procedure must contain also the code that allows writ-
ing into the memory.
Another important point to discuss is that the two routines are done in such a way that any user program
can import them directly with few modifications. The price to pay for this end is to reserve a user-variable
to keep track of the configuration register relative to the I/O PORT_A (Configuration Register #4) of the
micro (this is an hardware register that is only writable from the user but not readable). Acting in this man-
ner we will be able to modify the I/O configuration only for the involved pins (PA0 and PA6) without chang-
ing the configuration of other six pins. Because inside the routine the direction of the PA6 is continually
changed (input or output), what the user has to do is to initialize the reserved variable (named
REG_CONF4_IM) with the wanted configuration of the PORT_A. At the end of each routine execution, the
PORT_A will restore its original configuration.
Finally, as the procedures were conceived to work inside a host program, it would be better that these
routines could be interrupted during their execution when an interrupt signal (internal or external) is gen-
TM
erated by the micro. At this end, the FUZZYSTUDIO
4.0 provides different ways to do this. See the doc-
umentation for major details about this.
5.1 Program WRITE
The main program sets the value for the auxiliary register REG_CONF4_IM (in our case we suppose that
the PORT_A is all configured as input) and, then, what has just to do is to provide the value for the variable
Address (from 0 to 255) and the value for the Data .
Then it calls the subroutine Write (Figure 8).
Figure 8. Data specification and call to “Write” subroutine
From the user point of view, the operation for writing into the memory is over.
Now, let us have a look as the Write subroutine is organized (Figure 9). First of all, the subroutine Start1
is called to begin the communication between the two devices. After that, the “ device selector ” is loaded
into the variable Byte (acting like a data source for the following subroutine) and then the subroutine
Write_Byte is called. To this part of code is demanded the actual transmission of each bit constituting the
data, generating the appropriate clock (SCL) and data bus (SDA) signals.
6/9

Related parts for AN1328