Forum: Mikrocontroller und Digitale Elektronik Interrupts in winavr....Problem mit UART Interrupt


von Sarah Heimbach (Gast)


Lesenswert?

Hallo,

ich steige zur Zeit von codevision auf winavr um. Mir reicht in der
codevision Demoversion die 2k flash nicht mehr aus. Im nachhinein muss
ich sagen, dass der automatische Codegenerator gewisse Probleme
bereitet. Ich bin gerade dabei Interrupts in winavr zu testen. Benutze
gerade einen AT90S4433. Meine beiden Interrupt0 und Interrupt1
funktionieren wie sie sollen. Mit dem  UART Interrupt (für RXC) klappt
es leider nicht so. Könnte mir jemand villeicht sagen, wo der Fehler
liegt? (Habe schon im makefile geschaut, aber da muss man bei mir keine
Baudrate angeben, wie im Tutorial beschrieben). In der io4433.h sind 3
Interrupt Vektoren (SIG_UART_RECV, SIG_UART_DATA, SIG_UART_TRANS).
Wofür wird denn der UART_DATA benötigt?


Hier mein Programmcode:


#include <avr/io.h>
#include <avr/io4433.h>
#include <avr/interrupt.h>
#include <avr/signal.h>


SIGNAL (SIG_UART_RECV)
{
  unsigned char temp;
  temp = UDR;
  PORTB = temp;
}

SIGNAL (SIG_INTERRUPT0)
{
  PORTB = 0x01;
}

SIGNAL (SIG_INTERRUPT1)
{
  PORTB = 0x02;
}


int main(void)
{
  PORTB=0x00;
  DDRB=0x3F;

  PORTD=0x00;
  DDRD=0x00;


  // UART initialization
  // Communication Parameters: 8 Data, 1 Stop, No Parity
  // UART Receiver: On
  // UART Transmitter: On
  // RXCIE Interrupt: On
  // UART Baud rate: 19200
  UCSRB=0x98;
  UBRR=0x0C;


  // External Interrupt(s) initialization
  // INT0: On
  // INT0 Mode: Any change
  // INT1: On
  // INT1 Mode: Any change
  GIMSK=0xC0;
  MCUCR=0x05;
  GIFR=0xC0;

sei ();

}


Vielen Dank für die freundliche Unterstützung!

Sarah Heimbach

von Hannes L. (hannes)


Lesenswert?

Das Datenblatt des 4433 meint auf Seite 57:

---------
UCSRA:

Bit 7, RXC: UART Receive Complete
This bit is set (one) when a received character is transferred from the
Receiver Shift
Register to UDR. The bit is set regardless of any detected framing
errors. When the
RXCIE bit in UCSRB is set, the UART Receive Complete interrupt will be
executed
when RXC is set (one). RXC is cleared by reading UDR. When
interrupt-driven data
reception is used, the UART Receive Complete Interrupt routine must
read UDR in
order to clear RXC, otherwise a new interrupt will occur once the
interrupt routine
terminates.

Bit 6, TXC: UART Transmit Complete
This bit is set (one) when the entire character (including the stop
bit) in the Transmit
Shift Register has been shifted out and no new data has been written to
UDR. This flag
is especially useful in half-duplex communications interfaces, where a
transmitting application
must enter Receive mode and free the communications bus immediately
after
completing the transmission.
When the TXCIE bit in UCSRB is set, setting of TXC causes the UART
Transmit Complete
interrupt to be executed. TXC is cleared by hardware when executing
the
corresponding interrupt handling vector. Alternatively, the TXC bit is
cleared (zero) by
writing a logical "1" to the bit.

Bit 5, UDRE: UART Data Register Empty
This bit is set (one) when a character written to UDR is transferred to
the Transmit Shift
Register. Setting of this bit indicates that the Transmitter is ready
to receive a new character
for transmission.
When the UDRIE bit in UCSRB is set, the UART Transmit Complete
interrupt to be executed
as long as UDRE is set. UDRE is cleared by writing UDR. When
interrupt-driven
data transmittal is used, the UART Data Register Empty Interrupt
routine must write
UDR in order to clear UDRE, otherwise a new interrupt will occur once
the interrupt routine
terminates.
UDRE is set (one) during reset to indicate that the transmitter is
ready.

-----------

Dein Compiler kann auch nur die Interrupts benutzen, die von der (im
Datenblatt erklärte) Hardware angeboten werden. Dass es dazu andere
Namen benutzt als das Datenblatt, damit wirst du wohl leben müssen.

Sorry für den schlechten Umbruch, aber ich wollte den Text möglichst
wenig verändern.

Bit- & Bytebruch...
...HanneS...

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.