2
\$\begingroup\$

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?

JYelton
35.7k34 gold badges149 silver badges282 bronze badges
asked Jun 22, 2014 at 16:35
\$\endgroup\$
0

1 Answer 1

3
\$\begingroup\$

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

answered Jun 22, 2014 at 16:46
\$\endgroup\$
3
  • \$\begingroup\$ SCL and SDA correctly connected and pull up resistors are in place. could you guide me or provide link on how i could do this without using arduino library \$\endgroup\$ Commented Jun 22, 2014 at 17:18
  • \$\begingroup\$ avrfreaks.net is a great resource for beginners. There are a ton of tutorials ranging from UART communication to EEPROM and interrupts. Here is another great resource that has some examples, but I mostly use it for documentation on avrlibc: nongnu.org/avr-libc/user-manual \$\endgroup\$ Commented Jun 22, 2014 at 20:28
  • \$\begingroup\$ My PCB had a small fault re-soldering solved the issue thanks a lot, looking at resources. \$\endgroup\$ Commented Jun 23, 2014 at 3:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.