Go Down

Topic: BroHogan I2C with Attiny84 (Read 6986 times) previous topic - next topic

Mlabs

I am working in a project using the Attiny84a and I require I2C to Interface with MMA7660 accelerometer.

Yesterday I started to port the BroHogan's I2C tiny 85 library to the Tiny 84
The only thing I came up with was adding this block of code to USI_TWI_Master.h

Code: [Select]
#if defined(__AVR_ATtiny84__) | defined(__AVR_ATtiny44__)
    #define DDR_USI             DDRA
    #define PORT_USI            PORTA
    #define PIN_USI             PINA
    #define PORT_USI_SDA        PORTA6
    #define PORT_USI_SCL        PORTA4
    #define PIN_USI_SDA         PINA6
    #define PIN_USI_SCL         PINA4
#endif


I will be working on this for the next couple days.

Any thoughts on this? might it work? is there a better option?

Any advice would be great. Specially from Coding Badly or BroHogan, who made it posible to use Arduino with the tiny.

Coding Badly


I'm willing to give advice but, in this case, it may not be very helpful.  I have yet to use I2C with an ATtiny processor.  (and I'm keenly aware of the irony)

I'll post an opinion later tonight (work beckons)...

Mlabs



I'm willing to give advice but, in this case, it may not be very helpful.  I have yet to use I2C with an ATtiny processor.  (and I'm keenly aware of the irony)

I'll post an opinion later tonight (work beckons)...


Thanks! If I get it to work I'll make sure to post the config and results.

nickgammon

Can you give a link to the library? I see that the chip supports I2C so it should be possible to get it to work.

I don't have one of those chips to hand so I can't assist right now. Element14 have the ATTINY84-20PU for $5.38 and the ATTINY84V-10PU for $5.78. But the -20 is faster isn't it?

I might grab a few and see what I can do with them.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Coding Badly

Can you give a link to the library?


This page provides a link to BroHogan's post, playground page, and library...
http://code.google.com/p/arduino-tiny/wiki/TWIMasterLibrary

Quote
I see that the chip supports I2C so it should be possible to get it to work.


Yup.  USI.

Quote
I don't have one of those chips to hand so I can't assist right now. Element14 have the ATTINY84-20PU for $5.38 and the ATTINY84V-10PU for $5.78.


Seems kind of expensive.  Has the Aussie dollar been deflating?

Quote
But the -20 is faster isn't it?


The 20 works up to 20MHz.  The 10 works up to 10MHz but operates at a lower voltage (that's the "V" in the part number).

Quote
I might grab a few and see what I can do with them.


They are nice processors.  Especially the analog features (differential input; gain).

nickgammon


Seems kind of expensive.  Has the Aussie dollar been deflating?


No. That's just the way things are out here.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Mlabs

Woah, my theory was correct! The library worked just fine with the addition of the Code block from my first post.

Since my goal was to interface with the MMA7660 acccelerometer I modified a library I found on the forums to use TinyWire insteead of Wire. It also worked on the first try. I guess I was lucky tonight.

Thanks for helping out guys.

I attached the two modified libraries in case someone needs it.


Mlabs

I am having problems with the I2C communication. while debugging i get readings for registers 0x00, 0x01 and 0x03. Wich hold the information for X, Y and Z orientation. The problem is that they keep changing even when the accelerometer is resting still on my desk.


  || 0x00:0  ||  || 0x01:0  ||  || 0x02:0  ||
  || 0x00:61  ||  || 0x01:60  ||  || 0x02:15  ||
  || 0x00:1  ||  || 0x01:4  ||  || 0x02:19  ||
  || 0x00:59  ||  || 0x01:60  ||  || 0x02:17  ||
  || 0x00:0  ||  || 0x01:58  ||  || 0x02:19  ||
  || 0x00:62  ||  || 0x01:62  ||  || 0x02:21  ||
  || 0x00:1  ||  || 0x01:1  ||  || 0x02:20  ||
  || 0x00:2  ||  || 0x01:59  ||  || 0x02:21  ||
  || 0x00:3  ||  || 0x01:5  ||  || 0x02:18  ||
  || 0x00:4  ||  || 0x01:62  ||  || 0x02:19  ||
  || 0x00:61  ||  || 0x01:1  ||  || 0x02:20  ||
  || 0x00:4  ||  || 0x01:1  ||  || 0x02:20  ||
  || 0x00:63  ||  || 0x01:56  ||  || 0x02:19  ||
  || 0x00:63  ||  || 0x01:2  ||  || 0x02:22  ||
  || 0x00:62  ||  || 0x01:62  ||  || 0x02:21  ||
  || 0x00:3  ||  || 0x01:0  ||  || 0x02:18  ||
  || 0x00:60  ||  || 0x01:3  ||  || 0x02:20  ||
  || 0x00:3  ||  || 0x01:60  ||  || 0x02:21  ||
  || 0x00:0  ||  || 0x01:3  ||  || 0x02:22  ||
  || 0x00:62  ||  || 0x01:56  ||  || 0x02:20  ||
  || 0x00:63  ||  || 0x01:58  ||  || 0x02:20  ||
  || 0x00:3  ||  || 0x01:3  ||  || 0x02:20  ||
  || 0x00:62  ||  || 0x01:1  ||  || 0x02:21  ||
  || 0x00:10  ||  || 0x01:60  ||  || 0x02:17  ||
  || 0x00:62  ||  || 0x01:2  ||  || 0x02:21  ||
  || 0x00:8  ||  || 0x01:60  ||  || 0x02:19  ||
  || 0x00:4  ||  || 0x01:58  ||  || 0x02:17  ||
  || 0x00:63  ||  || 0x01:2  ||  || 0x02:21  ||
  || 0x00:63  ||  || 0x01:58  ||  || 0x02:18  ||
  || 0x00:62  ||  || 0x01:63  ||  || 0x02:21  ||
  || 0x00:2  ||  || 0x01:55  ||  || 0x02:85  ||
  || 0x00:60  ||  || 0x01:59  ||  || 0x02:20  ||
  || 0x00:61  ||  || 0x01:61  ||  || 0x02:21  ||
  || 0x00:9  ||  || 0x01:1  ||  || 0x02:23  ||
  || 0x00:62  ||  || 0x01:0  ||  || 0x02:20  ||
  || 0x00:1  ||  || 0x01:0  ||  || 0x02:23  ||
  || 0x00:127  ||  || 0x01:56  ||  || 0x02:22  ||
  || 0x00:62  ||  || 0x01:2  ||  || 0x02:24  ||
  || 0x00:1  ||  || 0x01:5  ||  || 0x02:18  ||
  || 0x00:2  ||  || 0x01:59  ||  || 0x02:20  ||
  || 0x00:63  ||  || 0x01:0  ||  || 0x02:19  ||
  || 0x00:3  ||  || 0x01:6  ||  || 0x02:17  ||
  || 0x00:2  ||  || 0x01:2  ||  || 0x02:25  ||
  || 0x00:60  ||  || 0x01:1  ||  || 0x02:20  ||
  || 0x00:2  ||  || 0x01:1  ||  || 0x02:22  ||
  || 0x00:0  ||  || 0x01:1  ||  || 0x02:21  ||
  || 0x00:57  ||  || 0x01:61  ||  || 0x02:21  ||
  || 0x00:0  ||  || 0x01:1  ||  || 0x02:20  ||
  || 0x00:0  ||  || 0x01:59  ||  || 0x02:22  ||

If I read the user configuration registers they show different values on each reading and I didn't modify them. My theory is that the I2C is not working properly. I am using the attiny84a with the 8Mhz internal oscillator, would this clock source be accurate enough for I2C? Or maybe BroHogan's code wasn't as portable as I thought.

nickgammon

Maybe. Post your code so we can see.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

Mlabs

My Code -> MMA7660 library -> TinyWireMLibrary -> Arduino Tiny -> Arduino

The project became a house of cards, the issues become untraceable. I have decided to hold off the I2C until the next iteration (which will be developed without Arduino, just AVR gcc)

It's very clear now, rapid prototyping requires ARDUINO and the official HARDWARE. Any other combination is just issues and more issues.

For the next phase I have two options custom board with ATMega328p using ARDUINO IDE or ATTINY84 and AVR STUDIO/CodeVision

Plecto

I'm also trying to communicate to a I2C ADC using an attiny84. I made the changes in the library that you proposed, Mlabs and that got rid of the compiling error that I got with the original Attiny85 I2C library, but it still doesn't work. Here's my code:

#include <TinyWireM.h>
#include <USI_TWI_Master.h>
void setup() {
  DDRA=0b01010000;
  TinyWireM.begin();
}

void loop() {
  TinyWireM.requestFrom(0x68,3);
  TinyWireM.receive();
  TinyWireM.receive();
  TinyWireM.receive();
  delay(1);
}

I was unsure whether the DDRA register should be set, I just remember successfully making SCL and SDA pins as outputs when using the Wire library with an Atmega328. It doesn't matter if the DDRA register is set or not though, it doesn't work regardless.

Scoping the output of SCL gives a HIGH for about 70us and then LOW for about 1.2ms, there's no clock signal. The SDA pin is just a constant LOW :(

JChristensen

I may just have done the same thing that Mlabs did, but here is a library that I'm using with ATtiny84A and an I2C RTC (MCP79412):
https://github.com/JChristensen/TinyWireM

Go Up