0

Hi I have a big problem with addressing multiple attiny85-chips with I2C:

For what I know the attiny uses 7-bit addresses for communication. I am using the TinyWireS lib, which works perfectly fine for me, untill I am reaching address: '64' which is '1000000' in binary. The highest usable address should be '1111111'.

This is what happens:

Slave:

Attiny85: switches led on or off when msg is received over I2C.

Slaveaddress: 64

#include <TinyWireS.h>
#include <usiTwiSlave.h>

#define output (4)
#define I2C_SLAVE_ADDR (64) //works if I2C_SLAVE_ADDR < 64

void setup() {
  TinyWireS.begin(I2C_SLAVE_ADDR);
  pinMode(output, OUTPUT);
}

volatile bool state = LOW;

void loop() {
  byte msg = -1;
  if(TinyWireS.available())
    msg = TinyWireS.receive();

  if(msg == 1)
    state = HIGH;
  else if(msg == 0)
    state = LOW;
  else if(msg == 2)
    state = !state;

  digitalWrite(output, state);
}

Master:

Arduino pro mini:

sendMsg(0, true); //works! led on chip: 64 switches on

sendMsg(64, true); //fails! led on chip: 64 is off.

#include <Wire.h>

#define DEVICE (64) //0 works!

void setup() {
    Wire.begin();
}

void loop() {
    sendMsg(1, DEVICE);
    delay(2000);
    sendMsg(0, DEVICE);
    delay(2000);
}

void sendMsg(int msg, int device) {
    Wire.beginTransmission(device);
    Wire.write(msg);
    Wire.endTransmission();
}

Have you any idea how to solve this problem?

TinyWireS version I am using: https://github.com/rambo/TinyWire/tree/master/TinyWireS

user3025417
  • 395
  • 1
  • 5
  • 17
  • I don't think that you will receive any support without posting your code..... – frarugi87 Jul 16 '15 at 09:05
  • @frarugi87 thank you. It should be fine now! – user3025417 Jul 16 '15 at 13:06
  • Two more questions: did you try more addresses or just 0 and 64? and.. If you `#define I2C_SLAVE_ADDR (192)`, leaving `#define DEVICE (64)`, does it work? I mean leave the address 64 in the master and set address 192 in the slave.. – frarugi87 Jul 16 '15 at 14:41
  • @frarugi87 1) sure: I've tried 65, 66, 67, and I think some more 2) no unfortunately it doesn't. – user3025417 Jul 16 '15 at 15:04
  • What about addresses 20, 21...? I mean less than 64 but greater than 0. If so, try to make a "broadcaster".. something like `for (add = 1; add < 128; add++) sendMsg(1,add);` instead of `sendMsg(1,DEVICE);` in the master. The same for the 0. Then try to change the address in the receiver, setting it to 22, 44, 66 and see until when it receives the commands. – frarugi87 Jul 16 '15 at 15:29
  • I already did this. works until the slave goes up to 63. after that the led stays off. – user3025417 Jul 16 '15 at 16:07
  • If you have an oscilloscope, try to figure out if the problem is in the master or in the slave. If you haven't, maybe switching the two elements can solve the problem (attiny = master and arduino mega = slave). Otherwise... Hack the TinyWire library (I'd try to look into the `ISR( USI_OVERFLOW_VECTOR )` in `usiTwiSlave.c` file) to see what you are getting... – frarugi87 Jul 16 '15 at 16:27
  • I did some tests and I think the error must be in the TinyWiresS lib. I used an Arduino Uno as Slave and left the Master code on the pro mini as it was. It works now for addresses higher than 63! but this does not solve my problem. I still need to figure out how modify the TinyWiresS lib in order to use higher addresses. – user3025417 Jul 16 '15 at 17:26
  • Please state the exact link you used to get the TinyWiresS library. – Nick Gammon Jul 17 '15 at 11:02
  • this may sound stupid, but your device actually has the address pins mapped correctly so that it can be addressed with address 64 ...right? You checked this!? – Pandrei Jul 17 '15 at 13:05
  • if you have the latest version of TinyWire library, open file `usiTwiSlave.c` and then change line 578 from `if ( ( USIDR == 0 ) || ( ( USIDR >> 1 ) == slaveAddress) )` to `if ( ( USIDR == 0 ) || ( ( ( USIDR >> 1 ) & 0x7F ) == slaveAddress) )`, then let us know the results – frarugi87 Jul 17 '15 at 16:22
  • @frarugi87 unfortunately it doesn't change anything. still not receiving anything. BTW I'm using the latest version of TinyWireS – user3025417 Jul 21 '15 at 15:11
  • @Pandrei what do you mean by address pins – user3025417 Jul 21 '15 at 15:18
  • @user3025417 every I2C device has an address so you can talk to it. This address is configurable (for most devices) and it is configured by hard-wiring some address pins to GND or VCC. So it your address is fixed and for some reason you expect to address the device using a different address,it's obvious it won't work. – Pandrei Jul 21 '15 at 15:23
  • @Pandrei Haha I would be very happy (and stupid) if this was the problem. unfortunately the issue is in the library. I've talked to the developer. – user3025417 Jul 21 '15 at 15:33
  • @user3025417 So.. what is the issue? – frarugi87 Jul 22 '15 at 08:25
  • @frarugi87 for some reason the 7th addressbit is masked. but there will not be any updates for TinyWireS soon. I still want to finish my project but I'm not that skilled in C/C++ to fix this by my own. Any help would be appreciated. Should I start a new thread for fixing the library? – user3025417 Jul 22 '15 at 10:32

0 Answers0