Motherboard Forums


Reply
Thread Tools Display Modes

i2c coding problem

 
 
tanu
Guest
Posts: n/a
 
      09-18-2006, 12:33 PM
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 <mega128.h>

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

#endasm
#include <i2c.h>
#include <delay.h>
// 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 With Quote
 
 
 
 
Dan Henry
Guest
Posts: n/a
 
      09-20-2006, 12:27 AM
On 18 Sep 2006 05:33:09 -0700, "tanu" <(E-Mail Removed)> wrote:

>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 ?
>

===SNIP===
>/* write a byte to the EEPROM */
>void eeprom_write(unsigned char EEPROM_BUS_ADDRESS,unsigned char
>address, unsigned char data)

===SNIP===
>void main(void)
>{

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

===SNIP===
^^^^^^ ^^^^

I smell fish.


--
Dan Henry
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
I2C high speed mode and I2C range extending Michael Embedded 1 06-14-2007 07:29 PM
Devantech USB-I2C R286-USB-I2C board mInfo Embedded 0 02-16-2007 10:57 PM
I2C - Do i need to check all the states of I2C bus? abhay Embedded 3 02-01-2007 03:47 PM
NVIDIA GeForce Settings by VB6 Coding like TVTool blackmagicinc@gmail.com Nvidia 0 12-10-2005 03:57 AM
Coding in bios Sankar-R MSI 0 06-22-2004 01:40 PM


All times are GMT. The time now is 01:49 AM.


Welcome!
Welcome to Motherboard Point
 

Advertisment