View Single Post
Old Feb 04, 2010, 06:08 PM
Teej is offline
Find More Posts by Teej
Registered User
Joined Feb 2010
59 Posts
Originally Posted by glauberm View Post
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 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)
out: 0xE8
out: 0x07
out: 0xE9
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.
Teej is offline Find More Posts by Teej
Reply With Quote