I2C Questions
I'm trying to write to an eeprom with Mike Green's Minimal I2C routines (I know there are several thread's about this, my question is different though).· Basically, I have never used I2C before, and am quite confused about many of the terms.· In the "I2Cwritepage" routine the following terms are used; i2cSCL, i2cAddr, addrReg, dataPtr, and count.· Can someone post a definition of these terms?··In fact, just explaining I2C would be great.
Thanks,
Craig
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
Thanks,
Craig
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
Comments
You only need to google "I2C specification" and you will find the information on the first link. The names of the routines should always be self-explanatory if you understand what needs to be achieved. Also download the datasheet on the eeprom so you can understand the writepage operation as well.
Take note that I2C is really a very simple protocol if you only consider it in the context of single master as it is generally used. Multiple master I2C is used where multiple micros may share the same I2C peripherals and need to be able to handle conflicts, but don't worry about that.
RTM RTM RTM
*Peter*
i2cAddr I think I now call devSel and is the basic device select code (usually provided in the datasheet for the device). For EEPROMs, it's normally $A0.
The Basic I2C routines take care of the I2C protocol details in terms of addressing the device, sending any EEPROM address bytes, re-addressing the device if you're trying to read from it, and transferring possibly multiple data bytes.
Can these be mixed? Say 2 devices that are 3 bit address:
%000
%001
%010
then a 2 bit addressed device:
%11
and a 4th device at 4 bits
%0100
If it does not see it's own device type, will it ignore the start byte which may contain 2, 3, or 4 bit addresses?
I had just done up a rather involved explanation of the use of device addresses + modifier bits but then my browser crashed.
I think you are getting confused with the use of n-bit addresses as this is referring to the pins that allow you to select the lsbs of a fixed device address. Eeproms such as the 24LC256 will have a 3-bit chip address input that can modify the base address from $A0 to $AE. The lsb is not actually an address bit but a read/write select. Each and every I2C device must end up (your responsibility) with a unique address otherwise you will have contention. Does that sort of answer your question?
*Peter*
1. Start bit (i2cStart(SCL))
2. 4 bit binary control code
3. 3 bit binary chip select (A0, A1 A2)
4. Read/Write bit
5. Acknowledgement bit
I'm guessing data comes after the acknowledgement bit.
Anyway, for a 2 byte pagewrite to the boot eeprom and the last internal data address, I think·it would be like this:
i2cSCL - 28
i2cAddr - $A0
addrReg - %0000111111111111111 ($7FFF = %0111111111111111)
dataPtr - @variable
count - 2
Question: Do I have to use the binary internal address, can I put it in hexidecimal instead?· ($7FFF instead of %0111111111111111)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NerdMaster
For
Life
Post Edited (crgwbr) : 3/10/2007 1:30:56 PM GMT
What you've got looks like it would work except that you're trying to write 2 bytes to the last data address (it'll wrap around to the start of the last "page"). Don't forget to either wait 5ms after the write or use writeWait to make sure the write has completed before you try to write anything else or read from the EEPROM. Regarding the binary vs. hexadecimal question. The Spin compiler translates all numbers into the same 32 bit numeric values regardless of whether they're written in decimal, binary, hexadecimal or 2-bit form (%%2310).
For data address, use $7FFE with a count of 2.
Again, the I2C object takes care of the start condition, sending the proper device address when it needs to be sent (including the read/write bit), any address or data bytes, and the stop condition.
By the way, don't include the read/write bit in the device address byte ... the routines do that for you.
Post Edited (Mike Green) : 3/10/2007 3:44:29 PM GMT
What I notice about the address byte is, it has a 5 bit device length versus 4 on the EEPROM.
This leads me to belive that it can be used with the EEPROM lines, since they have adjusted the device type bit length to compensate for the shorter address bits.
focus.ti.com/lit/ds/symlink/ads7828.pdf
Post Edited (originator) : 3/10/2007 7:30:41 PM GMT
If you look at the upper 4 bits for different kinds of devices, they have different codes. EEPROMs are $Ax, the I/O expanders are $40 or $70. The A-D/D-As as you've noticed are $90. This is done so the devices can be mixed. Your ADC can be used with an EEPROM.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Typical 27lc256 eeprom write and read access.
The datasheet does detail this in timing diagrams but maybe this makes it a bit easier to see for some. Hope it helps.
*Peter*
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Paul, in the case of the expander, that is a very good point, since the PCF8575 has an Interrupt output that fires on any received input to the ports (if in the correct mode). A simple Spin waitpne that starts a Read on the I2C bus could be fast enough. My guess is that the from the time a trigger happens, and the INT hits the Propeller that initiates the read, the info shoud still be present when it gets read.