PDA

View Full Version : I2C EEPROM PASM Driver (AT24C512, etc)



Cluso99
01-21-2009, 02:22 PM
I am writing the I2C code to read and write the AT24C512 (or others) on the Prop Proto Board for use with the (thread)...

Post Boot PASM COG Loader?·· http://forums.parallax.com/showthread.php?p=776824

Can anyone answer the following question:

Before using the eeprom, I think it wise to ensure the eeprom is in a proper initialisation state. This can be achieved by sending 9 clocks (SCL) and checking if the SDA is high while SCL is high. Code I have seen truncates the number of clocks when SDA returns high. Then a START condition is sent. The data sheets do not spell out an answer to my question. Is there anything wrong with continuing the full 9 clocks? I believe this will not cause a problem, and if so I can considerably shorten my code by reusing a routine.

FYI: I have parameterised the driving of the I2C so the page size is set by the user program. When done I will post the code here. http://forums.parallax.com/images/smilies/cool.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439

My cruising website http://www.bluemagic.biz

Cluso99
01-21-2009, 07:39 PM
Further investigation reveals that the data being read from the eprom should be sampled while SCL is high, although I note Chip's code samples just prior to SCL being raised high. The AT24C512 datasheet show that the timings are still being met if SDA is sampled just before SCL goes high.

There also seems to be an extra clock required to allow for SDA to be placed low (as it ends high for NO ACK) during the next SCL low, in order for the STOP command to be issued (SDA goes high after SCL goes high).

Also, SCL should be open drain like SDA. Chip's code and the Basic_I2C_driver in the Obex drive the SCL both high and low (instead of using dira).

I would like to get it right, so does anyone have any experience they can shed???

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Prop Tools under Development or Completed (Index)
http://forums.parallax.com/showthread.php?p=753439

My cruising website http://www.bluemagic.biz

Cluso99
01-21-2009, 10:51 PM
Here is untested code based on my previous post. It takes about $50 longs for instructions plus buffer. Currently I am only doing read.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Links to other interesting threads:

· Prop Tools under Development or Completed (Index) (http://forums.parallax.com/showthread.php?p=753439)
· Emulators (Micros eg Altair, and Terminals eg VT100) - index (http://forums.parallax.com/showthread.php?p=778427)

My cruising website is ·www.bluemagic.biz (http://www.bluemagic.biz)

virtuPIC
01-22-2009, 06:49 AM
As I understand the Atmel AT24C512 datasheet you only need to tick SCL until SDA reacts. But then you have to send a start condition.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets (http://www.airspace-v.com/ggadgets) for tools & toys

Carl Jacobs
01-22-2009, 07:51 AM
Cluso99, Just a couple of notes:

1) You probably don't have to worry about initialising the EEPROM chip. By the time you get to it, it's already done! If not, then the Propeller probably would not have got as far as it did.

2) The timing of Chip's read is fogiven by the fact that the Propeller is SOOO much faster than I2C clocking rates - 20Mhz as opposed to 100kHz or 400kHz.

3) It is generally okay to drive the SCL line in both directions, as the Propeller is always going to be the I2C master (the master drives the clock). Now if ever the Propeller becomes an I2C slave, or other devices are going to talk amongst themselves on the I2C bus then this assumption is no longer valid. Strictly speaking, the pullup resistor could probably be omitted on SCL for most Propeller applications, although it does help define pre-boot conditions.

Regards,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Carl Jacobs


JDForth - Forth to Spin Compiler http://www.jacobsdesign.com.au/software/jdforth/jdforth.php
Includes: FAT16 support for SD cards. Bit-bash Serial at 2M baud. 32-bit floating point maths.·Fib(28) in 0.86 seconds. ~3x faster than spin, ~40% larger than spin.