Society of Robots - Robot Forum
General Misc => Misc => Topic started by: ukesh on December 02, 2009, 09:20:35 AM
-
Hello!
I'm trying to send a data to the axon through hyper terminal (UART1). But it doesn't seem to work ??? But the code compiled without an error. Am i doing something wrong?
my code:
void control(void)
{
int temp;
rprintf("\n enter the data");
temp=uart1GetByte();//returns -1 if no data present
if (temp==1)//if data received
while(1)
{
servo(PORTE,4,1400);
delay_ms(20);
}
}
-
You have the while loop in the wrong spot. Do this:
void control(void)
{
int temp;
rprintf("\n enter the data");
while(1)
{
temp=uart1GetByte();//returns -1 if no data present
if (temp==1)//if data received
servo(PORTE,4,1400);
delay_ms(20);
}
}
-
Tried your code. But doesn't seem to work too. ???
-
Can you define 'doesn't seem to work'?
We can't help if you don't tell us any information :P
-
We can't help if you don't tell us any information :PSure ;D
On the hyper terminal, i get enter the data statement. After that when i press 1, and press enter in my keyboard nothing happens. The program just seems to stop there?
-
How do you know nothing happens?
Add a line in your code to reply when it gets data:
void control(void)
{
int temp;
rprintf("\n enter the data");
while(1)
{
temp=uart1GetByte();//returns -1 if no data present
if (temp==1)//if 1 received
{
servo(PORTE,4,1400);
rprintf("stuff received");
delay_ms(20);
}
}
}
-
I think the data is not sent to the axon. It gets stuck at the same place of the program
-
Lets just use my code. Put this in the control() function and see if pushing r helps.
char temp;
while(1)
{
temp=uart1GetByte();//returns -1 if no data present
if (temp == 'r')//if data received
rprintf("stuff");
}
-
It works ;) And when i try this code it doesnt.
void control(void)
{
int temp;
rprintf("\n enter the data");
while(1)
{
temp=uart1GetByte();//returns -1 if no data present
if (temp==1)//if data received
rprintf(" entered no is 1");
}
}If you dont mind, can you explain why the first code didnt work? you said i placed the while loop statement in the wrong place. In my first code, the axon gets input once and if that input is equal to 1, the servo runs for an infinite time. Am i understanding something wrong?
-
In my first code, the axon gets input once and if that input is equal to 1, the servo runs for an infinite time.
In your first code, you have an infinite while loop with the servo code in it. Your code would never exit that while loop to check for a new character.
-
if (temp==1)//if data received
That line is expecting a value of 1 or 0x01. That is an ASCII "Start of Header" or a 'Control A'. Is that the keys you pressed?
The code example that did work used
if (temp == 'r')//if data received
which is expecting the 'r' ASCII character.
Here is info on ASCII:
http://en.wikipedia.org/wiki/ASCII (http://en.wikipedia.org/wiki/ASCII)
edit: corrected the 'r' character.
-
The code example that did work used
if (temp == 'r')//if data received
which is expecting a Carriage Return ASCII character.
'r' is the character r. '\r' is carriage return.
Chelmi.
-
It now works guys. Thanks for pointing me about ASCII code :)
-
Woo Hoo, isn't it a great feeling.