i2c usage on the Propeller
CumQuaT
Posts: 156
Hi all,
Does anyone know of a good place to learn the basics of interacting with an i2c device? I'd like to use one of the LiPo Fuel Gauges and RTC Modules from Sparkfun with my Prop, but I don't know the first thing about reading and writing i2c, or how it all works. Can anyone give me a push in the right direction as I'd very much like to learn.
Thanks in advance.
Does anyone know of a good place to learn the basics of interacting with an i2c device? I'd like to use one of the LiPo Fuel Gauges and RTC Modules from Sparkfun with my Prop, but I don't know the first thing about reading and writing i2c, or how it all works. Can anyone give me a push in the right direction as I'd very much like to learn.
Thanks in advance.
Comments
Maybe if you tell us what you are familiar with and we can explain I2C in relation to what you know rather than what we know or assume you know.
I don't even know where to begin with i2c... I have a LiPo fuel gauge from Sparkfun, but I don't know where to begin when it comes to getting the information out of it. Doing some reading I've found things about needing addresses and reading pages and so on and so forth, and none of it really makes sense... In serial a device simply broadcasts and receives information upon request, but i2c seems to be more complicated.
So when it comes to what I mean by "basics" i really mean "from the start".
Thanks for that, but I've given that a go and it makes no sense to me. It goes into addresses and such and I don't know what address to use for the things I am connecting to...
Well you're familiar with sending data over serial by which I take it you mean "asynchronous" serial, that is in this case meaning that no clock is used between the two ends although clocks are still required.
Now this may be long winded but let's see if you grasp any of it first.
Shift registers are just a chain of flip-flops registers that remember the data bit that was at it's input when the clock went from low to high. So it's a one bit memory. The trick is that these flip-flops output that bit only when the clock goes from high to low. So you see if you chain the output of the first one into another one and so on and then join the clock lines together the bit on the very first input will seem to shift across from register to register. If you have eight of these cascaded together then if you input a new bit of data every time the clock went from low to high then you could store 8 bits of data in this "shift register".
If you can preload each individual register with 8 bits then apply 8 clock pulse you will see each bit appear on the output of the last stage bit by bit with every pulse. This is basically the way we can transmit serial data and as explained previously also the way we receive serial data.
The serial stuff that you are familiar with is much more complicated as it needs to reconstruct the exact same clock at the receive end just by knowing the speed and synchronizing with the data bits.
I2C just sends out packets of 8 bits (bytes) of data strung together but preceded by a simple START condition where normally both the clock and data lines are idling high and when the data goes from high to low while the clock is high then this is interpreted as a start condition. Normally the data line remains stable while the clock is high. So the very first 8 bits after the START happens to be a device address which selects a particular chip. There may be more bytes of data which this device will accept which in the case of EEPROMs would include a memory address and data because.....it's a memory chip.
Confusing? soak it up and then ask some questions and we can fine tune it.
BTW. you could simulate the I2C transmission just by using 2 push-buttons and two LEDs on the I2C line. It would be slow but you would see what was happening every time you push a button.