I2C on Raisonance's C Compilers

This article is on the implementation of the I2C protocol. The I2C specification has been defined very well on many web pages and in Philips Semiconductor data sheets, and thus will be discussed very little here. It is assumed the HW is properly attached to dedicated IO pins on an 8051 derivative micro.

Many of the low cost 8051 devices do not have a built-in I2C bus controller, thus programmers are forced to manually "bit bang" their data out to I2C devices. Specifically, this article is about an implementation of a bit-banged master-slave I2C bus with the 8051 as the master, and it assumes that the slave device(s) does not request to have service performed.

Many implementations can be found on the web for doing an I2C master/slave bus. The ones I have investigated are all complete, but are either far more complex than needed, are very inefficient, or have both of these disadvantages. Also, some of the examples are in assembly. While an assembly-based driver is fine, it can be harder to maintain, especially as assembly programming becomes a lost art form and many colleges have removed many (or all) assembly classes from their requirements.

Code and RAM space are VERY valuable when you are working with memory-limited micros such as the 8051, particularly when they are implemented on cost-sensitive products. While modern C compilers can produce code rivaling the size of the best assembly code (the Raisonance family of 8051 tools contains the best code optimizer I have seen), highly optimized code can be time consuming to debug. For this reason, writing efficient C code to start with may reduce the need for using the optimizer.

View Entire Paper | Previous Page | White Papers Search

If you found this page useful, bookmark and share it on: