I2C Bus
[Serial Buses]

Introduction

This module makes the I2C bus available for writing and reading data to and from. The bus is configured at 400kbits/sec by default.

All data written to the transmit buffer is decoded by this module, and will generally instruct data to be written, or read from a I2C slave node. An ASCII text based message protocol is used.

Message Protocol

Currently the following commands are defined:
CommandFormatDescription
0-9
A-F
ASCII HEX A 8 bit value represented in ASCII HEX format.
S S Put a I2C Start condition on the bus.
P P Put a I2C Stop condition on the bus. This command returns the I2C bus to the idle state. You should always leave the bus in this state when finished with a command.
R Rnn Reads given number of bytes from I2C slave node. Where 'nn' gives number of bytes to read in a 2 digit value. For example, R05 will read 5 bytes from I2C bus. The I2C bus can not be idle when issuing this command, and must be preceded by a S (I2C Start Condition) command.
W Wxx Writes a single byte to the I2C bus. Where "xx" represents a byte in two-digit upper case hex format. For example, W1F will write 0x1F (31 decimal) to the I2C bus. The I2C bus can not be idle when issuing this command, and must be preceded by a S (I2C Start Condition) command.

Reading from I2C bus

Each I2C node actually has two addresses. The even address is used to write to the node, and the odd address to read from it. Bit 0 (R/W bit) of the address byte is used to determine if a read or write command has to be executed. If 1, a I2C read is executed. To read, set bit 0 of the address. For example, accessing address 0x20 will write to the node, and address 0x21 will read from it.

Examples

Following are some examples for communicating with nodes on the I2C bus.
Writing 0x10 to a I2C node with address 5A
S5A10P
<[I2C Start][Address:0x5A][Data:0x10][I2C Stop] This commands sends and I2C message, beginning with a I2C Start condition, and ending with an I2C stop condition.


Writing "Hello" to an I2C node with address 25
S2548656C6C6FP
<[I2C Start][Address:0x5A][Data:0x48, 0x65, 0x6C, 0x6C, ox6F][I2C Stop] This commands sends and I2C message, beginning with a I2C Start condition, and ending with an I2C stop condition. The ASCII string "Hello" is sent. Each character has to be sent with it's ASCII code.


Reading two bytes from an I2C node with address 51
S5102P
<[I2C Start][Address:0x51, R/W = Read][Number of bytes to read: 02][I2C Stop] This commands sends and I2C message, beginning with a I2C Start condition, and ending with an I2C stop condition. Two bytes are read from the I2C node with address 0x51 (or 0x50 for reading).


Repeated Start, write 1 byte (0x15), reading 3 bytes from an I2C node with address 2A (or 2B for writing)
S2A15 S2B03P
<[I2C Start][Address:0x2A, R/W = Write][Data: 0x15] [I2C Repeated Start][Address:0x2B, R/W = Read][Number of bytes to read: 03][I2C Stop] This commands uses the I2C repeated start feature. If a second start command is sent, without sending a stop command, it will cause a repeated start condition to be put on the I2C bus. A single byte is written to the I2C node with address 0x2A, and 3 bytes are read from the I2C node with address 0x2B.


Generated on Wed Feb 3 12:45:36 2010 for SBC65EC Web Server by  doxygen 1.5.8