Interfacing techniques and questions on them
Can I Connect a Serial A/D to My Computer's Serial Port?
The answer to this question is yes, but there are simpler ways to interface to a computer. To begin with, the computer's RS-232 port uses higher voltage levels that are incompatible with most ADC's TTL/CMOS logic. Another problem is that the computer's RS-232 serial port is asynchronous, which places a few more requirements on the communication, including some additional handshaking control lines. Also, with the RS-232 serial port, you must set both ends of the link to the same baud rate. The A/D converter's serial port is synchronous; thus, its handshaking requirements are minimal and it only requires one wire for clock and one or two wires for data.
If you are truly determined, you can bit-bang using the RS-232 port's handshake lines.
What Is Bit-Banging?
Bit-banging is a method of using general-purpose I/O lines to emulate a serial port. Microcontrollers that include serial-port modules like SPI[tm] and I2C[tm] manage all synchronization and timing signals, and this activity is transparent to the user. With bit-banging, however, each write to the port causes a single transition at the port pin. And it's up to the user, first, to provide the correct number of transitions to obtain the desired waveform and, second, to ensure that the timing requirements (particularly setup and hold times for reading and writing data) are met. Due to the overhead associated with the number of writes to the port, though the actual port speed might be quite high the actual bit-bang throughput rate is usually very slow. This technique is very inefficient from a software perspective, but it may be acceptable in some applications where the communication overhead is acceptable (for example for doing occasional controlling communication).
Microwire and SPI versus I2C
SPI is a close cousin of the older Microwire. Both interfaces are very simple and basically consist only of an 8-bit serial shift register and (for master devices) a programmable shift clock. There is no means of addressing devices. Typical applications consist of one master device (usually a microcontroller) and one or multiple slave devices (usually peripheral functions, like A/D, EEPROM, display drivers, etc.).
I2C is quite a bit more complex than SPI and Microwire, which results in a larger silicon area and therefore slightly more expensive devices. In addition Philips is collecting licensing fees for I2C implementations from competitors, adding to the cost of I2C devices.
Connecting External Peripherals
There is a minimum of 3 connections for SPI and Microwire: serial clock, serial data out and serial data in. Therefore you'll see those interfaces sometimes referred to as 3-wire interfaces. The interconnected devices need to also share the same Vcc and GND of course and in the case of multiple connected devices you need one chip select for each connected slave device (for just one slave, the slave's chip select can be enabled all the time not recommended, but possible).
If you want to connect N devices to your microcontroller with Microwire or SPI you need to sacrifice 3+N pins to do the job. This is an area where I2C has an advantage. I2C features a 7-bit address as part of the protocol. As such I2C can address up to 128 devices on the bus without the need for dedicated chip select signals.
The Need For Speed
Microwire and SPI shine when it comes to speed. I2C was initially specified at a maximum speed of 100kbits/sec. This was later increased to 400kbits/sec and lately some devices started to show up that boast 1Mbits/sec. This still pales in comparison to Microwire and SPI speeds. SPI has the edge over Microwire, due to the availability of higher speed peripheral devices. Today's serial EEPROM for example support up to 3MBits/s for Microwire and up to 10Mbits/sec for SPI. But even the slowest Microwire and SPI peripherals still beat the typical 100 or 400kbit/s I2C speeds.
Increasing the speed gap is the fact that SPI and Microwire have fullduplex capability (can receive and send data at the same time), while I2C, due to its two-wire nature (one clock, one data) can only communicate half-duplex.
Why can speed be important? Current consumption for one - many microcontroller applications spend most of their time in power save modes and only short periods of time in "normal" operating mode. The faster a read or write operation to a peripheral can be completed, the shorter the time the controller needs to be active. This is especially true for access to large external EEPROM memories.
Multi-Master Systems
I2C offers better support for multi-master systems. The interface has built in arbitration to detect multiple devices sending on the bus at the same time and to give priority to the one that first sends a "0". Microwire would require some software implemented handshaking via a standard I/O pin to allow for multiple master devices on the bus. SPI has a crude way to support multi-master systems via its built in "fault logic". It can detect requests of devices to become the master via the dedicated SS (slave select) pin.
Noise Immunity
One possible disadvantage of I2C should not go unmentioned: Higher noise sensitivity and along with it lower data integrity. I2C uses a read/write bit which follows the initial 7 address bits to tell a peripheral whether data should be read or written. In addition I2C is level sensitive - in contrast to Microwire and SPI, which are edge sensitive. This means that I2C samples data during the high or low phase of a bit and you can easily envision that noise could flip the read/write bit. So if you wanted to read data from your external EEPROM, but noise turned your read bit into a write bit, your memory might get corrupted. Microwire and SPI peripherals on the other hand implement read and write operations via explicit commands send over the bus, making selecting the "wrong" operation less likely.
So which synchronous interface should you give the preference?
If you have many devices to connect and in addition have multiple microcontrollers in your system that can act as masters, then I2C is the interface of choice. The same holds true if you need to keep the number of interconnects, board routing and pins required for the interface to an absolute minimum. The I2C interface is very popular in video and audio applications, due to Philips' (microcontroller & application specific peripheral) dominance in those applications. If you develop such applications you might not find your desired peripheral function with any other interface.
If your main concerns are low cost, high speed or noise immunity, either Microwire or SPI are preferable. An added advantage is that MICROWIRE/PLUS microcontrollers can talk to SPI peripherals and SPI microcontrollers can talk to Microwire peripherals with minimum additional software overhead, which gives you a large selection of available peripherals to choose from for most applications.
(continued)