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

Clearing UART HW 3 Byte Buffer

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



Joined: 06 Nov 2013
Posts: 27

View user's profile Send private message

Clearing UART HW 3 Byte Buffer
PostPosted: Thu Dec 05, 2013 12:50 pm     Reply with quote

Hello , I`m trying to clear the UART incoming buffer but It just wont work...I look on the forum and looking on the 18f25k22 datasheet I come up with this code but it still wont work...
Code:

#byte RCREG = 0xFAE // UART1 RCREG REGISTER



Code:

char NULL;
NULL= RCREG;
NULL= RCREG;
NULL= RCREG;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 2:58 pm     Reply with quote

The 18F25K22 has two UARTS. RCREG1 at 0xFAE is for UART1.
Are you sure you are using UART1 (and not UART2) ?

Post a small test program that demonstrates to us how it doesn't work.


Also here in your example, you're using a reserved word in the C
language for a variable name. Look in stddef.h and you'll see that
NULL is defined there. It's not a good idea to use reserved words
for variable names. Use something else like "temp" or "dummy" or
something.
Quote:
char NULL;
NULL= RCREG;
NULL= RCREG;
NULL= RCREG;
pulurumbuluruciu



Joined: 06 Nov 2013
Posts: 27

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 4:07 pm     Reply with quote

Hi , the UART1 TX/RX are connected together via a open collector buffer , UART2 the same, the purpose is acting like a 1 wire databus , preventing the echo getting in the receive buffer.
Code:

#include <18F25K22.h>
#FUSES NOWDT, WDT128, INTRC_IO, NOFCMEN, NOIESO, NOHFOFST, NOMCLR, NOLVP, NOXINST
#use delay(clock=64000000)
#use rs232(uart1, BITS=8,baud=9600, PARITY=N, STOP=1, STREAM=U1,errors)
#use rs232(uart2, BITS=8,baud=9600, PARITY=N, STOP=1, STREAM=U2,errors)
#byte RCREG1 = 0xFAE
#byte RCREG2 = 0xF74


#int_rda
void RDA_isr(void) {
DISABLE_interrupts(INT_RDA2);
fputc(fgetc(U1),U2);
ENABLE_interrupts(INT_RDA2);
CHAR DUMMY;
DUMMY=RCREG2;
DUMMY=RCREG2;
DUMMY=RCREG2;
}


#int_RDA2
void  RDA2_isr(void)
{
DISABLE_interrupts(INT_RDA);
fputc(fgetc(U2),U1);
ENABLE_interrupts(INT_RDA);
CHAR DUMMY;
DUMMY=RCREG1;
DUMMY=RCREG1;
DUMMY=RCREG1;
}

main(){
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
enable_interrupts(INT_RDA);
enable_interrupts(INT_RDA2);
enable_interrupts(GLOBAL);
    while(true){


}
}





The programs just ..jams..if i use Getc() after each putc() to get rid of the echo ,it will work but it will eat to much time.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 4:27 pm     Reply with quote

Is this your circuit ?
http://www.eeweb.com/company-blog/ixys/uart-to-implement-a-1-wire-master/

Or this:
http://e2e.ti.com/cfs-file.ashx/__key/communityserver-discussions-components-files/166/4503.OneWire.bmp

Or this (upper one) ?
http://www.ccsinfo.com/faq.php?page=connect_pics
pulurumbuluruciu



Joined: 06 Nov 2013
Posts: 27

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 4:31 pm     Reply with quote

Hi , at each UART is this :
http://www.maximintegrated.com/images/appnotes/214/1189Fig02b.gif
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 5:05 pm     Reply with quote

It takes 1.04 ms to finish transmitting the character (at 9600 baud).
After the character is completely transmitted, then it will also be in the
receive buffer (because of your connections). But, you are clearing
the buffer before you have received the character in it. This is why
the getc() method worked. It waits for a character to be in the buffer.

In other words, when you are doing the three reads of RCREG, the
character is still in the process of being shifted out at a slow bitrate
of 104us per bit.
pulurumbuluruciu



Joined: 06 Nov 2013
Posts: 27

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 5:31 pm     Reply with quote

I understand. I`m gonna use the TXSTA TRMT flag to check if the character has been shifted. Hope will work. Thank you very much
asmboy



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

View user's profile Send private message AIM Address

PostPosted: Thu Dec 05, 2013 5:44 pm     Reply with quote

Code:

byte junk;
int8 safety=0;

while(safety<100){
  if (kbhit) junk=getc();
  delay_ms(50);
   safety++;
}


so long as 'ERRORS' defined in port open,
never known the code to fail to empty the system out,though it commits
up to 5 seconds to making sure, even at very high baud
pulurumbuluruciu



Joined: 06 Nov 2013
Posts: 27

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 6:05 pm     Reply with quote

Sorry Asmboy , but I dont understand this part "never known the code " Embarassed ..could you please rephrase...I`m not such a fine english user.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 05, 2013 6:55 pm     Reply with quote

asmboy,
He wants it done quickly. His preference would be to do it in 10 usec or
less, but he can't.
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