Specifications

114
3706C–MICRO–2/11
AT89LP3240/6440
Figure 18-10. Interfacing the Application to the TWI in a Typical Transmission
1. The first step in a TWI transmission is to transmit a START condition. This is done by
writing a specific value into TWCR, instructing the TWI hardware to transmit a STA RT
condition. Which value to write is described later on. However, it is important that the
TWIF bit is cleared in the value written. The TWI will not s
tart any operation as long as
the TWIF bit in TWCR is set. Immediately after the application has cleared TWIF, the
TWI will initiate transmission of the START condition.
2. When the START condition has been transmitted, the TWIF flag in TWCR is set, and
TWSR 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 TWSR, to make sure that the
START condition was successfully transmitted. If TWSR 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 TWDR.
Remember that TWDR is
used both for address and data. After TWDR has been
loaded with the desired SLA+W, a specific value must be written to TWCR, instructing
the TWI hardware to transmit the SLA+W present in TWDR. Which value to write is
described later on. However, it is important that the TWIF b it is cleared in the value writ-
ten. The TWI will not start any operation as long as the TWIF bit in TWCR is s
et.
Immediately after the application has cleared TWIF, the TWI will initiate transmission of
the address packet.
4. When the address packet has been transmitted, the TWIF flag in TWCR is set, a nd
TWSR is updated with a status code indicating that the address packet has success-
fully been sent. The status code will als
o reflect whether a slave acknowledged the
packet or not.
5. The application software should now examine the value of TWSR, to make sure that the
address pa cket was successfully transmitted, and that the value of the ACK bit was as
expected. If TWSR indicates otherwise, the application software might take some spe-
cial action, like calling
an error routine. Assuming that the status code is as expected,
the application must load a data packet into TWDR. Subsequently, a specific value
must be written to TWCR, instructing the TWI hardware to transmit the data packet
present in TWDR. Which value to write is described later on. However, it is important
that the TWIF bit is cleared in the valu
e written. The TWI will not start any operation as
START SLA+W A Data A STOP
1. Application writes
to TWCR to initiate
transmission of
START
2. TWIF set.
Status code indicates
START condition sent
4. TWIF set.
Status code indicates
SLA+W sent, ACK
received
6. TWIF set.
Status code indicates
data sent, ACK received
3. Check TWSR to see if START was
sent. Application loads SLA+W into
TWDR, and loads appropriate control
signals into TWCR, making sure that
TWIF is written to zero and
STA is written to zero.
5. Check TWSR to see if SLA+W was
sent and ACK received.
Application loads data into TWDR,
and loads appropriate control signals
into TWCR, making sure that
TWIF is written to zero.
7. Check TWSR to see if data was sent
and ACK received. Application loads
appropriate control signals to send
STOP into TWCR, making sure that
TWIF is written to zero.
TWI bus
Indicates
TWIF set
Application
Action
TWI
Hardware
Action