From: "Don Kinzer" <dkinzer@easystreet.com>
To: <AVR-Chat@yahoogroups.com>
Sent: Saturday, November 20, 2004 10:45 PM
Subject: [AVR-Chat] Re: USART string reception
>
>
> --- In AVR-Chat@yahoogroups.com, "Ian Drennan" <ianid@s...> wrote:
> > I [...] want to receive and store a string of 10 bytes transmitted
> from the PC. [...] I am using the USART in asynchronous mode on the
> mega8 and want to use the USART Receive Complete Interrupt for each
> received byte. [...] do I need to send an ack for each byte received
> to pace the transmission from the PC?
>
> No, it's simpler than that. You just need to enable the interrupt
> and write an interrupt handler to retrieve the received character.
> Unless you're using "flow control" (which requires additional
> circuitry and logic) the PC will simply send the characters one after
> the other whether or not you retrieve them properly.
>
> If you want to, you could design the two ends of the comm channel to
> implement acknowledgement. You could write special code on the PC
> end to wait for the acknowledgement before the next character is
> sent. This is probably not necessary unless you have special
> circumstances which increase the probability of character loss.
Don
Thanks for your reply and comments. I managed to come up with a interrupt
handler which seems to work fine. I echoed the string back to the PC just to
see that all was intact as intended. This is using the R0 to R9 for
temporary storage. My next attempt will be to store the bytes directly into
SRAM using the Y pointer.
regards
Ian
Here is my sorting code just for interest:
sort_bytes: ;sorts a string of sequential bytes and allocates each byte to a
specific register
inc byte_count
cpi byte_count, 0
breq byte0
cpi byte_count, 1
breq byte1
cpi byte_count, 2
breq byte2
cpi byte_count, 3
breq byte3
cpi byte_count, 4
breq byte4
cpi byte_count, 5
breq byte5
cpi byte_count, 6
breq byte6
cpi byte_count, 7
breq byte7
cpi byte_count, 8
breq byte8
cpi byte_count, 9
breq byte9
;--------------------------
byte0: mov r0, temp
ret
byte1: mov r1, temp
ret
byte2: mov r2, temp
ret
byte3: mov r3, temp
ret
byte4: mov r4, temp
ret
byte5: mov r5, temp
ret
byte6: mov r6, temp
ret
byte7: mov r7, temp
ret
byte8: mov r8, temp
ret
byte9: mov r9, temp
ser byte_count ;reset the byte_count to 255 so next increment will roll it
over to zero
rcall echo_all
ret
;------------------------------------------------------------------------
Echo_all:
mov temp,r0
rcall transmit
mov temp,r1
rcall transmit
mov temp,r2
rcall transmit
mov temp,r3
rcall transmit
mov temp,r4
rcall transmit
mov temp,r5
rcall transmit
mov temp,r6
rcall transmit
mov temp,r7
rcall transmit
mov temp,r8
rcall transmit
mov temp,r9
rcall transmit
ret