![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
TL
Joined: 15 Sep 2003 Posts: 75
|
How to flush software UART Rx buffer? |
Posted: Fri Jul 18, 2008 7:21 am |
|
|
Hi, I know how to flush a hardware UART Rx buffer but how do you flush a software one? Can someone check whether the following code is correct? Also, is it a good idea to use the FORCE_SW option in the "#use RS232" line for a software UART (see code below)? Thanks.
Code: |
#include <18F6720.h>
#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)
// #use fast_io(f)
#use fast_io(g)
#byte port_a = 0xF80
#byte port_b = 0xF81
#byte port_c = 0xF82
#byte port_d = 0xF83
#byte port_e = 0xF84
#byte port_f = 0xF85
#byte port_g = 0xF86
// See CCS help file to see definitions
#FUSES NOWDT // No Watch Dog Timer
//#FUSES WDT // Watch Dog Timer
//#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz
#FUSES PUT //Power Up Timer
#FUSES PROTECT //Code protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV42 //Brownout reset at 4.2V
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NOCPD //No EE protection
#FUSES NOLVP //Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NOWRT //Program memory not write protected
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
// 4MHz clock
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, STREAM=COMMS)
#use rs232(baud=9600, xmit=PIN_G1, rcv=PIN_G2, ERRORS, STREAM=VTS)
#use rs232(baud=9600, parity=N, xmit=PIN_G3, bits=8, STREAM=PRINTER)
#use rs232(baud=9600, xmit=PIN_E5, rcv=PIN_E4, ERRORS, STREAM=EXT, FORCE_SW)
char in_packet[50];
void getReplyFromExt (void)
{
U8 i=0;
char ch;
// Flush any spurious characters waiting
while(kbhit(EXT)) fgetc(EXT);
// Wait for reply from External
while( !kbhit(EXT) );
// If char in RX buffer...
if(kbhit(EXT)) // If data in Rx buffer
{
do
{
ch=fgetc(EXT);
in_packet[i++]=ch;
} while(ch != 0x0D);
}
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Jul 18, 2008 7:32 am |
|
|
A software UART, has _no_ buffering at all, in either direction.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
TL
Joined: 15 Sep 2003 Posts: 75
|
|
Posted: Fri Jul 18, 2008 7:44 am |
|
|
Thanks. Does it mean that the following 2 lines can be deleted from the function? Also, I assume FORCE_SW option is correct in the "#use RS232" line.
Code: |
// Flush any spurious characters waiting
while(kbhit(EXT)) fgetc(EXT);
|
|
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|