View previous topic :: View next topic |
Author |
Message |
ali6094
Joined: 31 Jan 2007 Posts: 18
|
24C256 help |
Posted: Thu Mar 29, 2007 10:30 am |
|
|
i am using pic16F877A with 24c256
and has the following configuration
for 24c256 ic
PIN 1 to 4 ground
Pin 5 SDA to PIN_E2 of PIC
Pin 6 SCL to PIN_E0 of PIC
Pin 7 to ground
PIN 8 to +5V
No capacitors and resistors
used the following ammendment in 24C256
Code: |
#ifndef EEPROM_SDA
#define EEPROM_SDA PIN_E2
#define EEPROM_SDA_TRIS TRISE2
#define EEPROM_SCL PIN_E0
#define EEPROM_SCL_TRIS TRISE0
#endif
|
only used the three routines in the main programme
i.e.
init_ext_eeprom()
write_ext_eeprom(a, d)
d = read_ext_eeprom(a)
where am i doing wrong ?
how can i check if my EEPROM is working fine? |
|
|
Guest
|
|
Posted: Thu Mar 29, 2007 10:40 am |
|
|
you forgot the pull up resistors from SDA and SCL to VCC.... try 10k each |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
Re: 24C256 help |
Posted: Thu Mar 29, 2007 2:09 pm |
|
|
ali6094 wrote: | i am using pic16F877A with 24c256
and has the following configuration
for 24c256 ic
PIN 1 to 4 ground
Pin 5 SDA to PIN_E2 of PIC
Pin 6 SCL to PIN_E0 of PIC
Pin 7 to ground
PIN 8 to +5V
No capacitors and resistors
where am i doing wrong ?
how can i check if my EEPROM is working fine? |
Pull up resistors are REQUIRED on the SDA and SCL pins. 2K to 10K is generally acceptable for a 5V system, depending on how fast you expect to run.
Also you really should have some bypass caps. 100nF and 10uF at the PIC and another 100nF at the eeprom. You might be able to use 10nF instead of 100nF depending on the quality of your supply. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
ali6094
Joined: 31 Jan 2007 Posts: 18
|
|
Posted: Fri Mar 30, 2007 11:01 am |
|
|
with pull u mean a resistor betwwen +5V and pin 5 and 6?
what u mean by capacitors at pic and eeprom, which PINS?.. mysupply is 5V pretty much fine and i am using capacitor with the regulator IC. which gives 5V |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Fri Mar 30, 2007 12:03 pm |
|
|
Yes.
You must have a ~4.7K resistor between SDA and 5.0V and
you must have a ~4.7K resistor between SCL and 5.0V.
(Without these I2C WILL NOT WORK.)
Also,
The EASIEST way to avoid problems is decouple the power supply at every chip. ALWAYS.... ALWAYS..... ALWAYS put a 0.1uF cap between 5.0V and ground as close to the power supply pin of every chip.
Good luck,
John |
|
|
ali6094
Joined: 31 Jan 2007 Posts: 18
|
|
Posted: Sat Mar 31, 2007 7:26 am |
|
|
I did the resistors and the capacitor. Now I think that the read function is fine but I am only getting one constant line but it is not writing the data.
What to do next I don't know...
How can I clear the EEPROM and how can I test as if it is working fine?
Plz check my code if every thing is right as posted above. |
|
|
jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sat Mar 31, 2007 8:01 am |
|
|
Quote: | i did the resistors and the capacitor |
Should be capacitorS.... You need a 0.1uF at the EEPROM and at the PIC.
Post a short, but complete program that you have compiled and tested that suffers from the problems you describe. To test the EEPROM only about 20 lines of code should be necessary.
John |
|
|
ali6094
Joined: 31 Jan 2007 Posts: 18
|
|
Posted: Sat Mar 31, 2007 8:17 am |
|
|
well i am using a graphic LCD and receiving input from a potentiometer and have to draw a graph on the LCD...
i used the internal EEPROM of PIC and every thing worked fine and i am getting fine
how ever i need more data to store...so i interfaced the 24c256... here is the code i am using
Code: |
#include "PIC16F877A.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP, NOPUT, NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "t6963.c"
#include "24256.c"
unsigned int depth = 0;
unsigned int ie_value = 0;
unsigned int ie_value_old = 0;
unsigned int adc_value = 0;
unsigned int adc_value_old = 0;
unsigned int int_counter = 0;
unsigned int depth_counter = 0;
int1 data_end = 0;
float temp;
unsigned int i;
#int_timer1
isr_timer1()
{
set_timer1( 0x88a5 );
if( !TRIGGER && !data_end )
{
if( int_counter > 31 )
{
int_counter = 0;
adc_value = read_adc();
write_ext_eeprom( depth_counter, adc_value );//<-- if i use only write_eeprom(depth, counter it is working fine)
depth_counter++;
if( depth_counter > 254 ) { data_end = 1; }
}
else { int_counter++; }
adc_value_old = adc_value;
}
}
void main( void )
{
set_tris_a( 0xff );
set_tris_c( 0xbf );
set_tris_e( 0xff );
GDispInit();
init_ext_eeprom();//<-- this i dont need to use in case of PIC`s eeprom
FontSize = 8;
GDispSetMode( XOR_MODE );
GDispSetMode( GRAPHIC_ON );
GDispClrGrh();
setup_adc_ports( AN0 );
setup_adc( ADC_CLOCK_INTERNAL );
set_adc_channel( 0 );
setup_timer_1( T1_INTERNAL );
enable_interrupts( INT_TIMER1 );
enable_interrupts( GLOBAL );
while( 1 )
{
if( !TRIGGER && !data_end )
{
if( depth < depth_counter )
{
ie_value = read_ext_eeprom( depth ) / 1.3;//<-- for PIC`s eeprom i used read_eeprom
}
}
}
|
this code is working for internal eeprom bur not external i.e. 24C256 and the pins i defined in 24256.c as described earlier
Last edited by ali6094 on Sun Apr 01, 2007 12:31 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 31, 2007 12:40 pm |
|
|
Quote: | #ifndef EEPROM_SDA
#define EEPROM_SDA PIN_E2
#define EEPROM_SDA_TRIS TRISE2
#define EEPROM_SCL PIN_E0
#define EEPROM_SCL_TRIS TRISE0
#endif
this code is working for internal eeprom bur not external i.e. 24C256 and
the pins i defined in 24256.c as described earlier
|
Where does this 24256.c driver come from ? You have #define
statements for the TRIS. Those statements are not in any CCS eeprom
driver that I know of. I know they're not in vs. 3.249. I installed vs.
4.030 and did a text search on all drivers, and they're not in there either.
I did a web search for "EEPROM_SDA_TRIS" and got no hits.
Conclusion: You have either written your own driver or have modified
the CCS driver.
You should use the CCS driver. It's in this folder:
c:\Program Files\Picc\Drivers\24256.c |
|
|
Guest
|
|
Posted: Sat Mar 31, 2007 1:14 pm |
|
|
yes before the file was like this
Code: | #ifndef EEPROM_SDA
#define EEPROM_SDA PIN_E2
#define EEPROM_SCL PIN_E0
#endif |
i modified it to like this
#ifndef EEPROM_SDA
#define EEPROM_SDA PIN_E2
#define EEPROM_SDA_TRIS TRISE2
#define EEPROM_SCL PIN_E0
#define EEPROM_SCL_TRIS TRISE0
#endif
so i can revert back with pinEO and E2 like
#ifndef EEPROM_SDA
#define EEPROM_SDA PIN_E2
#define EEPROM_SCL PIN_E0
#endif
But still no results ...
i think the read function is working as it is giving a constant out put but write function is not working...[/code] |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 31, 2007 1:42 pm |
|
|
My advice is to make a simple test program that only tests the ability
to write and read from the 24256 eeprom.
Try the test program shown below. Use the CCS driver. Don't use
your driver.
It should display this on your terminal window:
If it doesn't work, it means there is probably something wrong with
your hardware. For example, you may have forgotten to connect
pull-up resistors on the SDA and SCL lines.
Code: |
#include <16F877A.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define EEPROM_SDA PIN_E2
#define EEPROM_SCL PIN_E0
#include <24256.c>
//=====================================
void main()
{
printf("Start\n\r");
init_ext_eeprom();
write_ext_eeprom(0, 0x55);
write_ext_eeprom(1, 0xAA);
printf("%x ", read_ext_eeprom(0));
printf("%x", read_ext_eeprom(1));
while(1);
} |
|
|
|
Guest
|
|
Posted: Sat Mar 31, 2007 2:24 pm |
|
|
the out pput i am receiving with this programme is
" Start
00 00"
this means we are not reading right and we dont know if we are writing ok or not....
Also i used one 4.7 K both at SCA and SCL lines .. used a 10 uf capacitor at pin8 of 24c256 ...with pic i am already using the capacitors...i dont know what is the problem ...
i checked resistance at different points but every thing seems to be fine.... |
|
|
ali6094
Joined: 31 Jan 2007 Posts: 18
|
|
Posted: Sat Mar 31, 2007 2:49 pm |
|
|
i think i am reading fine
but unable to write data on 24C256..
so what to do next... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 31, 2007 3:13 pm |
|
|
What is your compiler version ? |
|
|
ali6094
Joined: 31 Jan 2007 Posts: 18
|
|
Posted: Sat Mar 31, 2007 3:35 pm |
|
|
its 3.224 |
|
|
|