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

Open Closing internal uart [ Solved ] Thanks

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



Joined: 14 Sep 2003
Posts: 96
Location: Toronto, Ontario, Canada

View user's profile Send private message

Open Closing internal uart [ Solved ] Thanks
PostPosted: Mon Mar 30, 2020 11:07 am     Reply with quote

Using PIC18F2620, Compiler V5.078

My application will be reading from a GPS data serial stream. The data stream transmits every 1 second. I don't require the data stream every second, every 5 minutes would be fine. This GPS module does not have an option to program the how often to transmit data.

What is the best way to open and close the uart port to ignore the data coming from the data stream. This will also stop data going into the circular buffer.

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8, ERRORS, stream=GPS)

disable_interrupts(INT_RDA) / enable_interrupts(INT_RDA) appears to work, but is the best way.

Thanks in advance for any suggestions. Very Happy


Last edited by Jerry I on Mon Mar 30, 2020 7:48 pm; edited 1 time in total
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Mon Mar 30, 2020 12:14 pm     Reply with quote

That is really as good as anything, but has the caveat, that when the
interrupt is re-enabled, you may well get a couple of garbage characters.
Also doing it this way the UART will be in an error state while not
receiving, with a buffer overflow.
There is a general issue with disabling the actual UART, and re-enabling,
that if you re-enable 'mid character', you will get a garbage character,
and depending on how the string is scanned this could cause problems.

Why disable?.
Why not just turn off receipt?.
Just have a single bit flag 'rx_off', and in the UART receive interrupt handler
if this is set, just don't store the character. This then implies that the
UART receipt is still running so the UART won't go into an error.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 30, 2020 1:07 pm     Reply with quote

Assuming you have some kinds of RTC..
within the ISR, check the RTC minutes and store the GPS data if 'minutes' is 0,5,10,15,20, etc.
There's probably a slick way to compare to '5's.. but I can't think of one right now.
I know you need to have a 'flag' so that you get ONE reading and NOT 5 minutes worth......
Also, maybe take 2 readings, compare the data or at least some form of verification as a bad reading between 2 good ones is a 10 minute 'window'.
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

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

PostPosted: Mon Mar 30, 2020 2:48 pm     Reply with quote

Your PIC doesn't have PPS, I've done a thing before where when I don't want my UART to receive, I just set the pin to null like:
Code:
pin_select("U2RX", NULL);
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