Ein kleines Beispiel von mir:
/*!
* \brief Schreibfunktion für 1 Byte Daten auf I²C Bus EEPROM
* \param adresse 2 Byte Adresse
* \param daten_byte Daten Byte das geschrieben werden soll
*/
void I2C_write_byte_EEPROM (unsigned int adresse, unsigned char
daten_byte)
{
unsigned char adr_high;
unsigned char adr_low;
adr_high = adresse >> 8;
adr_low = adresse & 0xFF;
// while (I2CDCTL&I2CBUSY); // wait until I2C module has finished
all operations
I2CNDAT = 0x03; // 3 Byte senden
I2CSA = EEPROM_I2C_ADDRESS; // Slave Adresse
U0CTL |= MST; // Master
I2CTCTL |= I2CTRX + I2CSTT + I2CSTP; // TX Mode, Start, Stop
while ((I2CIFG & TXRDYIFG) == 0); // Wait for transmitter
I2CDRB = adr_high; // Adresse High-Byte
while ((I2CIFG & TXRDYIFG) == 0); // Wait for transmitter
I2CDRB = adr_low; // Adresse Low_Byte
while ((I2CIFG & TXRDYIFG) == 0); // Wait for transmitter
I2CDRB = daten_byte; // Daten
//while ((I2CTCTL & I2CSTP) == I2CSTP); // Auf Stop warten
while ((I2CIFG & ARDYIFG) == 0); // Warten bis I2CNDAT Anzahl
I2CIFG=0x00; // Clear I2C interrupt Flags
}