Hi,
I was playing with my attiny2313 and UART communication in the way that i uploaded a sketch [sketch1] to my Arduino UNO and sketch [sketch2] to my attiny2313 and connected Tx from attiny to Rx of my Uno. Then i opened up a serial monitor and got some mess - every time it send a signal the arduino received three lines each with one zero.
I tested the same code on my Arduino Nano (arduino nano and attiny was programmed using USBasp and my Uno via built-in USB socket) and got what i wanted - basically there was number 3 showing in serial monitor on each pulse. But with attiny no luck.
Also i noticed (because for UART both uC has to run on the same clock, in this 16Mhz i connected a crystal on Xtal inputs of my attiny) that on serial i get the same result with and without the crystal...even the time between each pulso was the same.
Note: code for my nano was modified because in the way that it could work ex. UDR (On attiny) must be UDR0 (on nano)
The fuses for my attiny i programmed same as standart aruino:
Lfuse: FF
Efuse: FD //typically for arduino is 0x05 but this is the same only with filled up unused bits in register
Hfuse: DE
[sketch1]
void setup() {
// for ARDUINO UNO
Serial.begin(9600);
}
void loop() {
// Print everything thats on serial bus
if(Serial.available() > 0)
{
int value = Serial.read();
Serial.println(value);
}
}
[sketch2]
#include <avr/io.h>
#include <util/delay.h>
#define F_CPU 16000000 // 16Mhz
#define BAUD 9600 // typical BAUDrate (samo on UNO)
#define BRC ((F_CPU/16/BAUD) - 1)
int main(void)
{
UBRRH = (BRC >> 8);
UBRRL = BRC;
UCSRB = (1 << TXEN);
UCSRC = (1 << UCSZ1) | (3 << UCSZ0); //Setting up Tx & Rx registers, stop bits
while(1)
{
_delay_ms(200); // Wait
UDR = 0b00000011; // Write to serial bus
}
}
I assume that it could be something with the crystal but after spending few hours on internet i coulnd find an answer.
Thanks