Go Down

Topic: I2C communication between Attiny85 as master and arduino UNO as slave (Read 891 times) previous topic - next topic

hguo

I want to make my Attiny85 and my Arduino UNO communicate together with I2C protocol. Since Attiny do not support Wire library, I use TinyWire by lucullusTheOnly and Wire on the Uno.

The Attiny is sending data as the master to the Uno, the slave.
Here is my code:
Master

Code: [Select]
#include <TinyWire.h>
   
    byte slave_address = 10;
   
   
    void setup() {
    // config TinyWire library for I2C master functionality
    TinyWire.begin();
    }
   
    void loop() {
    TinyWire.beginTransmission(slave_address);
    TinyWire.send('c');

    // endTransmission sends the bytes in the buffer to the slave and returns 0 if there was no error
        TinyWire.endTransmission();
    delay(500);
    }


Slave

Code: [Select]
   

#include <Wire.h>
   
    void setup() {
      Wire.begin(10);                // join i2c bus with address #10
      Wire.onReceive(receiveEvent); // register event
      Serial.begin(9600);           // start serial for output
    }
   
    void loop() {
      delay(100);
    }
   
    // function that executes whenever data is received from master
    // this function is registered as an event, see setup()

    void receiveEvent(int howMany) {
      while (1 < Wire.available()) {  // loop through all but the last
        char c = Wire.read(); // receive byte as a character
        Serial.print(c);         // print the character
      }
      int x = Wire.read();    // receive byte as an integer
      Serial.println(x);
    }


I connect the pin like this :

Code: [Select]

    Arduino --> Attiny
    SCL ---- PIN 7
    SDA ---- PIN 5


I try to pull-up the clock and data line with 2.2k resistors but nothing happened, I receive nothing on the Uno from the Attiny.
Any idea ? Thanks !

pert

Also posted at:
https://arduino.stackexchange.com/q/49088
If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

Go Up