can any one help me to interface 24c04 external memory to pic16f887

Thread Starter

nnnnnnn

Joined May 29, 2009
15
this is my example code i cannot able to get the data on hyperterminal.....pls check the code
#use i2c(master, sda=PIN_C4, scl=PIN_C3)
#use rs232(baud=9600, xmit=pin_c6,rcv=pin_c7)
void main()
{
int data=0,data1=8;

output_b(0x00);
output_low(pin_c3);
output_high(pin_c4);
i2c_start();
output_low(pin_c2);
i2c_write(0x00);address to external eeprom
delay_ms(100);
i2c_write(8); data to the 0x00 th location
delay_ms(100);
data=i2c_read(0);
delay_ms(100);
i2c_stop();
while(1)
{
putc(data);
delay_ms(1000);
puts("hai");
output_b(data);
delay_ms(1000);
}
}
 

AlexR

Joined Jan 16, 2008
732
If you want help you should make it easier for people to read and understand your problem.

Use the advanced formatting option and enclose your code in the code tags (#) to preserve the code formatting.

Give details of what language and compiler you are using.

Give detail of what parts work and what parts don't work, also any error messages that occur during assembly and linking.

A circuit of your PIC connections would also help to eliminate any hardware issues.
 

russ_hensel

Joined Jan 11, 2009
825
what compiler are you using? does it compile fine? do you have any code to test the rs232 ( no ). make sure it is working first. have you ever compiled anything that worked ( what ).
 

Thread Starter

nnnnnnn

Joined May 29, 2009
15
sorry sir...i'm using ccs compiler, clanguage.. i compiled sucessufully no error occured..what data i required i cannot get that... i'm using pic16f887 ...
controller pin 23 portc c4is sda i connected to sda of 24c04 is pin
contoller pin 18 portc c3 is scl i connected to scl of 24c04
i connected wp write protect of 24c04 pin to controller c2 and gave low signal to it
 

AlexR

Joined Jan 16, 2008
732
What are your fuse settings?
What oscillator are using internal/crystal?, frequency?
Where do you tell the compiler your clock speed?, for that matter where do you tell it the PIC type?
Is MCLR pin pulled high?
How are you connecting to the PC? A circuit diagram would help.

Try getting the PIC to PC link working without the I2C code and EEPROM. Once it works and you see data coming into your Hyperterm then you can worry about the EEPROM
 

Thread Starter

nnnnnnn

Joined May 29, 2009
15
i'm using 4mhz crystal......no i have not pulled MCLR PIN HIGH.....i'm new to microcontroller.....why i should pull out high the mclr pin sir.....
at first seperately serial communication is working when i add i2c code its not working....
now i can write and read the data of external eeprom in hyperterminal but problem is i can write and read only on 0x00 address
i cannot not write and read in other locations

thanks in advance
 

GetDeviceInfo

Joined Jun 7, 2009
2,192
Assuming your I2C protocol is operable, you cannot do a write / read (or vise versa) in one operation. You must readdress the device, with the appropriate r/w bit set. When you perfrom an operation at some location, if successful, the device autoincrements, so you would need to readdress the device to return to the last location.
 

Thread Starter

nnnnnnn

Joined May 29, 2009
15
alberto sir.
i can able to read/write 0x00 address sucesfully.......mclr pin is pulled out with resistor sir .........but i can'nt able to read other adress sucesfully ......help me out sir
thanks regards......
thnaks for replying my questions......
 

Thread Starter

nnnnnnn

Joined May 29, 2009
15
getdeviceinfo sir..
ya i changed oxoo to 0x01 when i change address its not get write in eeprom i can sucessuflly read and write in 0x00 address
 

GetDeviceInfo

Joined Jun 7, 2009
2,192
if in fact you can write/read the first location, then I would try a sequential write/read. The code as you've posted it will not work, so I assume that was just an summary. Care to post the actual code that write/reads the one location?
 
Top