Zdravím.
Prosím o pomoc s assembler procedúrou na príjem dát cez USART. Potrebujem to na komunikáciu s XPortom. Pri krokovaní (s nastavením RXC) som prišiel na to, že sa mi vymaže UDR ešte predtým, než ho prečítam.
Kde robím chybu?
Fragmenty programu:
equ MaskBaudR = 0b00011111; maska nastavenia Baud Rate
.equ MaskBR00 = 0b00000000; maska pre BaudRate00
.equ MaskBR01 = 0b00000001; maska pre BaudRate01
.equ MaskBR02 = 0b00000010; maska pre BaudRate02
.equ MaskBR03 = 0b00000011; maska pre BaudRate03
.equ MaskBR04 = 0b00000100; maska pre BaudRate04
.equ MaskBR05 = 0b00000101; maska pre BaudRate05
.equ MaskBR06 = 0b00000110; maska pre BaudRate06
.equ MaskBR07 = 0b00000111; maska pre BaudRate07
.equ MaskBR08 = 0b00001000; maska pre BaudRate08
.equ MaskBR09 = 0b00001001; maska pre BaudRate09
.equ MaskBR10 = 0b00001010; maska pre BaudRate10
;
.equ BaudRate00 = 95 ; 2400 bps
.equ BaudRate01 = 47 ; 4800 bps
.equ BaudRate02 = 23 ; 9600 bps
.equ BaudRate03 = 15 ; 14400 bps
.equ BaudRate04 = 11 ; 19200 bps
.equ BaudRate05 = 7 ; 28800 bps
.equ BaudRate06 = 5 ; 38400 bps
.equ BaudRate07 = 3 ; 57600 bps
.equ BaudRate08 = 2 ; 76800 bps
.equ BaudRate09 = 1 ; 115200 bps
.equ BaudRate10 = 0 ; 230400 bps
;
.def BaudRate = R19 ; Baud Rate
.def Work = R16
(********************************************************)
;(* Inicializácia portu D *)
;(********************************************************)
;(* Vsetky vystupy PORTD budu nastavene na log. 0 *)
;(* PORTD bude prijimat a vysielat tieto signaly: *)
;(* -----------------------------------------------------*)
;(* bit 6 - ACW6 - vstup zo Slave6 *)
;(* bit 5 - BR3 - Baud Rate - kod rychlosti USART *)
;(* bit 4 - BR2 - Baud Rate - kod rychlosti USART *)
;(* bit 3 - BR1 - Baud Rate - kod rychlosti USART *)
;(* bit 2 - BR0 - Baud Rate - kod rychlosti USART *)
;(* bit 1 - TXD - vystup na XPort (USART) *)
;(* bit 0 - RXD - vstup z XPort (USART) *)
;(********************************************************)
Init_PortD:
;
ldi Work,(0<<PORTD6)+(0<<PORTD5)+(0<<PORTD4)+(0<<PORTD3)+(0<<PORTD2)+(0<<PORTD1)+(0<<PORTD0) ; nastavenie masky
out PortD,Work
;
ldi Work,(0<<DDD6)+(0<<DDD5)+(0<<DDD4)+(0<<DDD3)+(0<<DDD2)+(1<<DDD1)+(0<<DDD0)
out DDRD,Work ; pin 6..2,0 = input(log0), 1 = output(log1)
;
nop ; pre synchronizaciu
;
ret
;*********************************************************)
;( Inicializácia USART *)
;(********************************************************)
;(* Nastavenie prenosovej rychlosti USART *)
;(* BR4..BR0 - kod nastavenia: *)
;(* -----------------------------------------------------*)
;(* 0 0 0 0 - BaudRate00 2400 bps *)
;(* 0 0 0 1 - BaudRate01 4800 bps *)
;(* 0 0 1 0 - BaudRate02 9600 bps *)
;(* 0 0 1 1 - BaudRate03 14400 bps *)
;(* 0 1 0 0 - BaudRate04 19200 bps *)
;(* 0 1 0 1 - BaudRate05 28800 bps *)
;(* 0 1 1 0 - BaudRate06 38400 bps *)
;(* 0 1 1 1 - BaudRate07 57600 bps *)
;(* 1 0 0 0 - BaudRate08 76800 bps *)
;(* 1 0 0 1 - BaudRate09 115200 bps *)
;(* 1 0 1 0 - BaudRate10 230400 bps *)
;(* 1 0 1 1 - unused *)
;(* 1 1 0 0 - unused *)
;(* 1 1 0 1 - unused *)
;(* 1 1 1 0 - unused *)
;(* 1 1 1 1 - unused *)
;(********************************************************)
USART_Init:
in Work, PortB
andi Work, MaskBaudR
;
cpi Work, MaskBR00
brne noBR00
ldi BaudRate, BaudRate00
rjmp NoBr10
NoBR00:
cpi Work, MaskBR01
brne noBR01
ldi BaudRate, BaudRate01
rjmp NoBr10
NoBR01:
cpi Work, MaskBR02
brne noBR02
ldi BaudRate, BaudRate02
rjmp NoBr10
NoBR02:
cpi Work, MaskBR03
brne noBR03
ldi BaudRate, BaudRate03
rjmp NoBr10
NoBR03:
cpi Work, MaskBR04
brne noBR04
ldi BaudRate, BaudRate04
rjmp NoBr10
NoBR04:
cpi Work, MaskBR05
brne noBR05
ldi BaudRate, BaudRate05
rjmp NoBr10
NoBR05:
cpi Work, MaskBR06
brne noBR06
ldi BaudRate, BaudRate06
rjmp NoBr10
NoBR06:
cpi Work, MaskBR07
brne noBR07
ldi BaudRate, BaudRate07
rjmp NoBr10
NoBR07:
cpi Work, MaskBR08
brne noBR08
ldi BaudRate, BaudRate08
rjmp NoBr10
NoBR08:
cpi Work, MaskBR09
brne noBR09
ldi BaudRate, BaudRate09
rjmp NoBr10
NoBR09:
cpi Work, MaskBR10
brne noBR10
ldi BaudRate, BaudRate10
NoBR10:
ldi Work , 0 ; Set baud rate high(BaudRate)
out UBRRH, Work
out UBRRL, BaudRate
;
ldi Work, (1<<RXCIE) | (1<<TXCIE) |(1<<RXEN) | (1<<TXEN) ; Set RX/TX Enable
out UCSRB, Work
;
ldi Work, (1<<USBS) | (3<<UCSZ0); Set frame format
out UCSRC, Work
ret
;(********************************************************)
;(* USART RX Complete Handler *)
;(********************************************************)
;(* *)
;(********************************************************)
USART0_RXC: ; USART RX Complete Handler
sbis UCSRA, RXC ; Wait for data to be received
rjmp USART0_RXC
in ReceiveData,UDR ; Get at return received data from buffer
reti
;(********************************************************)
;(* Reset *)
;(********************************************************)
;(* $60 - Internal SRAM first address *)
;(* $DF - Internal SRAM last address *)
;(********************************************************)
RESET:
;
cli ; Clear global Interrupt flag
;
ldi Work,RAMEND ; Set Stack pointer
out SPL,Work ; Stack pointer
;
rcall Init_PortD ; Initialize PortD
rcall Init_PortB ; Initialize PortC
rcall USART_Init ; Initialize USART
rcall Init_USI ; Initialize Universal Serial Interface
sei ; Set global interrupts flag
;
;
;
;(********************************************************)
;(* *)
;(* MAIN PROGRAM *)
;(* *)
;(********************************************************)
;(* *)
;(********************************************************)
zaciatok:
Loop:
rjmp Loop
.exit