BASIC stamp manual v2.2
I2CIN – BASIC Stamp Command Reference
Page 218 • 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
Both 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
I2COUT
Table 5.32: I2CIN 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 I2CIN command allows
the BASIC Stamp to receive data from an I
2
C device.
The following is an example of the I2CIN command:
result VAR Byte
I2CIN 0, $A1, 0, [result]
This code will transmit a "read" command to an I
2
C device (connected to
I/O pins 0 and 1) and then will receive one byte and store it in the variable
result. Though it may seem strange, the I2CIN command first transmits
some data and then receives data. It must first transmit information (ID,
read/write and address) in order to tell the I
2
C device what information it
would like to receive. The exact information transmitted ($A1, 0) depends
on the I
2
C device that is being used.
The above example will read a byte of data from location 0 of a 24LC16B
EEPROM from Microchip. Figure 5.8 shows the proper wiring for this
example to work. The SlaveID argument ($A1) is both the ID of the chip
and the command to read from the chip; the 1 means read. The Address
argument (0) is the EEPROM location to read from.
A SIMPLE I2CIN EXAMPLE.
NOTE: The I2C command will make up
to 8 attempts to connect to the
addressed device. If the device does
not properly respond, the I2C command
will timeout and the InputData will
remain unchanged..