Hallo,
ich habe ein Problem. Ich möchte RGB's über ein I2C Slave anstueren.
Unten habe ich I2C Master und ein I2C Slaver Programm aufgeführt. Ich möchte wissen wie der I2C Slaver erkennt welcher Port angesprochen wird. Kann mir bitte jemand helfen?

Master:
Code:
$regfile = "m32def.dat" 
$crystal = 16000000 
$baud = 9600
Config SCL = Portc.0 
Config SDA = Portc.1

$lib "I2c_twi.lbx" 

Config Twi = 400000 


Const Slave1 = &HC0                                         'I2C Adresse slave1 
Const Slave2 = &HC2                                         'I2C Adresse slave2 
Const Slave3 = &HC4                                         'I2C Adresse slave3 


Dim Status As Byte 

   Wait 2                                                   'Warte 2 Sekunden 
   I2cinit                                                  'Bus initialisieren 

Do 

   Status = 1 

   I2cstart 
   I2cwbyte Slave1                                          'Slave1 ansprechen 
   I2cwbyte Status                                          'Status 
   I2cstop 

   Waitms 1000 

   I2cstart 
   I2cwbyte Slave2                                          'Slave2 ansprechen 
   I2cwbyte Status                                          'Status 
   I2cstop 

   Waitms 1000 

   I2cstart 
   I2cwbyte Slave3                                          'Slave3 ansprechen 
   I2cwbyte Status                                          'Status 
   I2cstop 

   Waitms 1000 


Loop 

End
Slaver:
Code:
$regfile = "m32def.dat" 
$crystal = 16000000 
$baud = 9600 

Config Portc = Output                                       ' kompletter Portc als Ausgang 

Dim Twi_control As Byte                                     ' Controlregister lokale kopie 
Dim Twi_status As Byte 
Dim Twi_data As Byte 

Dim Neuesbyte As Byte                                       ' Bytemerker 

Declare Sub Twi_init_slave 

Twi_data = 0 
Call Twi_init_slave                                         ' TWI aktivieren 

' alle LEDs ein 
Portc = 0 

' Hauptschleife 
Do 

    ' Merker zurücksetzen 
    Neuesbyte = 0 

    ' schauen ob TWINT gesetzt ist 
    Twi_control = Twcr And &H80                             ' Bit7 von Controlregister 

    If Twi_control = &H80 Then 
        Twi_status = Twsr And &HF8                          ' Status 

        ' wurde ein Byte geschickt 
        If Twi_status = &H80 Or Twi_status = &H88 Then 
            Twi_data = Twdr                                 ' neue Daten merken 
            Neuesbyte = 1                                   ' merken das ein neues Byte da ist 
        End If 

        ' TWINT muss immer gelöscht werden, damit es auf dem Bus weiter geht 
        Twcr = &B11000100                                   ' TWINT löschen, erzeugt ACK 
    End If 

    ' wenn ein neues Byte gekommen ist, LEDs einschalten 
    If Neuesbyte <> 0 Then 
        Portc = 1                                           ' LEDs einschalten 
    End If 

Loop 

End 


' Unterprogramme 


' TWI als slave aktivieren 
Sub Twi_init_slave 
    Twsr = 0                                                ' status und Prescaler auf 0 
    Twdr = &HFF                                             ' default 
    Twar = &HC0                                             ' Slaveadresse setzen 
    Twcr = &B01000100                                       ' TWI aktivieren, ACK einschalten 

End Sub