View previous topic :: View next topic |
Author |
Message |
edi
Joined: 22 Dec 2003 Posts: 82
|
RS232 driver |
Posted: Wed Jul 28, 2004 1:15 am |
|
|
Hi,
I want to send & receive strings to a controller via RS232.
I'm using PIC 16F877A.
I have to send it a control string like ("AT") : printf("at\r\n");
The controller return every char as echo and add his response string like : "OK" or "OK 1234".
I'm looking for C code that can check the response (ignore the echo).
The receive must be complete string and interupt driven.
Thanks in advance.
Edi |
|
|
carlosma
Joined: 24 Mar 2004 Posts: 53 Location: Portugal
|
|
Posted: Wed Jul 28, 2004 4:53 am |
|
|
Hello
I make something similar. But when send a printf"AT... , I disable interrupt #int_RDA. Now I do not read the echo.
enable_interrupt when I need to read from RS232.
Carlos |
|
|
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
|
Posted: Sat Jul 31, 2004 11:23 pm |
|
|
You have to decide how many characters you want to receive, or you must send a specific character like EOF, etc. which will signify that the data transmission has ended, check your controller and see if it sends this end of data transmission character.
The following code should give you an idea.
I have assumed total characters to be 5, and end of transmission character as EOF. (13 )
You must paste this code extract to your program.
Also after receiving the data you must check manually for the required string.
thank you
arun
char dt(5);
int n;
#int_RDA
rs232()
{
char c;
c=getc();
if (c!=13)
{
dt(n)=c;
n++;
if (n>5)
{
n=0;
// The buffer is full, clear the buffer and start again. Also execute rest of the code.
}
}
} |
|
|
Guest
|
|
Posted: Sun Aug 01, 2004 1:55 am |
|
|
Thanks,
Edi |
|
|
|