Pages: [1] 2 3   Go Down
Author Topic: I2C on the ATtiny85  (Read 19691 times)
0 Members and 1 Guest are viewing this topic.
Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I like this new place. It's like moving into a new office!  smiley

Just to say that I made a Playground article that provides the libs for I2C (master and slave) on the ATtiny85. It's here . . .
http://www.arduino.cc/playground/Code/USIi2c

Hope some of you find it useful.
« Last Edit: January 26, 2011, 05:48:37 pm by BroHogan » Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 222
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First off, thank you for writing this!

I gave it a whirl talking (or not, heh) to a AD5171 digital cap, I didn't get any output from pin5 or pin7 on the attiny, though I discovered when i was hooking it up that the closest to 4.7k resistors I had was 3.9k.

I'm going to spend some more time with it later on today hopefully, I'd be very, very pleased if I can get it to work as I was going to have to work out a way to bitbang it, which is rather over my head!
Logged

Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think 3.9K is close enough. (They are pull ups right?)
So I'll assume . . .
- your using the I2C master lib (TinyWireM)
- it compiles and loads to the ATtiny fine
- you have an LED on one of the other pins showing the sketch started
- you put a scope on pin 5 (SDA) and pin 7 (SCL) and saw nothing

Humph, as you can see in the examples that come with the lib, as a master, I had it talking to an I2C temp sensor, RTC and a GPIO.
The AD5171 looks like a straight forward chip to interface to.

What ATtiny core files are you using?
I've only been using those from "high-low tech", and loading with the ArduinoISP or the USBtinyISP.
« Last Edit: January 29, 2011, 04:29:02 pm by BroHogan » Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 222
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't done the scope yet, I'm going to take it to work on monday and do that.  Got some 4.7k resistors for good measure.
The attiny core files are one generation old now, I need to update.  That might be the problem right there.

I'll update the core files and check it out on the scope and post back after that.
Logged

Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Bob,
Could confirm my assumptions - i.e.
Quote
- your using the I2C master lib (TinyWireM) - YES ?
- it compiles and loads to the ATtiny fine - YES ?
- you have an LED on one of the other pins showing the sketch started - "NO BUT GOOD IDEA . . . YES IT DOES" ?
- you put a scope on pin 5 (SDA) and pin 7 (SCL) and saw nothing - NO, BUT I KNOW I'M NOT GETTING OUTPUT BECAUSE . . .

That would help me help you.
Quote
What ATtiny core files are you using?
I've only been using those from "high-low tech", and loading with the ArduinoISP or the USBtinyISP.

I'm now guessing you are using the core files Coding Badly is involved with. I haven't tested with those. Try the cores from here
http://hlt.media.mit.edu/wiki/pmwiki.php?n=Main.ArduinoATtiny4585

You can change boards.txt if your using a programmer other than ArduinoISP. For example:
Code:
attiny852.name=ATtiny85 (Load w/ USBtinyISP)
attiny852.upload.using=arduino:usbtinyisp
attiny852.upload.maximum_size=8192
attiny852.build.mcu=attiny85
attiny852.build.f_cpu=1000000L
attiny852.build.core=attiny45_85

(What programmer are you using?)

The "hlt" core works fine and it's simpler in some ways - a lot less going on in boards.txt. If you don't like that core for some reason, I still suggest you try it first - you can always go back to the other after you see everything working.



« Last Edit: January 30, 2011, 07:31:53 pm by BroHogan » Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Humph, Looks like I scored a -karma for my efforts! Great system. smiley-confuse

@Bobnova
Since I figured you were using the cores from here . ..
http://code.google.com/p/arduino-tiny/
I tested those cores with my libs.

After changing boards.txt to upload with the USBtinyISP I found that the TinyWireM lib worked with those cores.

However, the sketch was running 10X slower - even the Blink sketch.  smiley-small
So I changed the speed in boards.txt from f_cpu=800000L to f_cpu=1000000L and now it works fine.
I don't know why one set of cores uses an 8MHz clock and another set uses a 10MHz clock.
Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

However, the sketch was running 10X slower - even the Blink sketch.  smiley-small

Was it 8X?

Quote
So I changed the speed in boards.txt from f_cpu=800000L

800K is nowhere to be found in boards.txt.  Was it an 8M entry you changed?

Quote
to f_cpu=1000000L and now it works fine.

Are the target processor's fuses set to run at 1 MHz?  Or 8 MHz?

Quote
I don't know why one set of cores uses an 8MHz clock and another set uses a 10MHz clock.

The HIT core uses a 10 MHz clock?

Logged

Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Kinda busting my chops on this aren't you?
Quote
Was it 8X?
Could have been 8X could have been 10X I didn't put a stopwatch on it. It was at least 8X. It is a critical difference for making a determination?

Quote
800K is nowhere to be found in boards.txt.  Was it an 8M entry you changed?
Ya got me! I dropped a 0 during the post. I changed it from 8MHz to 10MHz as I stated.
As you know boards.txt in google code core is set for 8MHz.

Quote
Are the target processor's fuses set to run at 1 MHz?  Or 8 MHz?
I suggest you look at the google code boards.txt and answer that yourself. I made no changes.

Quote
The HIT core uses a 10 MHz clock?
That's what I said. You can download the HIT core and verify that if you wish.

In the google code site for the core you asked if someone would verify if these libraries would work with that core.
This is what I've done, and this is, I guess, my thanks.

« Last Edit: January 31, 2011, 11:04:22 pm by BroHogan » Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Kinda busting my chops on this aren't you?
This is what I've done, and this is, I guess, my thanks.

I do apologize for upsetting you.  That was not my intention.  I'm simply trying to determine if there is a problem with either core or if there is a misunderstanding on how either of them should work.  I simply don't want another user to have the same problems that you've just had.  Both cores should be simple to install and easy to use.  I promise to refrain from any further communication.

For what it's worth, I appreciate your efforts and thank you for your time.
Logged

Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I was wrong! Adamant, but wrong.
I was posting instead of sleeping, and between cut & paste and counting zeros, I screwed up.

- boards.txt for HIT core is set for 1MHz.
- boards.txt for "google code" core is set for 8MHz.
  (It also sets fuses which sets the internal clock speed.)

Nonetheless, when I used the "google code" core, Blink ran 8X slower.
When I changed it from f_cpu=8000000L to f_cpu=1000000L it ran normally.
Reloading again with the HIT core it continued to run normally.

It looks like the fuse settings in boards.txt for "google code" aren't getting set for some reason.

That's all I know. Sorry about the confusion.

In any case, the ATtiny I2C libs work with either core.
« Last Edit: February 02, 2011, 12:42:19 pm by BroHogan » Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12283
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

- boards.txt for "google code" core is set for 8MHz.
  (It also sets fuses which sets the internal clock speed.)

It looks like the fuse settings in boards.txt for "google code" aren't getting set for some reason.

Ah!  In order to change the fuse settings you have to select "ATtiny85 @ 8 MHz" then execute "Burn Bootloader".  "Burn Bootloader" is also a nice way to clean the slate when switching to another project or putting a processor into storage.  In addition to changing the fuse settings an empty do nothing Sketch is uploaded.

Quote
Well, I was wrong! Adamant, but wrong.
I was posting instead of sleeping, and between cut & paste and counting zeros, I screwed up.

The moral of the story is ... friends don't let friends play with Arduinos when sleep deprived?   smiley-wink

Quote
- boards.txt for HIT core is set for 1MHz.

The "google code" should also have a "ATtiny85 @ 1 MHz" option.  It should be almost identical in behaviour to the HIT core.

Quote
In any case, the ATtiny I2C libs work with either core.

Excellent news!  Thanks!
« Last Edit: February 02, 2011, 09:39:06 pm by Coding Badly » Logged

Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
select "ATtiny85 @ 8 MHz" then execute "Burn Bootloader".
Ive tried that, but I get errors. (Perhaps it's best I PM you on them, or start another thread.)

In any case, I managed to set the fuses properly using Avrdude. (Every evening this week I found myself being drawn deeper and deeper into the dark side. smiley-roll-sweat) So now I am able to test the libs with both cores at both 1MHz and 8MHz.

I wonder if anyone else has tried these libs yet.
« Last Edit: February 03, 2011, 11:38:46 am by BroHogan » Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Humboldt, CA
Offline Offline
Full Member
***
Karma: 2
Posts: 222
Arduino BBB
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry it took me so long to get back to you, it's been a hectic week around here.
I got all set up with the scope this morning and the 4.9k resistor pull-ups, and the scope picture was perfect so I plugged in the digipot (which controls a fan pwm controller) and it worked perfectly too!

So either A) 3.9k resistor pull-ups do not work, or B) I didn't have them all the way inserted into the breadboard.
In any case, you code is working perfectly for me, thanks!  (I made no changes in software/firmware/sketch/etc)


Sorry if I cause you mental issues with my screwup!

Blink seems to be running the right speed for me, for whatever that is worth.
Logged

Denver
Offline Offline
God Member
*****
Karma: 19
Posts: 778
Inactive - PM
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Aces! Great to hear. Thanks!
Logged

"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll

Offline Offline
Jr. Member
**
Karma: 0
Posts: 64
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

bHogan,

I'm going to give this a try with attiny85 as i2c slave.  Has anyone tried to implement onReceive and onRequest?  Is there any fundamental reason why this would not work on attiny85?

Thanks for the work to date,
George 
Logged

Pages: [1] 2 3   Go Up
Jump to: