Im trying to save an array from uart rx to an variable and send it to tx, i dont know where is the problem in the code and if the array is saved in the variable but im not receiving any data in the terminal, probably im missing something
.DSEG
.ORG 0X0100
STRNG: .BYTE 128 ;Strings recommended to be even
.CSEG
STRNG2: .DB "Printing aithing from probably the buffer",0X00 ;Strings recommended to be even
RJMP MAIN
MAIN: SBI DDRD,PD1
LDI R16,0X00
LDI R17,0XCF
STS UBRR0L,R17 ;UBRRXL - Usart Baud Rate 0 Register Low| Low byte of Baud Rate
STS UBRR0H,R16 ;UBRRXH - Usart Baud Rate 0 Register High| High 4bits of Baud Rate
LDI R18,0X22
STS UCSR0A,R18 ;UCSRXA - Usart Control and Status Register X A| flags, status and config: (flag after receive)(flag after transmit)(flag buffer data register empty[1 defaul])(flag frame error)(flag buffer overrun)(flag parity error)(U2XX state)(multiprocessor communication state) | set flags acording documentation (all in 0 except UDRE0)
LDI R19,0X06
STS UCSR0C,R19 ;UCSRXC - Usart Control and Status Register X C| flags, status and config: (Usart modes)(parity mode)(stop bits mode)(character size)(clock polarity[for USART])
LDI R20,0X18
STS UCSR0B,R20 ;UCSRXB - Usart Control and Status Register X B| config: (after receive interrupt)(after transmit interrupt)(buffer data register empty interrupt)(rx enable)(tx enable)(character size)(receive data bit 8[for 9bit])(transmit data bit 8[for 9bit])
LOOP: RJMP RX
RCALL WAITT
RJMP LOOP
RX: LDS R21,UCSR0A
SBRS R21,UDRE0
RJMP RX
LDI XL,LOW(STRNG) ;Z POINTER
LDI XH,HIGH(STRNG)
LDS R22,UDR0
CPI R22,0X0D
BREQ TX
LDI XL,LOW(STRNG) ;Z POINTER
LDI XH,HIGH(STRNG)
ST X+,R22
RJMP RX
TX: LDI XL,LOW(STRNG) ;Z POINTER
LDI XH,HIGH(STRNG)
LD R23,X+
CPI R23,0X00
BREQ END
SEND: LDS R21,UCSR0A
SBRS R21,UDRE0
RJMP SEND
STS UDR0,R23
RJMP TX
END: RET
WAITT: LDI R24, 82
LDI R25, 43
L1: DEC r25
BRNE L1
DEC r24
BRNE L1
RET
I cant understand where is the problem
First issue in your program is that AVR8 core starts to execute code from reset vector at address 0 but you have string there. CPU tries to execute its content. Usually at address 0 interrupt vectors table is located. If you don't plan to use interrupts, you can place your code there, but it must start from address 0.
Second issue is that your code waits for character from UART by testing UDRE0 flag:
You should test RXC0 flag to detect character reception:
Third issue is that you initialize current charater pointer (X-register) on every iteration, moreover twice: before testing for end of line and before storing to a buffer.
Fourth issue is that in STORE function you look for NUL terminator as the end of a string but never store it.
The whole program could be like following. I don't know purpose of WAIT function so removed it.
I didn't test it on real hardware but it does work in QEMU.
Hint for optimization: you can use CR character (0x0D) as string terminator. In this case you shouldn't store NUL character but check for CR in SEND: