We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to write some bytes of data on EEPROMs, and later retrieve the data using at89s51/52. How I2C communication can be established to do this task? I need the C help for generating timing signals, writing to eeprom and reading from eeprom for interfacing 24C02 with at89s52.
I mistakenly re-posted because I'm discussing for first in this site. WELL I WAS NOT SHOUTING! and here is my code, I found similar type of code in a site and edited in my way and tried to save the data from a port and send the saved the data to other port. But not working...# simulated in ISIS proteus 7.1...
#include <reg52.h> #include<intrins.h> //to use no operation #define data P2 sbit scl=P1^3; sbit sda=P1^4; bit ack; void delay(unsigned char n) // delay function approx. for about 1ms { unsigned char i; TMOD=0x01; for(i=0; i<=n; i++) { TH0 = 0xFC; TL0 = 0x18; TR0 = 1; while(TF0==0); TR0 = 0; TF0 = 0; } } void aknowledge() //acknowledge condition { scl=1; _nop_(); _nop_(); scl=0; } void start() //start condition { sda=1; scl=1; _nop_(); //No operation provides a very small delay _nop_(); sda=0; scl=0; } void stop() //stop condition { sda=0; scl=1; _nop_(); _nop_(); sda=1; scl=1; } void send_byte(unsigned char value) //send byte serially { unsigned int i; unsigned char send; send=value; for(i=0;i<8;i++) { sda=send/128; //extracting MSB send=send<<1; //shiftng left scl=1; _nop_(); _nop_(); scl=0; } ack=sda; //reading acknowledge sda=0; } unsigned char read_byte() //reading from EEPROM serially { unsigned int i,reead=0; sda=1; for(i=0;i<8;i++) { reead=reead<<1; scl=1; _nop_(); _nop_(); if(sda==1) reead++; scl=0; } sda=0; return reead; //Returns 8 bit data here } void save(unsigned char num) //save in EEPROM { start(); send_byte(0xA0); //device address aknowledge(); send_byte(0x00); //word address aknowledge(); send_byte(num); //send data aknowledge(); stop(); } unsigned char read(void) { unsigned char i; start(); send_byte(0xA0); aknowledge(); send_byte(0x00); aknowledge(); start(); i=read_byte(); aknowledge(); stop(); aknowledge(); return i; } void main() { while (1) { save(data); // save the value at Port 2 delay(10); P3=read(); // Send the saved value at Port 3 delay(10); } }
Yes, you were: http://www.keil.com/forum/21474/
Writing in ALL UPPERCASE is SHOUTING!
post what difference you have seen by comparing what you see on your scope with what the standard states.
expecting someone to (for free) wade through 100 lines of code is a bit much. you need to do the 'narrowing' of the problem yourself.
Erik
The major problem I faced is to generate appropriate timing signals for I2C Communication.. at least I am in search of an algorithm for managing all the timing signals... Thank You
But don't _all_ code/articles about I2C cover the timing?
Timing isn't an issue as long as you don't try to do it too quickly.
another one of those wonderful OPs that, instead of answering a question bing up something different
The major problem I faced is to generate appropriate timing signals for I2C Communication
that can not possibly be the problem, as long as I²C timing is slow enough it can be NOT be too long.
if timing is suspected just go dead slow, you can always try to go faster.