Author Topic: I2C with attiny using TinyWire causes the bus to go low  (Read 1047 times)

0 Members and 1 Guest are viewing this topic.

Offline MoriambarTopic starter

  • Supporter
  • ****
  • Posts: 490
  • Country: it
I2C with attiny using TinyWire causes the bus to go low
« on: February 24, 2019, 05:40:03 pm »
Hi there.
I tried posting this on the arduino forums too, but I think here is better.
I have the need to use an attiny85 chip on a i2c bus. It has to have both slave and master functionalities in the end, but it's not the issue now.

I used the TinyWire library in order not to have to write everything from scratch, since its predecessor (TinyWireM for the master) worked fine and I used that a lot with tiny 8/45 chips.

Basically right now the net has only a Nano acting as a master, trying to call the tiny. And guess what: when the communication starts both SDA and SCK are pulled low and stay that way indefinitely. I tried:
  • disconnecting the tiny: the bus works properly
  • connecting other stuff on the bus, with or without the tiny but NOT calling the tiny: the bus works properly

So I suspect it's either a problem of the library (doubt it) or of my code (that's more like it), especially the "tiny" side.
Here is the "master" nano code:
Code: [Select]

#include <Wire.h>
void setup() {
Wire.beginTransmission(0x10);
Wire.endTransmission();
delay(1);
}

void loop() {
  // put your main code here, to run repeatedly:

}

and the tiny code:
Code: [Select]

#include <TinyWire.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stdint.h>

#define addr 0x10

volatile boolean startLed;

int main(){
 
TinyWire.begin(addr);
TinyWire.onReceive(onI2CReceive);

while(1)
{
  if(startLed){
  startLed=false;
  // Do something later
  }
}
return 0;
}

void onI2CReceive(){

  startLed=true;
}

Please do mind that I tried sending data on the tiny and even putting a while inside the onI2CReceive function, reading the data, but nothing changed. This is the easiest failing example I can give.

So, what am I doing wrong here?

Cheers!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf