I2C (also: I2C) is a circuit arrangement and communication protocol. It allows one or more processors to communicate with one or more special-purpose ICs using a single pair of wires. A group of wires for communication is called a bus, and so this pair is called an I2C bus.
The simpletools library has functions for common I2C tasks. The Propeller microcontroller “master” orchestrates communication with I2C device “subordinates.” Here, we’ll prototype some code to talk with the 64 KB I2C EEPROM built into the Propeller Activity Board (original or WX version). The simpletools library already has functions to do just that, but this activity will give you a starting point for prototyping with other I2C devices that do not already have library support.
Need a quick way to save data to your Activity Board’s EEPROM (original or WX version)? Try these simpletools functions: ee_putByte, ee_getByte, ee_putInt, ee_getInt, ee_putFloat32, ee_getFloat32, ee_putStr, and ee_getStr.
Need more I2C options? The simplei2c library provides access to lower-level communication details with more flexibility. In SimpleIDE, click Help and select Simple Library Reference. Propeller GCC has even more I2C functions with advanced features and faster communication rates.
Many Propeller development boards already have a 64 KB I2C EEPROM connected to P28 and P29:
- Activity Board or Activity Board WX (#32910, #32912)
- Propeller BOE (#32900)
- QuickStart (#40000)
- Propeller Project Board (#32810)
If you are using a different Propeller board, you will need:
- 24FC512 EEPROM
If the EEPROM circuit is already built into your Propeller development board, you are good to go. Just use the code examples as-is with SCL = P28 and SDA = P29.
If you are using a different Propeller set-up, connect the 24FC512 EEPROM using the schematic shown below. You can use a different pair of I/O pins (other than P28 and P29). Just make sure to update the code examples to reflect the different pair of pins.
Let’s look at the connections that the EEPROM on the Propeller Activity Board (original or WX version) needs, in addition to Vcc (3.3 V) and Vss (0 V).
Address pins A2…A0
Each subordinate device on an I2C bus needs its own address. The lowest three digits in EEPROM’s address are determined by applying voltage to the address pins: 3.3 V = 1, and 0 V = 0. In our example, A2...A0 are connected to ground, so those digits will be 000. Up to eight similar EEPROMs could be placed on the same I2C bus, each with a different pattern of 3.3 V and 0 V applied to A2…A0.
The I2C bus’ SCL (serial clock) line is used to coordinate communication between devices. The EEPROM’s SCL pin connects Propeller I/O pin P28. A pull-up resistor holds the voltage on the SCL line at Vdd (3.3 V in our example below) when no devices are talking.
The SDA (serial data) line is used to transmit data from one device to another. The EEPROM’s SDA pin connects Propeller I/O pin P29. The SDA line also has a pull-up resistor.
WP stands for write protect, and when it is enabled with a high signal, the data stored inside the EEPROM cannot be changed. Since it is receiving a GND (0 V) low signal here, write protect is disabled. To enable write protect, you could change that connection to 3.3 V.