I want to know what I have to do to be able to use serial on my attiny2313. What I'm trying to do is to make an USART->I2C gateway using one atmega328p(as master) and two attiny2313(as slaves).
But I2C using an arduino uno as master and attiny2313 using TinyWireS not. I can see on my logic analyzer my arduino sending read to 0x7f(127) but attiny does not answer.
I'm pullin-up SDA and SCL with 4.7k resistors.
Arduino Code:
#include <Wire.h>
void setup()
{
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial for output
}
void loop()
{
Wire.requestFrom(127, 6); // request 6 bytes from slave device #1
while(Wire.available()) // slave may send less than requested
{
char c = Wire.receive(); // receive a byte as character
Serial.print(c); // print the character
}
delay(1000);
}
But I2C using an arduino uno as master and attiny2313 using TinyWireS not. I can see on my logic analyzer my arduino sending read to 0x7f(127) but attiny does not answer.
Can't help with that one. I don't even know what "TinyWireS" is.
Are you getting any signs that the '2313 is alive (like a status LED flash)? How are you clocking '2313? Vcc is the same value for both Arduino and Tiny? A 4.7K pull up on each of the correct pins? Carefully check pinout on each end (SCL is pin 19 on 2313 DIP package, SDA on pin 17). Make sure these match to Arduino pinouts for SCL/SDA.
If none of that helps, not sure what next. It should work on '2313 if it worked on '85.
Are you getting any signs that the '2313 is alive (like a status LED flash)?
Yes, I have a logic analyzer plugged on a PIN and on software I implemented a simple pin pulse(LOW, HIGH).
How are you clocking '2313?
8Mhz external crystal with fuses OK.
Vcc is the same value for both Arduino and Tiny?
That was the problem. I was powering attiny2313 from a 5V regulated power supply, than I plugged arduino on VIN. I figured out that 5V thru regulator gives <5V on arduino making logic HIGH <5V and attiny didn't understand what's high and what's low. So, plugging on 5V make it works.
Also, I noted that if I power my attiny2313 before arduino, the wire library does not work. on Wire.requestFrom my arduino hangs. I reset my attiny and it resumes on the same time. To work around this I plugged an arduino pin on attiny reset pin to reset it on the last setup() line.
Thanks for the help, you really gives me some points that I didn't think about.
Also, I noted that if I power my attiny2313 before arduino, the wire library does not work
That may be a problem related to the Brown Out Detector. If you're using the Tiny Core to set the fuses I believe the BOD is disabled. I suggest setting the BOD to 4.3 volts if it is not already.
Where do you live? Do you have plans to travel to Brazil? I owe you a beer.
I set the fuses to FUSE_L = 0xff and FUSE_H = 0x99(was FUSE_H = 0x9f). As datasheet says 100 = 4.3V on BOD. It works perfectly.
I didn't know what is BOD, I read datasheet and read a little, just to see if I understood correctly, it's used on comparison by microcontroller to "detect" what's HIGH right?
I'm playing with this little bastards(started with arduino, now standalone atmega's and attiny's, ...) for 6 months only.
Dallas. (I suspect you can guess the state and country. :D)
Do you have plans to travel to Brazil?
The closest I will be getting to Brazil in the predictable future is Bogotá, Colombia. Relatively speaking that isn't too far from the Brazilian border but I suspect it is still quite some distance from your location.
I owe you a beer.
Sounds good to me!
I set the fuses to FUSE_L = 0xff and FUSE_H = 0x99(was FUSE_H = 0x9f). As datasheet says 100 = 4.3V on BOD. It works perfectly.
Nice. Glad to hear it.
I didn't know what is BOD
Basically it's a power switch. If the voltage is too low, the BOD turns off power to the processor. If the voltage is above a certain level and stable, the BOD turns on power to the processor. It ensures the processor makes a clean transition from voltage-too-low to voltage-OK.