Hi, everybody!
I have one little project for home, so I decided to use ATTiny45 because of its size. The problem is that i cant use Wire libriary. So i dig a lot and found [this](http://playground.arduino.cc//Code/USIi2c). I wrote a code for master and slave, but...it doesn
t work stable: LED is flashing not as I expect(500ms on, 500ms off), it can stay OFF for minutes and then turn ON for some seconds, for example. Can someone explain what I am doing wrong?
Pull-up 5k-resistors are set.
Code for master:
#include <TinyWireM.h>
void setup() {TinyWireM.begin();}
void loop(){
delay(500); //a little delay for slave to get ready
TinyWireM.beginTransmission(0x33); //start transmission to slave
TinyWireM.send(0); //send him zero
TinyWireM.endTransmission(); //finish transmission
delay(500); //a little delay for slave
TinyWireM.beginTransmission(0x33); //start transmission to slave
TinyWireM.send(1); //send him one
TinyWireM.endTransmission(); //finish transmission
}
Code for slave:
#include <TinyWireS.h>
void setup(){
pinMode(4, OUTPUT); //set pinMode for pin with LED
TinyWireS.begin(0x33); //set adress for slave
}
void loop(){
byte byteRcvd;
if (TinyWireS.available()) //wait for master to start transmission
{
byteRcvd = TinyWireS.receive(); //get a byte from master
if (byteRcvd==1) {digitalWrite(4, HIGH);} //if byte was 1 then light up the led
if (byteRcvd==0) {digitalWrite(4, LOW);} //if byte was 0 then light down the led
}
}