Hi. I'm messing around with i2c and attiny, after, some years ago I managed to successfully make a tiny25V talk to a MCP79410 over i2c.
Things changed since my laptop was stolen and I did not have a backup of the libraries I used (nor of the project). Anyhow I tried messing around with it (as you can tell from other topics in this section) and was advised to use the ATTinyCore library, which offer many advantages and so on.
So the problem is this: I wire up the attiny as a slave, making it talk to an arduino nano as master and it works like a treat. Now I want to try and make the attiny as a master, to recreate the old 79410 board. But first I want to try to use it on an empty bus, just to see whether it works. So I left all of the wirings as before (except for the nano who's not there), that means pullups (the following won't work for any value from 1 to 10k) and the connected pin, and I flash the TinyCore master writer sketch on my board.
Guess what: the SDA line works correctly, but the clock is inverted! By inverted I mean that, instead of being normally high and pulled low when needed, it is normally high and gets "released up" when needed.
I tried checking the scope settings (but I really never touched anything) and also switching the probes, to see whether it was a problem specific to one channel or specific to the probes but, whatever setup I use, the SCL line is "normally low".
What do you think am I doing wrong, or what do you think I can possibly investigate?
Please do mind that resetting the tiny as a slave works fine and I can still use it.
pylon:
Bad idea. The Tiny is either an I2C slave or it is a master but it shouldn't be both.
Perhaps bad wording. Let me rephrase:
now I'd like to test a circuit where the Tiny is a master, not a slave. Only a slave
Post your code and post a wiring diagram.
The code is exactly what I linked above, ie the example master writer taken directly from the attiny core library. I'm also providing a local copy:
// Wire Master Writer
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Writes data to an I2C/TWI slave device
// Refer to the "Wire Slave Receiver" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus (address optional for master)
}
byte x = 0;
void loop() {
Wire.beginTransmission(8); // transmit to device #8
Wire.write("x is "); // sends five bytes
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(500);
}
Regarding the wiring, it's the same when it was a slave. I will edit this post and attach a diagram, hopefully in the next 24 hours but:
SDA to PB0, with a pullup* to VCC
SCL to PB2, with a pullup* to VCC
VCC (5V) to pin8
GND to pin 4
*I tried different pullups, 1k, 2k2 and 10k, with no difference in the behavior.
I have no other devices on the bus, at the moment, just the scope probing sda and scl.
I tried different pullups, 1k, 2k2 and 10k, with no difference in the behavior.
All are probably wrong, usually a 4k7 or 3k3 is the best choice but I would have expected the 10k to work. The 1k is definitely to low, it might have damaged the Tiny or the Nano.
Guess what: the SDA line works correctly, but the clock is inverted! By inverted I mean that, instead of being normally high and pulled low when needed, it is normally high and gets "released up" when needed.
Can you post scope pictures of this? It might work if the start and stop conditions are correct but I don't remember a Tiny to have acted like that.
pylon:
All are probably wrong, usually a 4k7 or 3k3 is the best choice but I would have expected the 10k to work. The 1k is definitely to low, it might have damaged the Tiny or the Nano.
Can you post scope pictures of this? It might work if the start and stop conditions are correct but I don't remember a Tiny to have acted like that.
Hi, I have the same problem with a Trinket (Attiny85), with arduino nano as master the circuit works fine.
You have the same problem? Which problem exactly? OP looked at the scope output and was surprised that the SCL idles at LOW but the I2C start and stop conditions where correct.
If you have some other setup, post a complete wiring diagram of your setup together with the code used (don't forget the code tags!).