1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

i2c coding problem

Discussion in 'Embedded' started by tanu, Sep 18, 2006.

  1. tanu

    tanu Guest

    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
     
    tanu, Sep 18, 2006
    #1
    1. Advertising

  2. tanu

    Dan Henry Guest

    On 18 Sep 2006 05:33:09 -0700, "tanu" <> 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
     
    Dan Henry, Sep 20, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sankar-R

    Coding in bios

    Sankar-R, Jun 22, 2004, in forum: MSI
    Replies:
    0
    Views:
    328
    Sankar-R
    Jun 22, 2004
  2. Replies:
    0
    Views:
    368
  3. abhay
    Replies:
    3
    Views:
    429
    Roland Zitzke
    Feb 1, 2007
  4. mInfo
    Replies:
    0
    Views:
    463
    mInfo
    Feb 16, 2007
  5. Michael
    Replies:
    1
    Views:
    410
    Jim Granville
    Jun 14, 2007
Loading...

Share This Page