How dose I2c work?
ThePenguinMaster
Posts: 89
OK so I have been learning about I2c communication and there are a few things I am unsure about how this works with the propeller. I understand the timing aspects of it, how you have a clock and a data line and by raising and lowering the line voltage you can send a start command, an address that includes a read or write bit, and then the stop condition. What I am unsure of is do I need a pull-up resistor? I think I might prefer this because it is standard. Also the start command says to bring SDA high while SCL is set low, but the biggest thing I am unsure about is how do you set the line high and low if you are using a pull-up resistor? Would I set the direction register in or out and then would I set it to one or zero? It is the simple things that I am getting stuck on, but any help would be appreciated. I have looked at the I2c driver but I am unsure if it is written to be used with a pull up resistor or not. Also I would prefer not to use the existing i2c driver because I want to write a version of my own for a specific application. And thanks for the patience with my basic questions.
Comments
What sort of specific application do you have in mind?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Quit buying all those fixed voltage regulators, and·get an Adjustable Power Supply·for your projects!· Includes an LED testing terminal!
If it doesn't assume a pull-up then outa[noparse][[/noparse]sda] :=0, dira[noparse][[/noparse]sda]:=1 for low and outa[noparse][[/noparse]sda]:=1,dira[noparse][[/noparse]sda]:=1 for high.
If you look at any of the existing I2C drivers, you'll see that the SDA pin output register bit is set to 0 (low) and the direction register bit is switched from 0 (input mode) to allow the pull up to produce a high (1) to 1 (output mode) to allow the output driver to pull the line down (low).
The Basic_I2C_Driver in the Object Exchange is really simple and should serve as an example of how to do I2C using Spin.
I can't recommend strongly enough that you use a working I2C driver as your model. There are several in the Object Exchange. Unless you are quite expert, it will save you much grief. Once you get your system basically working, you can always rewrite it from scratch with your own driver to do exactly what you want.
If you read the comments in "Basic_I2C_Driver", you'll see that it's intended to work whether or not the pullup is present on SCL.
Remember though that I2C only transports your data to and from the I2C chip, it's up to you to read the chip's datasheet properly to determine what you need to read/write and how. It's not black magic so just be methodical about it and first determine that the chip is responding and build it up from there.
*Peter*