Hallo Alexandra,

ich habe mir Deinen Code angesehen und kann - bis auf ein paar Unschönheiten - keinen plausiblen Grund finden für den beschriebenen Fehler.

Aber ich hab noch folgende Idee:
- könnte es sein, dass Du im makefile das Assembler-File i2cmaster.S nicht mit kompilieren läßt? Du musst das makefile aus der Bibliothek von Peter Fleury benutzen und dort unter Assembler-Sourcen das File i2cmaster.S aufführen.

Wie stellst Du eigentlich fest, dass Du am I2C Bus nur $FF liest?
Es könnte doch auch sein, dass Deine RS232 Routine fehlerhaft ist.
Um das zu überprüfen, würde ich den gelesenen Wert im EEPROM speichern (das habe ich unten im Code eingefügt).

Ansonsten empfehle ich Dir, Deinen Code wie folgt abgeändert zu übernehmen (Änderungen in Fettdruck):

#include <inttypes.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <math.h>


#include <avr/io.h>
#include "i2cmaster.h"
#define SRF 0xE0
#define F_CPU 8000000UL
#include <util/delay.h>
#define BAUD 9600
#include <avr/iom8515.h>
#include <avr/sfr_defs.h>
#define SDA 0 // SDA Port E, Pin 0
#define SCL 1 // SCL Port E, Pin 1
#define SDA_PORT PORTE // SDA Port E
#define SCL_PORT PORTE // SCL Port E

unsigned int distance EEMEM; // reserve storage space in EEPROM

// USART_INIT--
void initusart(void) // Hauptfunktion
{
unsigned char x; //Hilfsvariable
// #idef UBRRL //USART-Schnittstelle
UBRRL = (F_CPU / (16UL*BAUD)) -1; //Baudrate mit TAKT und Baud
UCSRB |= (1<<TXEN) | (1<<RXEN); //Sender und Empfänger ein
UCSRC |= (1<< URSEL) | (1<< UCSZ1) | (1<<UCSZ0); //ansync 8bit
x = UDR;
}

void sendeusart(int x)
{
while (!(UCSRA & (1<<UDRE))); // warten bis Senden moeglich
UDR = x;
}

int main(void)
{
i2c_init(); // einmal zu Anfang reicht
initusart();
sendeusart(distance);
unsigned char Lbyte,Hbyte;

DDRE = 0xff;
PORTE = 0xff;

while(1)
{
i2c_start(SRF);
i2c_write(0x00);
i2c_write(0x51);
i2c_stop();

_delay_ms(70);

i2c_start(SRF);
i2c_write(0x02);
i2c_stop();

i2c_start(0xE1);
Hbyte=i2c_readAck();
Lbyte=i2c_readNak();
i2c_stop();

distance=(Hbyte*256)+Lbyte;
eeprom_write_word(&distance,distance); //save to EEPROM

sendeusart(distance);
}
}

Auszug aus dem makefile:

# Target file name (without extension).
TARGET = "Dein Dateiname"

# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c

# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and GCC itself does
# care about how the name is spelled on its command-line.
ASRC = i2cmaster.S

Gruß, Dirk.