2015-05-25 451 views
1

嗨我想通過I2C將arduino pro mini連接到我的AtTiny85。AtTiny85和Arduino之間的簡單通信(I2C)

arduino應該告訴attiny打開或關閉LED。 arduino設法切換我attiny上的LED,但它永遠不會熄滅。

我沒有任何線索爲什麼?

這裏是我的主,從代碼:

MASTER:

#include <Wire.h> 
#define device (1) 

void setup() { 
    // put your setup code here, to run once: 
    Wire.begin(); 
} 

void loop() { 
    // put your main code here, to run repeatedly: 
    Wire.beginTransmission(device); 
    Wire.write(1); 
    Wire.endTransmission(); 
    delay(2000); 
    Wire.write(0); 
    Wire.endTransmission(); 
    delay(2000); 
} 

SLAVE:

#include <TinyWireS.h> 
#include <usiTwiSlave.h> 
#define output (4) 
#define I2C_SLAVE_ADDR (1) 


void setup() { 
    // put your setup code here, to run once: 
    TinyWireS.begin(I2C_SLAVE_ADDR); 
    pinMode(output, OUTPUT); 
} 

volatile byte msg = 0; 

void loop() { 
    if(TinyWireS.available()) 
    msg = TinyWireS.receive(); 

    if(msg == 1) 
    digitalWrite(output, HIGH); 
    else if(msg == 0) 
    digitalWrite(output, LOW); 
    else 
    msg = 0; 
} 

回答

2

我終於找到了我的錯誤: 當我這樣做: Wire.write(0);我忘記開始傳輸:Wire.beginTransmission(device);

相關問題