English
Language : 

AT89LP51IC2_14 Datasheet, PDF (143/254 Pages) ATMEL Corporation – 8-bit Microcontroller Compatible with 8051 Products
AT89LP51RB2/RC2/IC2 Preliminary
interrupt request. If the TWE bit is cleared, the application must poll the SI flag in order to detect
actions on the TWI bus.
When the SI flag is asserted, the TWI has finished an operation and awaits application
response. In this case, the TWI Status Register (SSCS) contains a value indicating the current
state of the TWI bus. The application software can then decide how the TWI should behave in
the next TWI bus cycle by manipulating the SSCON and SSDAT registers.
Figure 19-10 is a simple example of how the application can interface to the TWI hardware. In
this example, a Master wishes to transmit a single data byte to a Slave. This description is quite
abstract, a more detailed explanation follows later in this section. A simple code example imple-
menting the desired behavior is also presented.
Figure 19-10. Interfacing the Application to the TWI in a Typical Transmission
1. Application writes
to SSCON to initiate
transmission of
START
3. Check SSCS to see if START was
sent. Application loads SLA+W into
SSDAT, and loads appropriate control
signals into SSCON, making sure that
SI is written to zero and
STA is written to zero.
5. Check SSCS to see if SLA+W was
sent and ACK received.
Application loads data into SSDAT,
and loads appropriate control signals
into SSCON, making sure that
SI is written to zero.
7. Check SSCS to see if data was sent
and ACK received. Application loads
appropriate control signals to send
STOP into SSCON, making sure that
SI is written to zero.
TWI bus
START
SLA+W
A
Data
A
STOP
2. SI set.
Status code indicates
START condition sent
4. SI set.
Status code indicates
SLA+W sent, ACK
received
6. SI set.
Status code indicates
data sent, ACK received
Indicates
SI set
1. The first step in a TWI transmission is to transmit a START condition. This is done by
writing a specific value into SSCON, instructing the TWI hardware to transmit a START
condition. Which value to write is described later on. However, it is important that the SI
bit is cleared in the value written. The TWI will not start any operation as long as the SI
bit in SSCON is set. Immediately after the application has cleared SI, the TWI will initi-
ate transmission of the START condition.
2. When the START condition has been transmitted, the SI flag in SSCON is set, and
SSCS is updated with a status code indicating that the START condition has success-
fully been sent.
3. The application software should now examine the value of SSCS, to make sure that the
START condition was successfully transmitted. If SSCS indicates otherwise, the appli-
cation software might take some special action, like calling an error routine. Assuming
that the status code is as expected, the application must load SLA+W into SSDAT.
Remember that SSDAT is used both for address and data. After SSDAT has been
loaded with the desired SLA+W, a specific value must be written to SSCON, instructing
the TWI hardware to transmit the SLA+W present in SSDAT. Which value to write is
described later on. However, it is important that the SI bit is cleared in the value written.
The TWI will not start any operation as long as the SI bit in SSCON is set. Immediately
after the application has cleared SI, the TWI will initiate transmission of the address
packet.
3722A–MICRO–10/11
143