UART an Attiny2313

Gast #3431899
Lesenswert?

Hallo zusammen
Ich habe folgenden Code, jedoch sehe ich auf dem Computer nur leere 
Vierecke (Ich verwende HTerm).

CPU Frequenz ist in den Fuses richtig eingestellt.

Hier mein Code:
1
#define F_CPU 4000000
2
#define BAUD 9600
3

4
#include <avr/io.h>
5
#include <util/delay.h>
6
#include <util/setbaud.h>
7

8
void inituart()
9
{
10
  UBRRH = UBRRH_VALUE;
11
  UBRRL = UBRRL_VALUE;
12
  // Set
13
  UCSRB = (1 << RXEN) | (1 << TXEN);      // Enable UART receiver and transmitter
14
  UCSRC = (1 << UCSZ1) | (1 << UCSZ0);   // set to 8 data bits, 1 stop bit
15
}
16

17
void transmitbyte (unsigned char data)
18
{
19
  while (!(UCSRA & (1 << UDRE)));   // Wait for empty transmit buffer
20
  UDR = data;                  // Start transmittion
21
}
22

23

24

25

26
int main(void) {
27
  
28
  inituart();
29

30
  while(1) {
31
    transmitbyte('b');
32
    _delay_ms(500);
33
    
34
  }
35
  return 0;
36
}

Kann mir jemand helfen? Danke.
Gast #3431942
Lesenswert?

Das ganze läuft über den internen Oszillator mit einer Taktfrequenz von 
4MHz (habe leider keinen Quarz zur Verfügung).
Das ganze wird mit Atmel Studio compiliert.

Ändern der Baudrate nützt auch nichts..
#3431962
Lesenswert?

Schalte das Terminalprogramm auf Empfang BEVOR der Controller anfängt zu 
senden!

Ansonsten das übliche Verfahren:

Controller aus Fassung ziehen und Rx/Tx brücken. Mit dem 
Terminalprogramm senden. Wenn das Zeichen als Echo zurück kommt, ist bis 
dahin alles OK. Controller wieder rein. Tx-Interrupt einschalten und in 
der Tx-ISR das empfangene Byte wieder zurück senden. Kommen dann 
Hyroglyphen an, ist zu 99,87361% eine falsche Baudrate eingestellt.

mfg.
Gast #3431976
Lesenswert?

During reset, hardware loads the calibration byte into the OSCCAL 
Register and thereby automatically calibrates the RC Oscillator. At 3V 
and 25°C, this calibration gives a frequency within ± 10% of the nominal 
frequency.

Das kann knapp werden.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren