View previous topic :: View next topic |
Author |
Message |
pilar
Joined: 30 Jan 2008 Posts: 197
|
How to clear the buffer TX in #use rs232 |
Posted: Mon Aug 24, 2009 11:21 am |
|
|
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
|
|
Posted: Mon Aug 24, 2009 11:53 am |
|
|
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
|
|
Posted: Mon Aug 24, 2009 12:05 pm |
|
|
Precisely to avoid the glitches during switchover, I introduced a delay(5000) and disable_interrupts(GLOBAL) and disable_interrupts(INT_RDA); |
|
|
Alan Guest
|
|
Posted: Sat Aug 29, 2009 9:43 am |
|
|
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
|
|
Posted: Sat Aug 29, 2009 10:18 am |
|
|
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
|
|
Posted: Mon Aug 31, 2009 7:40 am |
|
|
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: 1933 Location: Norman, OK
|
|
Posted: Mon Aug 31, 2009 9:21 am |
|
|
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
|
|
Posted: Mon Aug 31, 2009 1:47 pm |
|
|
Please, could you give a example code ?? |
|
|
pilar
Joined: 30 Jan 2008 Posts: 197
|
|
Posted: Tue Sep 01, 2009 7:28 am |
|
|
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
|
|
Posted: Tue Sep 01, 2009 7:38 am |
|
|
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 ?? |
|
|
|