Receiving coordinate information over USART
Posted: Wed May 04, 2011 10:13 am
I have the TC553/852 control module and I am struggling to get the coordinates from my touches on my AVR. I have a feeling I'm getting data-type conflicts.
here's my code:
As you can see, I'm trying to read in the data as characters; when I was in debug mode in my AVR dragon I step by stepped through the USART input from touching the screen and I was getting anywhere from 4-5characters up to 7-8 characters...
I know in the documentation its only supposed to respond with 4 bytes:
"X,Y "
'X' = byte value of x coord
',' = a char comma
'Y' = byte value of y coord
' ' = stop character....
What am I doing wrong here at I'm receiving so many bytes? Are they being sent in characters (what I assumed when the int values weren't reading in properly)
Please help!
here's my code:
Code: Select all
usart_putc(0x05);
usart_putc(0x01);
wait(); //activates touchscreen
while(1){
if(!uart_buffer_empty()){ //recieved touchscreen input
_delay_ms(100.0);
input_decode();
}
}
//decodes the input x,y from the LCD
void input_decode(){
unsigned char tempin[10];
unsigned char xin[10];
unsigned char yin[10];
unsigned char temp;
int i = 0;
int x, y, tmp;
while(!uart_buffer_empty()){
temp = usart_getc(); //read the buffer
if(temp == ','){
break;
}
else{
tempin[i++] = temp;
}
}
tmp = i;
for(int k = 0; k <= tmp; k++){
xin[k] = tempin[i--]; //reverses the character order
}
i = 0;
while(!uart_buffer_empty()){
temp = usart_getc(); //read the buffer
if(temp == ' '){
break;
}
else{
tempin[i++] = temp;
}
}
tmp = i;
for(int k = 0; k <= tmp; k++){
yin[k] = tempin[i--]; //reverses the character order
}
//code continues to atoi the char arrays and use them as coordinates
I know in the documentation its only supposed to respond with 4 bytes:
"X,Y "
'X' = byte value of x coord
',' = a char comma
'Y' = byte value of y coord
' ' = stop character....
What am I doing wrong here at I'm receiving so many bytes? Are they being sent in characters (what I assumed when the int values weren't reading in properly)
Please help!