20.5.2 Communicating As a Host In a Single Host Environment
The I2C module’s typical operation in a system is using the I2C to communicate with an I2C peripheral, such as an I2C serial memory. In an I2C system, the host controls the sequence of all data communication on the bus. In this example, the dsPIC33AK128MC106 device and its I2C module have the role of the single host in the system. As the single host, it is responsible for generating the SCLx clock and controlling the message protocol.
The I2C module controls individual portions of the I2C message protocol; however, sequencing of the components of the protocol to construct a complete message is performed by the user software.
For example, a typical operation in a single host environment is to read a byte from an I2C serial EEPROM. Figure 20-6 illustrates the example message.
To accomplish this message, the user software will sequence through the following steps:
- Assert a Start condition on SDAx and SCLx.
- Send the I2C device address byte to the client with a write indication.
- Wait for and verify an Acknowledge from the client.
- Send the serial memory address high byte to the client.
- Wait for and verify an Acknowledge from the client.
- Send the serial memory address low byte to the client.
- Wait for and verify an Acknowledge from the client.
- Assert a Repeated Start condition on SDAx and SCLx.
- Send the device address byte to the client with a read indication.
- Wait for and verify an Acknowledge from the client.
- Enable the host reception to receive serial memory data.
- Generate an ACK or NACK condition at the end of a received byte of data.
- Generate a Stop condition on SDAx and SCLx.
The module supports Host mode communication with the inclusion of the Start and Stop generators, data byte transmission, data byte reception, Acknowledge generator and a BRG. Generally, the user software will write to a control register to start a particular step, then wait for an interrupt or poll status to wait for completion. These operations are discussed in the subsequent sections.