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

How to clear the buffer TX in #use rs232

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

How to clear the buffer TX in #use rs232
PostPosted: Mon Aug 24, 2009 11:21 am     Reply with quote

Hi, I'm making a program to communicate the UART of Pic18f452 with four ports RS232 Multiplexed. The problem is that when switching from channel to channel and sending a control word garbage characters are introduced, but when I send the same command for the second time all are fine. I imagine that the problem is in the transmission buffer of the UART. How I can clear this buffer?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Aug 24, 2009 11:53 am     Reply with quote

Clearing of TX buf may be necessary, if you want to switch while a character is transmitted. This would cause garbage at one peer anyway.

I rather guess, that you don't set a correct idle level or cause glitches during switchover.
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Mon Aug 24, 2009 12:05 pm     Reply with quote

Precisely to avoid the glitches during switchover, I introduced a delay(5000) and disable_interrupts(GLOBAL) and disable_interrupts(INT_RDA);
Alan
Guest







PostPosted: Sat Aug 29, 2009 9:43 am     Reply with quote

Had a similar problem, you have to wait for the last character to be out of the TX buffer before disabling the int. Maybe wait a second after putting the last character in the buffer and then disable
ttelmah
Guest







PostPosted: Sat Aug 29, 2009 10:18 am     Reply with quote

This is what the TRMT bit is for.....

Basically, the transmit system, has up to two characters of buffering. There is the transmit register, and the output shift register. You get the TXIF interrupt, when the transmit register empties, but there is still potentially the 'just transferred' character in the shift register, still being sent.
So, when performing serial switching, you have to disable the transmit interrupt, on the last character, then wait for the TRMT bit to go high, and say that the shift register is empty, before turning the bus around.
Since you are the person loading the buffer, presumably you do want the character to be sent. Otherwise, don't load it!.....

Best Wishes
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Mon Aug 31, 2009 7:40 am     Reply with quote

Quote:
when performing serial switching, you have to disable the transmit interrupt


Hi Ttelmah, to do that is not enough?
Code:
disable_interrupts(GLOBAL);
disable_interrupts(INT_RDA)
Delay_ms(2000);


or what the program code that you recommend?
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Aug 31, 2009 9:21 am     Reply with quote

Technically yes, your code should work. However, two issues need to be considered:

1. When you disable INT_RDA for the receive in the middle of a reception characters will be lost.

2. In place of the delay, if you enter a loop and poll the TRMT bit as Ttelmah suggests you don't need the 2 second delay and can turn around the switchover in as little as 10ms or less.
_________________
Google and Forum Search are some of your best tools!!!!
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Mon Aug 31, 2009 1:47 pm     Reply with quote

Please, could you give a example code ??
pilar



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

PostPosted: Tue Sep 01, 2009 7:28 am     Reply with quote

Quote:
when performing serial switching, you have to disable the transmit interrupt, on the last character, then wait for the TRMT bit to go high, and say that the shift register is empty, before turning the bus around.


Hi ttelmah, please can you give a code example?
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Sep 01, 2009 7:38 am     Reply with quote

I actually suspect the circuitry that you are using to "switch" the output.

- hint each switched output needs a pullup or other means to assure that there is no accidental negative glitch during transitions.

The normal idle state of the PIC TX pin is HIGH and is pulled DOWN to
output chars - if your switching circuit does not handle this seamlessly - you will always generate glitches in the stream.

Care to post a link to your SCHEMATIC for the switch ??
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