I2C Networking
An Autumn 2001 CSE466 Project by Mike Fernandes and Shirley Gaw

Home I2C Details Application Details Links

 

Project Objectives

Our goal was to implement writing shared variables for shared memory on multiple devices.  We wanted the devices to communicate with each other using the I2C protocol.

Project Implementation

Network Topology: I2C

I2C is a broadcast topology network, like Ethernet. Any node may connect to any other node in the network. Each node is a device, such as a microprocessor like the Atmel 89C55 (aka the 8051).

Unlike Ethernet, the bus is controlled in a master/slave connection. Any node may gain control of a free bus and become the master of the bus. A master may send two types of I2C messages: reads from a slave and writes to a slave. Messages are passed in a simple byte acknowledgement protocol, that is, each byte sent is acknowledged by the receiver.

We used a Philips PCF8584 I2C Bus Controller to abstract the details of the I2C protocol, leaving the 8051 to implement sending and receiving master to slave write messages through a PCF8584. This means the master is always a transmitter and the slave is always a passive receiver.

The master transmission procedure call implementation follows the protocol outlined in Figure 6 (Master transmitter mode) of the PCF8584 specification. The slave receiver interrupt handler implementation follows the basic portions of the slave receiver protocol outlined in Figure 9 (Slave  receiver/slave transmitter modes) of the PCF8584 specification. Because we did not implement master to slave read messages through the PCF8584, our implementation of the slave receiver mode interrupt handler does not perform checks such as asking if the node was addressed as a slave, if the node's own address was accessed correctly, and if the message was a read or a write before reading the byte received in the I2C controller buffer. 

To use the I2C controller, you need to initialize the bus controller following the procedure outlined in Figure 5 (PCF8584 initialization sequence), which we implement in our I2C interface.

Details on using our I2C bus controller interface are found here.

Application: Serial Chat Program and Shared Memory

Our project implements a message passing system.  We implemented the I2C bus controller interface (effectively datalink/physical layers) and then built an application that handled the low level details of message passing (effectively the transport, session, and application layers all together).

A node on the network is the collection of a serial port terminal window for text viewing (optional), an 8051 for application processing , and a bus controller for I2C handling.

Each node on the network has an array of variables ("shared variables") which may be accessed by other nodes on the network.  Each node acts as an owner for a fixed sized set of variables.  The number of shared variables available for access by other nodes is then proportional to the number of nodes on the network. 

Locally, the node may perform three operations: HELP, ZERO, VIEW, and buffer dump.  HELP displays the commands available in the application in the terminal window.  ZERO resets the values of all of the owner's shared variables to zero.  VIEW displays the value of each of the owner's shared variables in the terminal window.  Buffer dump shows the details of the last message received in the terminal window: what is the type of the message, who is the sender, and what is the message payload.

Our system supports a maximum of twenty-six 8051 processors.  On the network, the node may perform four operations: PING, CHAT, READ, and WRITE.  PING is a network polling command which attempts to send an "Are you alive?" message to each of the twenty-six possible nodes. CHAT sends an application message to another node, which appears in the node's terminal window. READ requests for the value of a shared variable on another node.  This is a timed request which displays the shared variable value if the node responded before the timeout or an error message if it did not.  WRITE requests to change the value of a shared variable on another node.  This is a best effort service, meaning the application does not guarantee or  acknowledge the request was granted.

Our application communicated to the computer terminals via serial I/0.  We implemented printf and scanf-like functions to abstract the details of handling serial I/O interrupts. 

Details on how to use the serial I/O interface, how to use this application, and how the application was implemented are here.

Project Details

To recreate our project, build the circuit below:


Just repeat this setup to add more nodes to the network, connecting each node to the network via the SDA and SCL lines of the I2C bus.  If you want to understand how to build on the I2C interface on the 8051 we implemented, you'll find it here along with the source files of the implementation.  We describe how to use our application here.  You will also find an implementation description of the program and source files.

Here are all of our source files:

Functionality Source Files
I2C bus controller interface
I2C.h
I2C.c
Serial I/O interface
Serial.h
Serial.c
Main Program
main.c
Shared Memory/Chat Application
SharedMemory.h
SharedMemory.c

 

For more information about the tools we used, check out the links page.

Project Extensions

Now that the I2C bus controller interface is implemented, it is easy to think of more projects that could extend from ours.

Implement the network stack.  Now the the hardware part is completed, future projects can use materials they already know how to use (the 8051 and Keil Development System) to develop on our interface.

Implement a different shared memory model.  In lecture, Professor Arnstein described a shared memory model where nodes declare and subscribe to variables.  Each node has its own local copy of the shared variables.  Updates of the variable depend if we are using a copy-on-read or a copy-on-write strategy to reduce the network traffic, which is described in Trade-offs of Shared Memory implementation lecture.

Last year, another team worked on a I2C network chat program with a Visual Basic serial port interface.  We'd suggest building from our I2C bus controller interface and serial port interface to make a better UI for a chat program.
Use our bus controller interface to configure the digital camera (the lab has a RoboCam Camera).  The camera is configured using the I2C protocol.