EDIT: OH MY GOD I'M A FLAMING IDIOT... when I started debugging an hour ago I forgot to turn the power supply on!!! So the ATmega has power, the AVR dragon has power, but the Timekeeper doesn't ... DOH
... even after turning the power on, it's still getting stuck at the same spot as mentioned below... lol that's strange. I guess it doesn't even need the RTC there to screw up...
so here's the revised IIC_read):
int IIC_read(int addr)
{
TWCR |= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); // enable TWINT and generate a start condition
TWDR = 0b11010000; // send slave address plus write bit
TWCR = (1<<TWINT)|(1<<TWEN);
while (!(TWCR & (1<<TWINT))); // wait for byte to send
TWDR = addr; // send address that we are reading from
TWCR = (1<<TWINT)|(1<<TWEN);
while (!(TWCR & (1<<TWINT))); // wait for byte to send
TWCR |= (1<<TWSTA); //repeated start
TWCR = (1<<TWINT)|(1<<TWEN);
while (!(TWCR & (1<<TWINT))); // wait for byte to send
TWDR = 0b11010001; // slave address plus READ bit
TWCR = (1<<TWINT)|(1<<TWEN);
while (!(TWCR & (1<<TWINT))); // wait for byte to send
TWDR = 0xFF; // shift junk data out to shift in the data byte requested
TWCR = (1<<TWINT)|(1<<TWEN);
while (!(TWCR & (1<<TWINT))); // wait for byte to send
TWCR |= (1<<TWSTO); // generate a STOP condition to bring bus back to rest
TWCR = (1<<TWINT)|(1<<TWEN);
while (!(TWCR & (1<<TWINT))); // wait for byte to send
return TWDR;
}
Now, it's getting stuck on the first "while (!(TWCR & (1<<TWINT)))", the one right after the slave address and write bit. It just sits there forever. I'm trying to understand what this while loop actually does. Obviously part of it is waiting for TWINT to be cleared, but why is TWCR in there? Why is it evaluating the entire register ANDed with TWINT?!? I know the whole statement is ! but still... confusing.
EDIT #2: So I busted out the oscilloscope. I am probing SDA, and when I send a character across the UART, the SDA line goes low... and just stays low. No action whatsoever. So even though the code has gotten to the while loop, the hardware hasn't even sent the first byte. I think it's sent the start condition but that's it. Strange. I guess I'll bust out the logic analyzer and watch everything a bit more closely.