I2C Kommunikation zwischen Raspberry Pi und TI Stellaris Launchpad

Gast #3613075
Lesenswert?

Hallo, ich möchte testweise eine Kommunikation zwischen Pi und Launchpad 
über I2C herstellen. Beim Pi habe ich soweit I2C richtig eingerichtet. 
Über "sudo i2cdetect -y 1" wird eine Adressliste erzeugt.

Jetzt möchte ich, dass das Stellaris Launchpad sich erstmal als Device 
mit seiner Adresse meldet. Ich habe ein Testprogramm gefunden, wo schon 
mal diverse Dinge eingerichtet werden. Dieses scannt seinerseits auch 
Adressports ab, was aber erstmal nebensächlich ist.

Ich weiß nun nicht, was man noch einstellen muss. Müsste man dem 
Launchpad nicht z.B. eine eigene Adresse zuweisen, auf dessen Anfrage es 
antworten soll? Hier mal noch der Code:
1
#include <Wire.h>
2

3
void setup()
4
{
5
  Wire.begin(1);
6
  Wire.setModule(1);
7
  pinMode(9,INPUT_PULLUP);
8
  pinMode(10,INPUT_PULLUP);
9
  Serial.begin(9600);
10
  Serial.println("\nI2C Scanner");
11
}
12

13

14
void loop()  // NICHT WICHTIG
15
{
16
  byte error, address;
17
  int nDevices;
18

19
  Serial.println("Scanning...");
20

21
  nDevices = 0;
22
  for(address = 1; address < 127; address++ ) 
23
  {
24
    // The i2c_scanner uses the return value of
25
    // the Write.endTransmisstion to see if
26
    // a device did acknowledge to the address.
27
    Wire.beginTransmission(address);
28
    error = Wire.endTransmission();
29

30
    if (error == 0)
31
    {
32
      Serial.print("I2C device found at address 0x");
33
      if (address<16) 
34
        Serial.print("0");
35
      Serial.print(address,HEX);
36
      Serial.println("  !");
37

38
      nDevices++;
39
    }
40
    else if (error==4) 
41
    {
42
      Serial.print("Unknow error at address 0x");
43
      if (address<16) 
44
        Serial.print("0");
45
      Serial.println(address,HEX);
46
    }    
47
  }
48
  if (nDevices == 0)
49
    Serial.println("No I2C devices found\n");
50
  else
51
    Serial.println("done\n");
52

53
  delay(5000);           // wait 5 seconds for next scan
54
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren