Adafruit TinyWireM library Attiny85/84

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
stryker1080
 
Posts: 2
Joined: Mon Feb 10, 2014 12:04 am

Adafruit TinyWireM library Attiny85/84

Post by stryker1080 »

Hi,

Was wondering if someone can help point me in the right direction with some issues I have been having with the TinyWireM library for the Attiny85/84 I2c communication. I have successfully got the following to work:

Arduino Uno (master) < - > Attiny 84/85 (running @ 8mhz) : Communicating master to slave, and back to master - OK
Attiny 84/85 (@ 1 MHz) Master <-> Attiny 84/85 (@ 8mhz): Communication between Attiny master to slave and back - OK
Attiny84/85 (@ 8 Mhz) Master <-> Attiny 84/85 (@ 8 MHz): Does not work

Whenever I try to use an Attiny device at 8Mhz with the I2C library (TinyWireM), it never works. I have serial outputs of the status register for initialization, sending data to trouble shoot, but nothing outputs. It hangs, in fact no serial data is transmitted to the monitor (don't see anything). When I switch back to 1Mhz, I get output on the serial monitor and it works, get data transmitting over i2c.

I have looked through the TinyWireM.cpp/.h, and USI_TWI_Master.h/.cpp . I have tried changing the F_CPU from 1000000ul to 8000000ul, tried playing with the T2_TWI, T4_TWI for the delays, tried different pull ups... nothing works.

Is there something that I am missing, any comments as to what else to check would be greatly appreciated. Been spending several nights trying to figure this out...

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Adafruit TinyWireM library Attiny85/84

Post by adafruit_support_mike »

This is just a guess, but you could be seeing the effects of clock skew between two devices running at speeds that are nearly-but-not-quite equal.

The TinyWire library uses short delays between pulses to allow for synchronization between the sender and receiver. The internal oscillators in most microcontrollers are good at controlling internal timing, but aren't precision timepieces by any stretch of the imagination.

If one device runs much faster than the other, it can compensate for the difference in frequencies by busy-waiting for as long as it takes to get the next signal. If both devices run at nearly the same frequency, you'll get a beat pattern.. the signals will go in and out of sync with each other at a frequency equal to the difference between the two main frequencies.

Even assuming the two oscillators have an error of 0.1%, that still puts the actual frequencies in a band 16kHz wide centered around 8MHz. On average, any two randomly selected devices will probably be about 11kHz off from each other, so you'll get a wierd hitch-step in the signals about every 90 microseconds. Assuming a 400kHz I2C bus rate, that's about once every 36 bits.

That's pure speculation though.. your best bet is to hook the thing up to a scope or logic analyzer and watch the signals.

1chicagodave
 
Posts: 564
Joined: Wed Jun 19, 2013 3:35 am

Re: Adafruit TinyWireM library Attiny85/84

Post by 1chicagodave »

I've never used the TinyWireM library. Since I usually use my Trinkets as Slaves, I use the TinyWireS library.

Have you tried toying with that one at all?

It offers functions like 'onRequest()' and 'onReceive()'. It only sends one Byte at a time without a few extra functions, but they're in a forum post here somewhere.

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: Adafruit TinyWireM library Attiny85/84

Post by adafruit »

Make sure you have strong pullups on SCL/SDA, 10K at least! without them you need to slow it down a lot to account for the slow rise times!

stryker1080
 
Posts: 2
Joined: Mon Feb 10, 2014 12:04 am

Re: Adafruit TinyWireM library Attiny85/84

Post by stryker1080 »

Got it working, i2c was working but serial wasn't. Changed from 9600 to 34xxx and it works great now!

User avatar
bartgarcia
 
Posts: 1
Joined: Sat Feb 14, 2015 8:59 am

Re: Adafruit TinyWireM library Attiny85/84

Post by bartgarcia »

Hey stryker1080 , Could you tell me how did you manage to make the I2C library work at 8Mhz on an attiny84? I been breaking my head on this for a while. I am also using software serial at 96000, but I have good comunication with this. Do you mean that by changing the software serial settings to 34xxx the I2C worked at 8Mhz clock?

Once again, it would be great if you could tell me how to make it work. (if you have code even better)
Thaks

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”