So let's take a look at the possibilities of the Arduino to communicate with other ICs:
- You can communicate using digital pins. You'll have to write code to HIGH/LOW them according to the protocol. This will take a long time and a lot of useful digital pins.
- Of course we have Serial/USB, enabling the Arduino to communicate with your PC or other arduinos. Not really easy and won't allow sketch uploads to your Arduino until you reset.
- Dallas one-wired interface allows you to communicate with other ICs that support it. Will require a digital pin.
- I2C is more common, and the Arduino supports it nicely.
So how does I2C work? The protocol requires a master IC and one or more slaves. I2C has two wires required for communication: a data and a clock. The master will provide the clock (required for the other IC's to be able to tell when to read the data pin). Both wires should be hooked up with the volt supply with a 4.7 KOhm resistor. This is because when not sending data the line should be HIGH. When an IC decides to send data, it will pull down the data line to LOW (0) or leave it at HIGH (1) for one clock cycle. Each slave will have an address on which it will listen for data.
The Arduino allows you to hook up many devices with I2C and can operate in master or slave mode using the supplied wire.h addition. Using analog pin 4 and 5 to hook up the Arduino, it will allow you to use all the 13 digital pins for other use.
By calling
Wire.begin();in the setup function you can start using I2C.
When you need to send data call to start transmission
Wire.beginTransmission(address);send data using
Wire.send (data)and end the transmission with
Wire.endTransmission();. What data you need to send depends on what the other IC is expecting. I2C only defines the protocol to send data. You can also read data from other devices with the Arduino, but how depends also on what th slave device is expecting.
So that's the theory. Please check next time on how to put it into practice.
Geen opmerkingen:
Een reactie posten