Problem with Atmega8 I2C-Slave and beagleboard

Hi,

I want to use an atmega8 processor as an i2c slave for my beagleboard. But I have some problems to get it working.

When the beagleboard tries to read one byte from the slave I get an interrupt on the atmega and the I2C status code gets printed. But the read() method of the master returns with -1 and the errno variable says “Remote I/O error”.
Now the problem is, that I get only one interrupt on my atmega8 everytime the master tries to read one byte.

So after the first try the slave prints “TW_STATUS1: a8” (SLA+R received, ACK returned: TW_ST_SLA_ACK) and the beagleboard prints an error.
After the second time the master reads on byte the slave prints “TW_STATUS default: c0” (data transmitted, NACK received: TW_ST_DATA_NACK) and the master prints an error. This procedure repeats everytime.

So it seems that the slave gets addressed, but the master stops the communication too early. I think these two messages of the avr should be printed while the master tries to read one byte and not after reading two times one byte.

I don’t know what’s the problem. I’ve tested different sourcecodes for the slave, but they all don’t work. I also tested an i2c compass CMPS03 and it works without any problem.

I use angstrom and a 2.6.29 kernel from OE. The i2c clock is set to 100khz and the atmega8 uses the internal 8 MHz clock.

The ISR of the slave and some defines:
http://pastebin.com/RLnAGEed

A part of my i2c class:
http://pastebin.com/rVehLmTu

Can somebody help me? It is very important for me to get the slave working, because my robot has to be ready in 3 weeks for the RoboCup Junior competition.

Regards, Joern

If the master is running away too fast, then one way to address the problem is
to have the slave put the I2C lines into wait-state.

This is a generic I2C suggestion. I haven't gone through your code or any
other details.

-Keith

Hi,

i'am using the same setup witha beagleboard talking to an atmega168
and i have no problem so far. Have your tried using i2c-tools for
debug ? On the atmega168 side , i'am using the avrlib librairie that
have i2c support. If your atmega8 is runnig at stock speed (1MHZ) the
default i2c frequency of 400khz on the beagleboard might be to high.

Hi,

i'am using the same setup witha beagleboard talking to an atmega168
and i have no problem so far. Have your tried using i2c-tools for
debug ? On the atmega168 side , i'am using the avrlib librairie that
have i2c support. If your atmega8 is runnig at stock speed (1MHZ) the
default i2c frequency of 400khz on the beagleboard might be to high.

    i2cdetect -y -r 2 shows only the CMPS03 compass at 0x60. The atmega runs at 8Mhz and on the beagleboard the i2c speed is set to 100khz.

If the master is running away too fast, then one way to address the problem is
to have the slave put the I2C lines into wait-state.

This is a generic I2C suggestion. I haven't gone through your code or any
other details.

-Keith
    

If I understand the datasheet of the atmega correctly, the SCL line is pulled to ground until the TWINT bit in the TWSCR register is set. And this is done after the data are written into the transmit register. The beagleboard also doesn't wait if in the ISR nothing is done and the TWINT bit isn't set.

Is it possible that the beagleboard doesn't wait until the SCL line is released? Or have you any other ideas?

Regards, Joern