BASIC stamp manual v2.2

I2COUT – BASIC Stamp Command Reference
Page 226 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Quick Facts
BS2p, BS2pe, and BS2px
Values for Pin
Pin = 0 Pin = 8
I/O Pin Arrangement
0: Serial Data (SDA) pin
1: Serial Clock (SCL) pin
8: Serial Data (SDA) pin
9: Serial Clock (SCL) pin
Transmission
Rate
Approximately 81 kbits/sec on a BS2p, 45 kbits/sec on a BS2pe,
and 83 kbits/sec on a BS2px (not including overhead).
Special Notes
The SDA and SCL pins must have 1 k - 4.7 k pull-up resistors.
The I2CIN command does not allow for multiple masters.
The BASIC Stamp cannot operate as an I
2
C slave device.
Related Command
I2CIN
Table 5.35: I2COUT Quick Facts.
Explanation
The I
2
C protocol is a form of synchronous serial communication developed
by Phillips Semiconductors. It only requires two I/O pins and both pins
can be shared between multiple I
2
C devices. The I2COUT command
allows the BASIC Stamp to send data to an I
2
C device.
The following is an example of the I2COUT command:
I2COUT 0, $A0, 5, [100]
This code will transmit a "write" command to an I
2
C device (connected to
I/O pins 0 and 1), followed by an address of 5 and finally will transmit the
number 100.
The above example will write a byte of data to location 5 of a 24LC16B
EEPROM from Microchip. Figure 5.11 shows the proper wiring for this
example to work. The SlaveID argument ($A0) is both the ID of the chip
and the command to write to the chip; the 0 means write. The Address
argument (5) is the EEPROM location to write to.
Vss
P1
Vdd
4.7 k
P0
24LC16B
(DIP)
4.7 k
SDA
SCL
1
2
3
4
8
7
6
5
Figure 5.11: Example Circuit for the
I2COUT command and a 24LC16B
EEPROM.
Note: The 4.7 k resistors are
required for the I2COUT
command to function properly.
A SIMPLE I2COUT EXAMPLE.