|
|
View previous topic :: View next topic |
Author |
Message |
Einly Guest
|
24LC64 External EEPROM- PIC16f876 |
Posted: Mon Jul 14, 2003 5:44 am |
|
|
Dear sir,
I am currently trying to write and read data to 24LC64 using PIC 16f876. However, I was unsuccessful to do it. First, I write data 0x05 to address 0 of the EEPROM. Then, I read the data from the address (0) to verify whether I have successfully written to address 0, & whether I could be able to read from the eeprom.
I have connected SDA line of the EEPROM to Pin C5 & SCL line of the EEPROM to Pin C4. Vss to ground, Vcc to 5V & control line to 0,0,0. The result is shown by using 8 LEDs connected to Port B.
Below is the program that I have written.
#include <16f876.h>
#use delay(clock=20000000)
#fuses hs, noprotect, nowdt, nolvp
#define EEPROM_CLK PIN_C4
#define EEPROM_DAT PIN_C5
#byte PORTA=5
#byte PORTB=6
#byte PORTC=7
#byte tris_c=0x87
void write();
void read();
void all();
int i;
byte status;
byte control;
byte address[2];
byte data;
int data2;
byte value;
void main()
{
set_tris_b(0);
portb=0xA0;
delay_ms(1000);
portb=0xff;
delay_ms(1000);
portb=0;
bit_clear(tris_c,4);
bit_clear(tris_c,5);
output_high(EEPROM_DAT);
delay_us(3);
output_low(EEPROM_CLK);
delay_us(3);
output_high(EEPROM_CLK);
delay_us(10);
output_low(EEPROM_DAT);
delay_us(10);
write();
bit_clear(tris_c,5);
output_low(EEPROM_DAT);
delay_us(3);
output_low(EEPROM_CLK);
delay_us(3);
output_high(EEPROM_CLK);
delay_us(10);
output_high(EEPROM_DAT);
delay_us(10);
delay_ms(1000);
bit_clear(tris_c,4);
bit_clear(tris_c,5);
output_high(EEPROM_DAT);
delay_us(3);
output_low(EEPROM_CLK);
delay_us(3);
output_high(EEPROM_CLK);
delay_us(10);
output_low(EEPROM_DAT);
delay_us(10);
portb=0x01;
read();
bit_clear(tris_c,5);
output_low(EEPROM_DAT);
delay_us(3);
output_low(EEPROM_CLK);
delay_us(3);
output_high(EEPROM_CLK);
delay_us(10);
output_high(EEPROM_DAT);
delay_us(10);
portb=data2;
delay_ms(1000);
portb=0x03;
delay_ms(1000);
}
void write()
{
control=0xA0;
address[1]=0;
address[0]=0;
data=5;
value=control;
all();
value=address[1];
all();
value=address[0];
all();
value=data;
all();
}
void read()
{
control=0xA1;
address[1]=0;
address[0]=0;
value=control;
all();
value=address[1];
all();
value=address[0];
all();
bit_set(tris_c,5);
delay_ms(100);
for(i=1;i<=8;i++)
{
output_low(EEPROM_CLK);
delay_us(2);
output_high(EEPROM_CLK);
shift_left(&data2,1,input(EEPROM_DAT));
delay_us(2);
}
}
void all()
{
status=0;
bit_clear(tris_c,5);
for(i=1;i<=8;i++)
{
output_low(EEPROM_CLK);
delay_us(2);
output_bit(EEPROM_DAT,shift_left(value,1,0));
delay_us(2);
output_high(EEPROM_CLK);
delay_us(4);
}
bit_set(tris_c,5);
output_low(EEPROM_CLK);
delay_us(4);
output_high(EEPROM_CLK);
delay_us(4);
while(status==0)
{
if(input(PIN_C5)==0)
{
status=1;
}
}
}
May I know is my program wrong? Thanks in advance.
Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515944 |
|
|
Pete Smith Guest
|
Re: 24LC64 External EEPROM- PIC16f876 |
Posted: Mon Jul 14, 2003 6:15 am |
|
|
:=Dear sir,
:=
:=I am currently trying to write and read data to 24LC64 using PIC 16f876. However, I was unsuccessful to do it. First, I write data 0x05 to address 0 of the EEPROM. Then, I read the data from the address (0) to verify whether I have successfully written to address 0, & whether I could be able to read from the eeprom.
:=
:=I have connected SDA line of the EEPROM to Pin C5 & SCL line of the EEPROM to Pin C4. Vss to ground, Vcc to 5V & control line to 0,0,0. The result is shown by using 8 LEDs connected to Port B.
Hi.
Couple of points
1) Why aren't you using the built in CCS functions? They're there, and they work perfectly well in my experience. You then don't have to worry about getting the low level stuff working. On the F876 (and any PIC with a hardware UART), the code size will be smaller, because the hardware takes care of the big banging for you.
2) Have you got 2.2k (around) pull up resistors, connecting SDA and SCL to VCC?
3) It might be worth getting a MAX202/MAX232 and some capacitors, and building a TTL to RS232 line driver. This way, you can send meaningful debug messages to a PC, rather than having to debug your program using LEDs.
HTH
Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515947 |
|
|
Einly Guest
|
Re: 24LC64 External EEPROM- PIC16f876 |
Posted: Wed Jul 16, 2003 12:44 am |
|
|
Dear sir,
Thanks for ur help.
May I know which built in CCSC functions do u mean? Do you have any examples of code that I can refer to u? Is it read_ext_eeprom(d)... In the CCSC manual, I came across this. But there are 2 lines for data & 1 line for clock. For the EEPROM that I m using now (24LC64), there is only 1 data line & 1 clock line. May I know how should I write for EEPROM_DI & EEPROM_DO? Can the built in functions for any external EEPROM (eg. 24LC64)?
Thanks in advance:-)
Einly
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516044 |
|
|
Pete Smith Guest
|
Re: 24LC64 External EEPROM- PIC16f876 |
Posted: Wed Jul 16, 2003 1:45 am |
|
|
:=Dear sir,
:=
:=Thanks for ur help.
:=
:=May I know which built in CCSC functions do u mean? Do you have any examples of code that I can refer to u? Is it read_ext_eeprom(d)... In the CCSC manual, I came across this. But there are 2 lines for data & 1 line for clock. For the EEPROM that I m using now (24LC64), there is only 1 data line & 1 clock line. May I know how should I write for EEPROM_DI & EEPROM_DO? Can the built in functions for any external EEPROM (eg. 24LC64)?
The file you're looking at there uses SPI to communicate. This isn't the same as I2C.
Look at ex_extee.c
It's a little confusing, because they're taking data in from the serial port, but the file you actually want is 2402.c. This is a driver for a 2402. You're using a 2464, so they should be almost compatible.
I've checked the documentation for the 24C64, and the only modifications you may have to do to change the 2402 drive to a 2464 driver, is make sure that you're passing the full 13 bits of address data.
As an example, to write to the 2402
i2c_start();
i2c_write(0xa0);
i2c_write(address);
i2c_write(data);
i2c_stop();
delay_ms(11);
AFAIK, to interface the 2464, you'd have to do something like this...
i2c_start();
i2c_write(0xa0);
i2c_write(MSB_address);
i2c_write(LSB_address);
i2c_write(data);
i2c_stop();
delay_ms(11);
It's as simple as that. You don't need to worry about bit banging & start/stop conditions, you just issue the commands, and it does it.
Take a close look at your manual, at the sections devoted to I2C, and all should become apparent.
HTH
Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516048 |
|
|
Guest
|
Re: 24LC64 External EEPROM- PIC16f876 |
Posted: Thu Oct 06, 2005 8:53 am |
|
|
Pete Smith wrote: | :=Dear sir,
:=
:=I am currently trying to write and read data to 24LC64 using PIC 16f876. However, I was unsuccessful to do it. First, I write data 0x05 to address 0 of the EEPROM. Then, I read the data from the address (0) to verify whether I have successfully written to address 0, & whether I could be able to read from the eeprom.
:=
:=I have connected SDA line of the EEPROM to Pin C5 & SCL line of the EEPROM to Pin C4. Vss to ground, Vcc to 5V & control line to 0,0,0. The result is shown by using 8 LEDs connected to Port B.
Hi.
Couple of points
1) Why aren't you using the built in CCS functions? They're there, and they work perfectly well in my experience. You then don't have to worry about getting the low level stuff working. On the F876 (and any PIC with a hardware UART), the code size will be smaller, because the hardware takes care of the big banging for you.
2) Have you got 2.2k (around) pull up resistors, connecting SDA and SCL to VCC?
3) It might be worth getting a MAX202/MAX232 and some capacitors, and building a TTL to RS232 line driver. This way, you can send meaningful debug messages to a PC, rather than having to debug your program using LEDs.
HTH
Pete.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515947 |
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Oct 06, 2005 9:04 am |
|
|
Do you just like quoting old posts! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|