Electronic – Arduino Uno to ATtiny44A I2C communication

arduinoattinyavri2c

I tried to make I2C communication from Arduino Uno to ATtiny44A.

Uno as Master and Transmitter code:

#include <Wire.h>

#define LED_PIN 13
byte x = 0;

void setup()
{
  Wire.begin(); // Start I2C Bus as Master
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

}
void loop()
{

  Wire.beginTransmission(0x26); // transmit to device #9
  Wire.write(x);              // sends x 
  Wire.endTransmission();    // stop transmitting
  x++;
  if (x > 5) x=0;
  delay(450);
}

ATtiny44A Slave/Receiver code:

#include "TinyWireS.h"                  // wrapper class for I2C slave routines

#define I2C_SLAVE_ADDR  0x26            // i2c slave address (38)
#define LED1_PIN         10             

void setup(){
  pinMode(LED1_PIN,OUTPUT);             // for general DEBUG use

  TinyWireS.begin(I2C_SLAVE_ADDR);      // init I2C Slave mode
}


void loop(){
  byte byteRcvd = 0;
  if (TinyWireS.available()){           // got I2C input!
    byteRcvd = TinyWireS.receive();     // get the byte from master

            if(byteRcvd == 5){
              digitalWrite(LED1_PIN,HIGH);
              delay(1000);
            }
            else{
              digitalWrite(LED1_PIN,LOW);
            }
  }
}

Am I doing something wrong? The LED does not blink. What are the other ways to debug ATtiny?

Best Answer

This is a pitfall of using the Arduino Library - everything is so abstracted from you that a little hiccup and you're completely lost. I don't know much about the Arduino libraries, but if it were me I would enable and use the TWI/I2C interrupts and see if they are being triggered. A simple LED blink inside the ISRs would do just fine as an indicator if it's working properly. If the LED doesn't blink then then problem lies in the protocol implementation.

Are you connecting the SCL and SDA correctly between the controllers? And do you have the SCL and SDA lines tied to pull-up resistors to VCC?

Similar to this: enter image description here