CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Strange problem with USART.

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Vovachess



Joined: 15 Mar 2004
Posts: 33
Location: Swiss

View user's profile Send private message Visit poster's website ICQ Number

Strange problem with USART.
PostPosted: Sun May 08, 2005 10:36 am     Reply with quote

Hello All
I have one strange problem with data receive over RS232.
My mC communicate with PC. PC sends each sec data “AT+iCOM=OK\r\n”. The software sees first data packets from PC well. Second, third an so on… data packets from PC software doesn’t see. Very strange. Looks like all data packets from PC are “not coming”, except first one. Does anybody have such kind of trouble?… Could it bee some buffering or I dont know? …Ideas?
Thanks forward.

Code:


#include <18F252.h>
#include <string.h>
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

char timed_getcV(long timedel) {
long time;
time=0;
while(!kbhit() && (++time<timedel))
delay_us(10);
if(kbhit()) return (getchar());
else return (0x87); // if nothig comes return 0x87 as error
}

int chek_A(){
unsigned char i=0,k=0;
char recieve_byte=0, *ptr;
int16 countr=0;
for (k=0;k<3;k++) {
countr=0;
do{
recieve_byte=timed_getcV(150000);
countr++;
}
while ((recieve_byte!=0x4F) && (countr!=10));
....bla bla bla---
}
return 0;
}
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun May 08, 2005 11:17 am     Reply with quote

Sounds like an overflow of the hardware UART receive buffer. The UART can only buffer up to three characters, if you are not reading this buffer fast enough it will get totally filled after which the UART stops receiving and sets an error-bit (overflow). Receiving will only resume after resetting the overflow flag.

A quick way to test if this is your problem is to add the ERRORS directive to the "#use RS232" line. This will clear the error-flags when errors occur, so the UART stays enabled. Please note that this clears the error-flags but you will still miss characters.

The best solution to all above is to service the receive of RS232 data in an interrupt routine. This interrupt routine will then put the incomming data in a buffer that is large enough for your application. Many examples can be found when searching this forum with key words like "ring buffer" and "serial".
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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