BS2p I2C device problem!
Sunzt
Posts: 9
I have a BS2px and i"m trying to read and write to some flash NVRAM using I2C. I looked all over the forums and some of the Nuts and Volts articles about I2C, but I still cannot get my RAM to work! Everytime I read from memory it's always 255 (FFFF) at each location!!!
Here's the specs on the RAM, it's a 512k Ferro-Magnetic Ram:
http://ramtron.com/lib/literature/datasheets/FM24C512ds_r1.0.pdf
I put 5.1k pull-up resistors (only had 5.1k's around) on the SDA and SCL line. I made sure the SDA connects to pin 8 and SCL connects to pin 9. I checked both the SDA and SCL line with an oscilloscope and the voltages act like information is going through the lines as I run the read and write code. It has power with Vdd = 4.97V. I'm not sure if there's anything wrong with my code. I tried writing with letters and numbers, but I always read back 255. Any help you guys might have would be greatly appreciated.
Here's the code I'm using for Writing:
Idx VAR Word
Main: 'Writes Flash Mem
DEBUG CR, "MemWrite", CR
PAUSE 1000
FOR Idx = 0 TO 32767 'Writes lower half of memory, which ends at 7FFF
I2COUT 8, $A0, Idx.HIGHBYTE\Idx.LOWBYTE, [noparse][[/noparse] 3 ] 'Writes Memory starting at Address 0
DEBUG "Addr: ", HEX4 Idx,
NEXT
Code for Reading:
MemValue VAR Byte
Idx VAR Word
Main: ' Reads flash memory
DEBUG CR, "MemRead", CR
PAUSE 1000
FOR Idx = 0 TO 32767 'reads lower half of memory, which ends at 7FFF
I2CIN 8, $A1, Idx.HIGHBYTE\Idx.LOWBYTE, [noparse][[/noparse]MemValue] 'Reads bytes of Memory starting at Address 0
DEBUG "Addr: ", HEX4 Idx, " " MemValueL: ", DEC MemValue, CR
NEXT
Post Edited (Sunzt) : 3/18/2007 1:18:20 AM GMT
Here's the specs on the RAM, it's a 512k Ferro-Magnetic Ram:
http://ramtron.com/lib/literature/datasheets/FM24C512ds_r1.0.pdf
I put 5.1k pull-up resistors (only had 5.1k's around) on the SDA and SCL line. I made sure the SDA connects to pin 8 and SCL connects to pin 9. I checked both the SDA and SCL line with an oscilloscope and the voltages act like information is going through the lines as I run the read and write code. It has power with Vdd = 4.97V. I'm not sure if there's anything wrong with my code. I tried writing with letters and numbers, but I always read back 255. Any help you guys might have would be greatly appreciated.
Here's the code I'm using for Writing:
Idx VAR Word
Main: 'Writes Flash Mem
DEBUG CR, "MemWrite", CR
PAUSE 1000
FOR Idx = 0 TO 32767 'Writes lower half of memory, which ends at 7FFF
I2COUT 8, $A0, Idx.HIGHBYTE\Idx.LOWBYTE, [noparse][[/noparse] 3 ] 'Writes Memory starting at Address 0
DEBUG "Addr: ", HEX4 Idx,
NEXT
Code for Reading:
MemValue VAR Byte
Idx VAR Word
Main: ' Reads flash memory
DEBUG CR, "MemRead", CR
PAUSE 1000
FOR Idx = 0 TO 32767 'reads lower half of memory, which ends at 7FFF
I2CIN 8, $A1, Idx.HIGHBYTE\Idx.LOWBYTE, [noparse][[/noparse]MemValue] 'Reads bytes of Memory starting at Address 0
DEBUG "Addr: ", HEX4 Idx, " " MemValueL: ", DEC MemValue, CR
NEXT
Post Edited (Sunzt) : 3/18/2007 1:18:20 AM GMT
Comments
-Phil
In looking through the documentation it appears the address lines and WP are internally pulled down. This is not the same as internally grounded since that suggests they cannot be changed. In any event it appears your code should work but I wonder if you’re sure of the pins you’ve connected to. Surface mount parts can be tricky, even to find pin 1 sometimes. As for I2C speed, the BS2px is well below the 1 MHz rating for this part. These numbers (speeds) are located in the Help File and the BASIC Stamp Manual under the I2CIN/I2COUT commands. Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support