Hi, I'm working with an ATtiny85 at 8MHz and have been testing on a Mega 2560 using address 99 (0x63) which has been working great.
I later connected to a Due and to my surprise it didn't work, after going in loops I happened to change the ATtiny85 address to 60 and it worked. So I started trying different addresses and it appears any address 63 or less will work but any address above 63 won't work, the I2C bus doesn't lock up, its just not seen.
I'm using the TinyWireS library and have tried 2 different versions and have also tried the TinyWire library but all give me the same results.
I have another factory device that can operate on address 99 and it works fine with the Due so I know it's possible. I've been searching and reading, others have had the same issue but a solution is never offered.
I've tried using a very basic sketch to eliminate other possible reasons. If address is 64 or high it can't be seen by the I2C scanner, 63 and under its ok. Only on the Due, Mega 2560 works with all addresses.
#include <TinyWireS.h>
void setup() {
byte i2cAddress = 63;
TinyWireS.begin(i2cAddress);
}
void loop() {
TinyWireS_stop_check();
}
Thanks
A standard slave address is on 7-bit and you can see that in TWI_MMR register. Since 63 = 0b111111 and 64 = 0b1000000, the DUE, as a TWI Master, should have no problem to read or write in a slave with the address 64 and up to 127.
As I understand your post, the DUE is the TWI Master and the ATtiny85 the TWI slave. You should try firstly with the example sketches provided with the Wire library, e.g. Master reader for the Due, slave sender for the ATtiny85. As you know, on the DUE side, SDA/SCL have already pull ups connected to 3.3V, therefore no pull ups should be added on the ATtiny side.
Note that it's possible to have a 10 bit slave address with the DUE as a TWI Master, if the slave device supports a 10-bit address (see page 717, Sam3x datasheet, 10-bit Slave Addressing). However AFAIK this feature is not implemented in the Wire library, you'll have to program directly registers.
Yeah the Due is ok with address 0-127 but there seems to be something wrong in the TinyWireS library to prevent 64+ from working. I can't use the example sketches for the slave on ATtiny85 as the Wire library isn't compatible. I am using the example for the Due. Thanks for the info on the 10-bit but I don't need that.
What core are you using for the Tiny? DrAzzy's TinyCore handles I2C natively so you don't need to mess around with an external Wire library, and the creator is active on the forums.
I think I'm running attiny by David A. Mellis, I find that by going to board manager which I assume is the cores? I'll try installing DrAzzy's core to see if that helps.
BJHenry:
What core are you using for the Tiny? DrAzzy's TinyCore handles I2C natively so you don't need to mess around with an external Wire library, and the creator is active on the forums.
So I removed the core I was using and installed this one, changed all the TinyWireS to Wire, set address to 99, uploaded and it worked.
Much easier than I expected, thanks for pointing this out!
BJHenry:
What core are you using for the Tiny? DrAzzy's TinyCore handles I2C natively so you don't need to mess around with an external Wire library, and the creator is active on the forums.
Just thought I would post an update, I was using the DrAzzy's TinyCore but overall it's worse. The problem doesn't appear to be fault of the core but more like the Wire library used in the core.
Using the Wire library on ATtiny85 four addresses would lock it up during a scan, 64, 80, 104 and 112 which didn't happen with the TinyWireS, with this only addresses past 64 are ignored. Worse yet 95% of the time after a restart of the Arduino (open/close serial monitor) or reprogramming an error would appear in the serial monitor saying there was an problem in twi.c file on line 279. I don't have the error on hand but it was in reference to address 0x80 even though that wasn't being used. To fix this the device had to be unplugged and plugged back in then it was ok again.