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

usart echo

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







usart echo
PostPosted: Wed Jan 23, 2008 10:21 am     Reply with quote

Hello:
I need to implement an echo rs232 with the 16f628
I have the next code and it only works when I write from keyboard .When I write with my hands "123456789abcdef" from the hyperterminal in my monitor I see "123456789abcdef" it´s ok.
When I like send an text file ( containing "123456789abcdef" )from hyperterminal in my monitor I see "13579bdf" )
The hyperterminal is setting ok ( 1200 bauds , 8 bits ...).
Why in the first way its works ok ? and why in the second way its eats characters ?

#if defined(__PCM__)
#include <16F628A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=1200, xmit=PIN_A0, rcv=PIN_A1,stream=PC)
#endif
#include <stdlib.h>
int c;

void main()
{
printf("Press any key to begin\n\r");

while(TRUE) {

c=fgetc(PC);
fputc(c,PC);

}

}
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

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

PostPosted: Wed Jan 23, 2008 10:26 am     Reply with quote

When you type it in, there is time in between characters.
When you send it with hyperterm It is really fast and you lose characters.

Try using hardware usart and interupts and buffers.
Ttelmah
Guest







PostPosted: Wed Jan 23, 2008 10:32 am     Reply with quote

You need to use the chip's hardware UART (on pins B1, and B2). The problem you have, is you are performing the recieve and transmit in _software_. As such, while the chip is sending, it can't receive. When you type the characters by hand, you are slow enough, that the chip can send the character back in the 'gap' between the typed characters. When you send a file, there is no gap, so while the first character is being sent back, the second character is missed, and so on.

Best Wishes
kikirojas
Guest







usart echo
PostPosted: Wed Jan 23, 2008 10:33 am     Reply with quote

Thank you .
I need the hardware usart for other application. I need the software usart for connect with a gps and its also eat characters .
John P



Joined: 17 Sep 2003
Posts: 331

View user's profile Send private message

PostPosted: Wed Jan 23, 2008 10:51 am     Reply with quote

I've done this, but I tell you, it's not for the faint-hearted. You have to write the code for the software UART yourself, because (I'm pretty sure) the CCS code will hog the processor's attention for the full duration of an incoming or outgoing character. You can do better than that if you use an interrupt when the start bit of a character arrives, and then a timer for each data bit. The trouble is, if you're simultaneously sending a character out and receiving one, you've got competing timer demands. So a lot depends on how many characters you have to receive in a burst--would it be acceptable to swallow them and then regurgitate them a little later, and can you guarantee that there won't be more stuff arrriving while you do it? Could you abandon an outgoing transmission and re-start it, if characters start to arrive? Or could the software UART run really, really slowly, so slowly that you could deal with incoming and outgoing bits at different times, so any inaccuracies in timing would be comparatively small?

If you want operation without any restrictions, I think you need 2 processors, or a processor with 2 UARTs. These chips can do a lot, but some things are just asking too much.
Ttelmah
Guest







PostPosted: Wed Jan 23, 2008 10:57 am     Reply with quote

Or (of course), why not cheat?.
If you just need to echo the incoming characters, connect the incoming data, to one input of a logic 'and' gate, with the other input from your PIC's transmit pin. Connect the output of the gate to the MAX232 or equivalent handling the transmit. Then when characters arrive, they will be echoed by the _hardware_to the transmit output, and if you send (provided you verify nothing is coming at the time), it too will be sent.

Best Wishes
SET



Joined: 15 Nov 2005
Posts: 161
Location: Glasgow, UK

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Jan 23, 2008 11:09 am     Reply with quote

Quote:
I need the hardware usart for other application. I need the software usart for connect with a gps and its also eat characters


So you mainly need to Rx (once the GPS has been configure). As John P said, it can be done, but it's a bit tricky. Your HW UART will need to put chars into a buffer from its ISR. Another thing to watch, even when using the hardware UART, CCS code waits for transmission to be completed (from printf for example). So your software UART will need interrupts for the start bit (falling edge) and then from a timer to check the bits.
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