Reply by Ivan Vernot January 22, 20042004-01-22
Danka,
You are not incrementing rx_size to put the subsequent characters in the
next rx_data[] array element.
Try something like
rx_data[rx_size++] = getchar();

Also the test for (USR & 80) will not give you what you want because as soon
as you read the character from the UART (with getchar())) the RXC flag
(0x80) will be clear by the micro.

To implement the 'until no more characters are received function is a little
tricky.
How can the micro know that "no more chars" are GOING to be received (it
doesn't know the future!).
Typically this is done by saying
"if I get no chars for x msec then I can 'trust' that I will not get any
more" or
"if I have received a particular character code 'x' (say a CR/LF) then I
can 'trust' that I will not get any more", or
"if I get x character then I can trust that I will get no more"
Which way you do it depends on your application.

HTH
Ivan Vernot
----- Original Message -----
From: "knightbanana" <emf@emf@...>
To: <avrclub@avrc...>
Sent: Friday, January 23, 2004 11:33 AM
Subject: [AVR club] data receive problem in uart > hi guys!
> im danka and i have a small problem with uarts. i'm developing a
> program that would receive characters from uart. the characters are
> placed in an array of unsigned characters with a certain size. what
> i would want to do is to receive characters until the size of the
> character array reaches its limit or until no more characters are
> received. then the program goes to a subroutine that parses the data.
> so far this is a part of my code:
>
> #include "io8515v.h"
> .
> .
> #define BUFFER 110 //maximum size of char array
> .
> .
> //global variables
> int rx_size=0;
> unsigned char rx_data[BUFFER]; //holds data from uart
> ...
> #pragma interrupt_handler rx_recieve:iv_UART_RX
> ...
> void rx_receive(void)
> {
> rx_data[rx_size] = getchar();
> if((x_size>=BUFFER) && !(USR & 80)){
> parse_data(rx_data,rx_size);
> rx_size=0;
> }
> }
>
> i'm sending 0x1e 0x00 0x0c 0x02 0x00 0x01 0x00 0x32 0x08 characters
> from my pc to the stk500 uart. but what is really happening is that
> i have to send the above characters a couple of times before the
> routine goes the parse_data subroutine, and i only receive a char
> array filled with only with 0x01. can someone please help me with
> this one? thanks a lot guys! >
>


Reply by knightbanana January 22, 20042004-01-22
hi guys!
im danka and i have a small problem with uarts. i'm developing a
program that would receive characters from uart. the characters are
placed in an array of unsigned characters with a certain size. what
i would want to do is to receive characters until the size of the
character array reaches its limit or until no more characters are
received. then the program goes to a subroutine that parses the data.
so far this is a part of my code:

#include "io8515v.h"
.
.
#define BUFFER 110 //maximum size of char array
.
.
//global variables
int rx_size=0;
unsigned char rx_data[BUFFER]; //holds data from uart
...
#pragma interrupt_handler rx_recieve:iv_UART_RX
...
void rx_receive(void)
{
rx_data[rx_size] = getchar();
if((x_size>=BUFFER) && !(USR & 80)){
parse_data(rx_data,rx_size);
rx_size=0;
}
}

i'm sending 0x1e 0x00 0x0c 0x02 0x00 0x01 0x00 0x32 0x08 characters
from my pc to the stk500 uart. but what is really happening is that
i have to send the above characters a couple of times before the
routine goes the parse_data subroutine, and i only receive a char
array filled with only with 0x01. can someone please help me with
this one? thanks a lot guys!