dsPIC30F Family Reference Manual
DS70068C-page 21-24 © 2004 Microchip Technology Inc.
21.5.7 Building Complete Master Messages
As described at the beginning of Section 21.5, the software is responsible for constructing
messages with the correct message protocol. The module controls individual portions of the I
2
C
message protocol, however, sequencing of the components of the protocol to construct a
complete message is a software task.
The software can use polling or interrupt methods while using the module. The examples shown
use interrupts.
The software can use the SEN, RSEN, PEN, RCEN and ACKEN bits (Least Significant 5 bits of
the I2CCON register) and the TRSTAT bit as a “state” flag when progressing through a message.
For example, Table 21-2 shows some example state numbers associated with bus states.
Table 21-2: Master Message Protocol States
The software will begin a message by issuing a Start command. The software will record the state
number corresponding to Start.
As each event completes and generates an interrupt, the interrupt handler may check the state
number. So, for a Start state, the interrupt handler will confirm execution of the Start sequence
and then start a master transmission event to send the I
2
C device address, changing the state
number to correspond to master transmission.
On the next interrupt, the interrupt handler will again check the state, determining that a master
transmission just completed. The interrupt handler will confirm successful transmission of the
data, then move on to the next event, depending on the contents of the message.
In this manner, on each interrupt, the interrupt handler will progress through the message
protocol until the complete message is sent.
Figure 21-15 provides a more detailed examination of the same message sequence of
Figure 21-7.
Figure 21-16 shows some simple examples of messages using 7-bit addressing format.
Figure 21-17 shows an example of a 10-bit address format message sending data to a slave.
Figure 21-18 shows an example of a 10-bit address format message receiving data from a slave.
Example
State Number
I2CCON<4:0>
TRSTAT
(I2CSTAT<14>)
State
0 00000 0 Bus Idle or WAIT
1 00001 n/a Sending Start Event
2 00000 1 Master Transmitting
3 00010 n/a Sending Repeated Start Event
4 00100 n/a Sending Stop Event
5 01000 n/a Master Reception
6 10000 n/a Master Acknowledgement
Note: Example state numbers for reference only. User software may assign as desired.