Originally Posted by glauberm
I'm trying to interface the sensor (already in 3rd party mode) with an Atmel mega32u4.
I wrote the code below but I can't output meaningful values. Right now I get 0xAAAA, 0xA8A8, 0xA2A2, 0x8A8A, 0xA8A8, 0xA2A2, 0x8A8A and 0x2A2A repeated in this order over and over again. I'm not sure what the 0 and 1 inputs in the pseudo code i2c_read function mean. Any help is appreciated.
The 0 and 1 refer to whether you're going to clock an ACKnowledgement of data received.
In essence, when you read data, be it from this altimeter or an eeprom...you need to ACK each byte read before you read the next one. You don't need to ACK the final byte. You're getting repeating data pairs because you're not ACKing the previous byte, so it's not sending the next one.
So in essence what you want to see is:
START (set the start condition in your TWC)
RESTART (set RESTART in TWC)
READ (set the rx enable in TWC)
save the rx register as your first data byte
ACK (set the ACK bit in your TWC)
READ (flip the receive enable bit in control register again)
save the rx register as your second data byte
Now your AVR chip may work different from my PIC - I cannot set both receive enable and ACK enable or it locks up the bus (target device gets confused and locks SDA low and you have to do the hokey pokey to release it). I have to set the RCEN bit, then read my byte, then set the ACKEN bit, then set RCEN, then read my 2nd byte.