i2c coding problem

Hi all I am using ATmega128 controller and using i2c bus eeprom to increase its memory space . I have i2c header file in my codevision avr and i used them and change that accordingly but when i m reading my eeprom i m geting nothing i think that my code is either not able to generate the clock pulse or not able to write the data into eeprom i m not getting ,how to genrate the clk ?

#include

// I2C Bus functions port D #asm .equ __i2c_port=0x12 .equ __sda_bit=1 .equ __scl_bit=0

#endasm #include #include // Declare your global variables here /* read a byte from the EEPROM */

unsigned char eeprom_read(unsigned char EEPROM_BUS_ADDRESS , unsigned char address) { unsigned char data; i2c_start(); i2c_write(EEPROM_BUS_ADDRESS); i2c_write(address); i2c_start(); i2c_write(EEPROM_BUS_ADDRESS | 1); data=i2c_read(0); i2c_stop(); return data; }

/* write a byte to the EEPROM */ void eeprom_write(unsigned char EEPROM_BUS_ADDRESS,unsigned char address, unsigned char data) { i2c_start(); i2c_write(EEPROM_BUS_ADDRESS); i2c_write(address); i2c_write(data); i2c_stop(); /* 10ms delay to complete the write operation */ delay_ms(10); }

unsigned char eeprom *ptrom; void main(void) { unsigned char i;

// Declare your local variables here

// I2C Bus initialization i2c_init();

ptrom=0x0000;

/* write the byte 55h at address AAh */ eeprom_write(0x0182,0x00aa,0x43);

PORTB=0X00; delay_ms(500); PORTB=0XFF; delay_ms(500); /* read the byte from address AAh */ i=eeprom_read(0x0182,0x00aa);

*ptrom=i; // Place your code here

while (1) {

}; }

need ur help thanx

Reply to
tanu
Loading thread data ...

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.