-
I2C-With the 24LC16B
Hi Guys!
I have a Pic 16C84 with a serial Eeprom 24LC16B.
I want to read the first 63 bytes and write it in the internel Eeprom
of my Pic.
My Programm:
include "modedefs.bas"
define OSC 4
B0 var byte
B1 var byte
B2 var byte
cont con %10100110
for b0=0 to 63
HIGH PORTB.4 'data pin
HIGH PORTB.5 'clock pin
Pause 50
LOW PORTB.4 'start signal for 24LC16B
I2cread PORTB.4,PORTB.5,cont,b0,B2
pause 50
write b0,b2
LOW PORTB.4 'stop signal for 24LC16B
next b0
end
This writes only "FF" in the internel Eeprom,
not my Data from the serial Eeprom!
Can you help me?
RON
-
what are your A0,A1,A2 settings... are they to ground?!? if so try this one
Code:
define OSC 4
B0 var word
B1 var byte
B2 var byte
cont con %10100000
b1=0
for b0=0 to 63
I2cread PORTB.4,PORTB.5,cont,b0,[b2]
write b1,b2
pause 50
b1=b1+1
next b0
-
Hi again!
yes,A0,A1,A2 are on ground.
but with your code,nothing happens.
with my code the pic reads "FF" in the internal eeprom
i have searched and posted in many forums last week,
but nobody can help me.
Please help me!
RON
-
well it's suppose to work... can you send your data to your PC or on a PORT and monitor that??? have you put 1k - 4k7 pull-ups on SDA & SCL pins ?!? Is by any chance you revert SDA & SCL pins?!?
-
Be sure you have the WP (pin #7) tied to ground, and pull-up
resistors on SDA & SCL (pins #4 & #5)
A0, A1 and A2 are not used on the 24LC16B, so you can leave
these pins (#1,#2,#3) floating.
The control byte consists of a 4-bit control code of %1010 which
remains constant.
The next 3-bits in the control byte are the "block select bits".
These can be from %000 to %111 for blocks 0 to 7 (8 blocks total).
Note that these 3-bits are the high-order "address" bits, so you do
not follow the control byte with a word sized variable for the address
of this EEPROM. The upper 3-bits of the word address are the lower
nibble bits 1,2,3 in the control byte.
The last bit of the control byte is for read or write, but PBP will
automatically flip this bit for you.
So, the control byte can be from %1010 000 0 to %1010 111 0 to
access blocks 0 to 8. The low-order address byte can be from 0-255.
Code:
B0 var byte
B1 var byte
B2 var byte
Cont con %10100110 ' Control 1010 + block #3 address 011
SYMBOL SDA = PORTB.4 ' Data pin
SYMBOL SCL = PORTB.5 ' Clock pin
Main:
FOR B0=0 to 63 ' Locations 0 to 63 = 64 bytes
B1=B0+4 ' Write address + 4 to each location
I2cWrite SDA,SCL,Cont,B0,[B1] ' Cont + B0 = word address
PAUSE 10 ' Pause for writes
NEXT B0
FOR B0=0 to 63 ' Locations 0 to 63 = 64 bytes
I2cRead SDA,SCL,Cont,B0,[B2] ' Cont + B0 = word address
WRITE B0,B2
NEXT B0
Display:
FOR B0 = 0 to 63
READ B0,B2
HSEROUT ["ADD: ",DEC B0," VAL: ",DEC B2,13,10]
NEXT B0
Here: GOTO Here
-
24lc16b
Hi again!
Thank you for your code example.
But it still don't works.Sorry for that!
Here is a Picture of my connections:
http://www.xg-midifiles.de/24LC16B.jpg
I use OSC=RC in my programmer settings.
I can't understand wy it don't works.
By'e
RON
-
we already told it but...you didn't place any pull-up resistor on the SDA and SCL pin...1.8k-4.7k
the internal one will never give you good results if you're using them.
-
24lc16b
Hi!
I have WP on Ground and pull up SDA and SCL.
Here a picture:
http:www.xg-midifiles.de/24LC16B.jpg
But nothing happen's!
When i write the serial Eeprom with the loader.hex then it works great.
But with your(my) program it doesn't.(WHY?)
By'e
Ron
-
O.K.... your connections are not correct.
A pull-up resistor must be connected between the EEPROM pin and +5V.
look to your PBP manual in the I2Cread and i2CWRITE section.
-
24lc16b
Hi again!
Sorry,i have tested my connections and they must be correct.
Because i have found a hexfile(loader.hex).
And when i burn it in my Pic,My Pic read 's and write's the 24LC16B perfect.
Here are my original Connections:
http://www.xg-midifiles.de/24LC16B.jpg
(I have made an Error,sorry for that)
So it MUST be a Software Error!
My Problem is,i have only this hexfile(that work's perfect).
But i want to write my own Program with PBP.
I have try many Sample Codes not only your's.
And i have read many Tutorials also the Datasheed's(but if you think,
then i will read them again)
My Question is:
Wy work's this hexfile perfect and all sample Code written with PBP
does not?
By'e
RON
-
Are you 100% sure you're setting your config fuse for RC_OSC before programming your PIC?
The RC values shown in your schematic should give you roughly 4MHz, but don't count on super accurate timing with any external RC osc circuit.
You could also try substituting a 10K pot for the fixed 5K resistor you have now. You can tweak the potentiometer to fine tune your RC osicllator circuit until you get it close enough to 4MHz for the I2CWrite & I2CRead timing to work.
Of course, you could always drop in a 4MHz crystal or resonator, and be done with it.
The pull-up resistors, as mentioned previously, would also be a nice twist if you're getting tired of fighting this thing. Your manual shows you the super simple pull-up resistor circuit. It really does make a difference.