I2CIN - BASIC Stamp Command Reference
Page 138
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
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.6 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.
The I2CIN command's InputData argument is similar to the SERIN
command's InputData argument. This means data can be received as
ASCII character values, decimal, hexadecimal and binary translations and
string data as in the examples below. (Assume the 24LC16B EEPROM is
used and it has the string, "Value: 3A:101" stored, starting at location 0).
A
SIMPLE
I2CIN
EXAMPLE
.
R
ECEIVING FORMATTED DATA
.
Figure 5.6: Example Circuit for the
I2CIN command and a 24LC16B
EEPROM. Note: The 4.7 K
Ω
Ω
resisters are required for the
I2CIN command to function
properly.
Vss
P1
Vdd
4.7 k
Ω
P0
24LC16B
(DIP)
4.7 k
Ω
SDA
SCL
1
2
3
4
8
7
6
5
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...