PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : interrupt problem



xanatos
11.04.2005, 15:44
ich hatte als test einfach vor ausgelöst durch das senden eines bytes via RS232 die LED an bzw. ausgehen zu lassen. allerdings funktioniert das ganze nur ein mal. sprich ich kann sie anmachen.


.include "m16def.inc"

.def temp = r16
.equ CLOCK = 10000000
.equ BAUD = 9600
.equ UBRRVAL = CLOCK/(BAUD*16)-1

.org 0x00
rjmp main

.org URXCaddr ; Interruptvektor für UART-Empfang
rjmp int_rxc

; Hauptprogramm
main:

ldi r16, 0xFF
out DDRB, r16
ldi r16, 0xFF
out PORTB, r16
cbi DDRB, 4
sbi PORTB, 0

ldi temp, LOW(RAMEND)
out SPL, temp
ldi temp, HIGH(RAMEND)
out SPH, temp


; Baudrate einstellen
ldi temp, LOW(UBRRVAL)
out UBRRL, temp
ldi temp, HIGH(UBRRVAL)
out UBRRH, temp

; Frame-Format: 8 Bit
ldi temp, (1<<URSEL)|(3<<UCSZ0)
out UCSRC, temp

sbi UCSRB, RXCIE ; Interrupt bei Empfang
sbi UCSRB, RXEN ; RX (Empfang) aktivieren
sbi UCSRB, TXEN ; RX (Empfang) aktivieren

s1: sei ; Interrupts global aktivieren

loop: rjmp loop

; Interruptroutine: wird ausgeführt sobald ein Byte über das UART empfangen wurde
int_rxc:
sbis PORTB, 0
sbi PORTB, 0
sbic PORTB, 0
cbi PORTB, 0
reti


wäre nett wenn mir jemand erklären könnte warum.

PicNick
11.04.2005, 16:02
Du mußt das RX-Register schon lesen, sonst glaub er, es is voll.

xanatos
11.04.2005, 16:18
sprich:
in temp, UDR
?

ich versteh auch nicht ganz was das damit zu tun hat. er löst den interrupt aus sobald er was empfangen hat. warum muss ich das register dann lesen?

uwegw
11.04.2005, 16:56
rtfm...

Receive Compete Flag and
Interrupt
The USART Receiver has one flag that indicates the receiver state.
The Receive Complete (RXC) Flag indicates if there are unread data present in the receive buffer. This flag is one when unread data exist in the receive buffer, and zero when the receive buffer is empty (i.e., does not contain any unread data). If the receiver is disabled (RXEN = 0), the receive buffer will be flushed and consequently the RXC bit will become zero.
When the Receive Complete Interrupt Enable (RXCIE) in UCSRB is set, the USART Receive Complete Interrupt will be executed as long as the RXC Flag is set (provided that global interrupts are enabled). When interrupt-driven data reception is used, the receive complete routine must read the received data from UDR in order to clear the RXC Flag, otherwise a new interrupt will occur once the interrupt routine terminates.

will sagen, wenn du die empfangenen daten nicht abholst, wird dein interrupt immer wieder aufgerufen...

xanatos
11.04.2005, 17:08
"rtfm..."
was glaubst du was ich die ganze zeit tue?
aber herzlichen dank für die hilfe!