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 CCS Technical Support

trouble with usart pic16f628A

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



Joined: 30 Jan 2008
Posts: 4

View user's profile Send private message

trouble with usart pic16f628A
PostPosted: Fri Jul 25, 2008 1:52 pm     Reply with quote

I'm working with the pic 628A. I need to work with usart.
I receive data from GPS in rcv=PIN_B1 and transmit this data by
xmit=PIN_B2, to the terminal soft in a PC.
With the next code it works ok:
Code:
#if defined(__PCM__)
#include <16F628A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOMCLR,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=4800, xmit=PIN_B2, rcv=PIN_B1,stream=PC)
#endif
#include <stdlib.h>

int c;
void main() {
printf("\r\n\RUNNING\r\n");

while(TRUE){
c = fgetc(PC); //read character from UART
fputc(c,PC); //put character to PC
}

on the hyperterminal I can see the next and more:
Code:
\0A
\0ARUNNING\0D
\0A$PSRFTXT,Version:GSW3.2.0PAT_3.1.00.12-SDK001P1.00d
\0D
\0A$PSRFTXT,Version2:F-GPS-03-0607031\0D
\0A$PSRFTXT,WAAS Disable\0D
\0A$PSRFTXT,TOW: 512216\0D
\0A$PSRFTXT,WK: 1488\0D
\0A$PSRFTXT,POS: 2730091 -4488622 -3604509\0D
\0A$PSRFTXT,CLK: 94823\0D
\0A$PSRFTXT,CHNL: 12\0D
\0A$PSRFTXT,Baud rate: 4800 \0D

It works ok. But when I want to add the line printf("Hola") it does not work ok.
Code:

int c;

void main() {
printf("\r\n\RUNNING\r\n");

while(TRUE){
c = fgetc(PC); //read character from UART
fputc(c,PC); //put character to PC
printf("Hola");
}
}

on the hyperterminal I can see only the next :
Code:
\0A
\0ARUNNING\0D
$HolaPHolaSHolaRHola

Why can I see only the four characters $PSR with the four "Hola" between them ?
Which is the problem with printf("Hola") in the loop ?
Thank you in advance.
Ttelmah
Guest







PostPosted: Fri Jul 25, 2008 3:10 pm     Reply with quote

Time.
The modem is sending the characters at 4800bps. The ouput sends characters at 4800bps. When one character arrives, there is only time to send _one_ character out, before another character arrives. There is a small amount of buffering (just under two characters only).
Hence the code starts losing characters.
In your case, the internal hardware buffer overflows after the fourth character is received. Because you don't have the 'ERRORS' keyword in the UART setup, this stops further receiving (hang the UART, with an overrun error). With 'ERRORS', the code will no longer hang, but will simply miss about 2/3rd of the characters.
Now, the GPS, should only send it's data in short bursts, with quite long gaps between them. If you want to send more data than is arriving, you need to buffer the incoming serial data. The EX_SISR interrupt driven serial receive code, will work for this, and provided your reply fits before the next packet of data from the GPS, gives the time needed for the PIC to catch up.

Best Wishes
kikirojas



Joined: 30 Jan 2008
Posts: 4

View user's profile Send private message

usart theory or tutorial
PostPosted: Sat Jul 26, 2008 9:18 am     Reply with quote

Dear sirs:
I need to build a system with a hardware(xmit=PIN_B2, rcv=PIN_B1) usart and the other software usart. But I have a lot of doubts about the theory about "two usarts" . I would like help about when a how to use "INT_RDA" "INT_TBE" "kbhit" " need I implement a buffer for incoming data in usart by soft ?" " and in usart by hardware ?" "Need I use the INT_EXT for usart by software ?"
My system must be receive in usart by hardware a gps signal ( 4800 bauds ) , and in a usart by software receive a gsm data and transmit data to 19200 bauds.
Is possible to implement this system with a pic 16f628A with a 20 Mhz crystal.
thank you in advance
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Sat Jul 26, 2008 12:14 pm     Reply with quote

Quote:
Which is the problem with printf("Hola") in the loop ?


Your #use RS232 pre-processor directive is configured to use "streams".

Change the printf("Hola");
to frpintf(PC, "Hola");
_________________
David
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