|
|
View previous topic :: View next topic |
Author |
Message |
Juanote Guest
|
RS232 Problem |
Posted: Tue Nov 07, 2006 11:44 am |
|
|
When i try to receive serial data the sender send "ERR" but PIC receive "ERERR"
ALways.i turn off PIc, i reset it.
if i receive data with a PC, data is OK "ERR",
Baud rate is OK 9600 , 8 bits, no parity,
this is part of my code:
#pragma fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#pragma use delay(clock=8000000)
#pragma use rs232(baud=9600, ERRORS,xmit=PIN_D5, rcv=PIN_D6,stream=COM2)
#pragma use rs232(baud=9600, ERRORS,xmit=PIN_C6, rcv=PIN_C7,stream=COM1)
int ReadString(char* s, int time){
unsigned long timeout;
time= time - 90;//timeout_error=FALSE;
timeout=0;//*100;
while(!kbhit(COM1)&&(++timeout<(time*10))) // 1/2 second
delay_us(5);
if(kbhit(COM1))fgets(s,COM1);
else
Return(FALSE);
return(TRUE);
}
int RSCHK(char *s1, char *s2)
{
return(!strcmp(s1,s2));
}
int KKT(int timeout){
char temp1[20];
char temp2[20];
fprintf(COM1,"KKT10037\r");
if(!ReadString(temp1,timeout))return(FALSE);
strcpy(temp2,"ERR");
fprintf(COM2,"----%s----",temp1);//WITH THIS LINE I CHECK WHAT PIC RECEIVES
if(RSCHK(temp1,temp2)) output_high(OKLed);
else
Return(FALSE);
Return(TRUE);
}
void main(){
if(!KRSW(1000))Return(FALSE);
} |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 07, 2006 4:42 pm |
|
|
Because you are using a software UART to send the command bytes,
it takes about 9 ms to send the command. My guess is that the
device that receives the command will quickly respond with "ERR",
even before it gets the entire command. But because your PIC
can't do anything else for 9 ms, the hardware UART's receive buffer
fills up and gets an overrun error. The ERRORS directive code
will clear this error, but it will leave the first two characters that it
received ("ER") in the receive buffer. So then the device sends
"ERR" again, but you read the first two characters ("ER" -- still in
the buffer) and the new message. So you get "ERERR".
I'm not sure why you're getting two error messages ("ERR") from
the device. |
|
|
Juanote Guest
|
Hardware RS232 |
Posted: Tue Nov 07, 2006 4:55 pm |
|
|
PIC16f877 have hardware RS232, how can i use hardware routines instead of software routines, ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 07, 2006 5:17 pm |
|
|
You could use the code in the CCS example file, EX_SISR.C, to create
an interrupt-driven receive buffer for the hardware UART. Then the
COM1 stream will be able to receive characters even though the
software UART (COM2) is sending characters.
Also, if you do this, you will need to add the DISABLE_INTS parameter
to the #use rs232() statement for the software UART (COM2). This will
prevent the receive interrupts for the COM1 port from disrupting the
bit timing on the software port (COM2). But interrupts can still occur
between transmission of bytes on COM2, so it will still work OK. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|