Atmega168 I2C as master

It's more of a Atmega168 programmed in C rather than an arduino.

I've been having some problems in using a Atmega168 as a I2C device. The basic setup is that the physical I2C bus is connected to other slave devices but the Atmel itself is not enabled for I2C.

There is a also a linux based TI DM365 SoC on the bus. The DM365 can communicate with the slave devices with no problem. So essentially, it's going to be a multi-master setup.

The essential atmel code is pasted below. USART_Transmit is same as printf in this case. TWIinit() is called in main() and the bus is read on command(from serial).

I keep getting "Didn't get 0x18", which is when the device address is not transmitted indicating the bus is busy. But when I use a voltmeter (sorry, no oscilloscope), the is held high at 3.3V, which means the bus is free to be used. I also tried this by physically cutting out the DM365, but even that didn't work. The actual value I get is 0x06.

Any help or ideas are appreciated.

uint8_t u8ebyte;
uint8_t u8erbyte;
uint16_t u16eaddress = 0x0002;
#define EEDEVADR 0x36

void TWInit (void)
{   
    TWSR = 0x00;    // prescaler 1
    TWBR = 0xFF;   //0xFF; //smallest TWBR value possible is 0x10
    TWCR = (1<<TWEN);  // Enable TWI-interface and release TWI pins.
}

void TWIStart(void)
{
    TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
}

//send stop signal
void TWIStop(void)
{
    TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);
}

void TWIWrite(uint8_t u8data)
{
    TWDR = u8data;
    TWCR = (1<<TWINT)|(1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
}

uint8_t TWIReadACK(void)
{
    TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);
    while ((TWCR & (1<<TWINT)) == 0);
    return TWDR;
}

//read byte with NACK
uint8_t TWIReadNACK(void)
{
    TWCR = (1<<TWINT)|(1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
    return TWDR;
}

uint8_t TWIGetStatus(void)
{
    uint8_t status;
    //mask status
    status = TWSR & 0xF8;
    return status;
}

uint8_t I2CReadByte(uint16_t u16addr, uint8_t *u8data)
{
    //uint8_t databyte;
    TWIStart();
    if (TWIGetStatus() != 0x08){
        USART_Transmit_string("Didn't get 0x08");
        TWIStop();
       return -1;
    }

    //select device 
    TWIWrite((EEDEVADR)|((uint8_t)((u16addr& 0x0700)>>7)));

    //TWIWrite(((EEDEVADR)<<1|0));
    if (TWIGetStatus() != 0x18){
        USART_Transmit_string("Didn't get 0x18");
        return -1;
    }

    //send the rest of address
    TWIWrite((uint8_t)(u16addr));
    if (TWIGetStatus() != 0x28){
        USART_Transmit_string("Didn't get 0x28");
        return -1;
    }

    //send repeated- start
    TWIStart();
    if (TWIGetStatus() != 0x10){
        USART_Transmit_string("Didn't get 0x10");
        return -1;
    }

    //select devise and send read bit
    TWIWrite((EEDEVADR)|((uint8_t)((u16addr & 0x0700)>>7))|1);
    if (TWIGetStatus() != 0x40){
        USART_Transmit_string("Didn't get 0x40");
        return -1;
    }

    *u8data = TWIReadNACK();

    if (TWIGetStatus() != 0x58){
        USART_Transmit_string("Didn't get 0x58");
        return -1;
    }
    TWIStop();
    USART_Transmit_string("MADE IT!!");
    return 1;
}