This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

I2C on 89C669

Hi

I Have problem to run the I2C on 89c669.

// function init_i2c
// initializes the I2C peripheral
void init_i2c(void)
{
P1 |= 0xC0; // set P1.6 and P1.7 open drain
TMOD |= 0x01; // timer 0 mode 1
EI2C = 1; // enable I2C interrupts
EA = 1; // global interrupt enable
}

// function rtc_write_byte
// stores a byte in a specific register in the Real Time Clock
// passed is the register address and the byte to store
// nothing is returned
// result of the operation is stored in i2c_status and may be
// I2C_OK or I2C_ERROR
void rtc_write_byte(unsigned char address, unsigned char byte)
{
i2c_storage_address = address; // copy the register address
i2c_byte = chartobcd(byte); // convert to BCD and copy the byte
i2c_status = I2C_BUSY; // I2C is now busy
i2c_operation = WRITE; // a write operation is being performed
I2CON = 0x40; // enable the I2C perhiperal
// no acknowledgements will be returned
I2CON |= 0x20; // request a start condition is transmitted
// therefore putting I2C perhiperal in Master Transmitter mode
while(i2c_status == I2C_BUSY); // wait until I2C is not busy
}

and after that i wait for an Interrupt.
But nothing happens.

I've changed my sfr to
sfr I2ADR = 0x94;
sfr I2CON = 0x91;
sfr I2DAT = 0x93;
sfr I2CLH = 0x96;
sfr I2CLL = 0x95;
sfr I2STA = 0x92;

Need help please.

/Ingo

  • My best suggestion (I used it for the 668) is to use codearchitect (http://www.esacademy.com) which will generate the code for a LPC932.

    It is very simple to modify the code to match a 66x.

    Erik

  • My code works on 664, but i need 2 uart
    and thats why i will use 669.

    I think that i have some problems with the sfr's but can't find out what.

    Anyone who has an header for 669,
    please replay.

    /Ingo

  • Anyone who has an header for 669
    The datasheet 'does'

    I always make my own. My name allow global search on bits and sfrs regardless of the use.

    I have seen too many lenghty debug sessions due to things like IE = and EX0 = not coming out in the same search.

    my names are e.g.

    sfr SF_IE             = 0xA8;
      sbit  SB_IE_EX0       = 0xA8;
      #define SM_IE_EX0       0x01
    
    That way you can find all uses of IE or all uses of EX0 in one global seatch (unless, of course you arew stupid enough to use numerics after the =). And for the benefit of a traditionalist that may follow me a search on the 'traditional' name works as well.

    Erik