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

How to loose USART data: a choice (PIC16F870).

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



Joined: 28 Jan 2004
Posts: 15

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

How to loose USART data: a choice (PIC16F870).
PostPosted: Fri Jan 30, 2004 1:19 pm     Reply with quote

Hi, I'm quite new to PICs and very very new to CCS. I'm working on an application that has to Aquire data from the A/D every second and ask something on Serial Port every 3 seconds. Considering that

1) The serial response has non-deterministic timing
2) The A/D conversion is much more important

I have to be sure that a Serial Data don't breaks my A/D. I thought to disable USART during acquisition. Now comes the question:

If I receive chars on USART while this is not enabled what happens? I read in the Datasheet that i can see and have to clear the Overrun Bit, otherwise "no further data will be received". Is this true ? How can I ignore some data coming from USART ?
I would like a method to say:
*"Ok, now I'm not longer interested in receiving data: if something arrives just trash it, I have to do something else for the next three seconds!" and then, after three seconds, send a string and receive again serial data for one second and.... GOTO "*" Smile !
Thanks a lot for your attention,

Best Regards

Paolo
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Fri Jan 30, 2004 1:28 pm     Reply with quote

You can disable the UART completely by using the function SETUP_UART().

SETUP_UART(FALSE) disables the UART.

Basically, it clears the SPEN bit and another bit so it won't even be receiving data anymore.

If you are using streams,
SETUP_UART(FALSE,STREAMNAME)
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: How to loose USART data: a choice (PIC16F870).
PostPosted: Fri Jan 30, 2004 4:18 pm     Reply with quote

fadeout wrote:
Hi, I'm quite new to PICs and very very new to CCS. I'm working on an application that has to Aquire data from the A/D every second and ask something on Serial Port every 3 seconds. Considering that

1) The serial response has non-deterministic timing
2) The A/D conversion is much more important

I have to be sure that a Serial Data don't breaks my A/D. I thought to disable USART during acquisition. Now comes the question:

If I receive chars on USART while this is not enabled what happens? I read in the Datasheet that i can see and have to clear the Overrun Bit, otherwise "no further data will be received". Is this true ? How can I ignore some data coming from USART ?
I would like a method to say:
*"Ok, now I'm not longer interested in receiving data: if something arrives just trash it, I have to do something else for the next three seconds!" and then, after three seconds, send a string and receive again serial data for one second and.... GOTO "*" Smile !
Thanks a lot for your attention,

Best Regards

Paolo


Why dont you read the analog input non stop and service the serial port non stop? What you have suggested will use under 1% of the resources available.
Ttelmah
Guest







Re: How to loose USART data: a choice (PIC16F870).
PostPosted: Sat Jan 31, 2004 4:09 am     Reply with quote

fadeout wrote:
Hi, I'm quite new to PICs and very very new to CCS. I'm working on an application that has to Aquire data from the A/D every second and ask something on Serial Port every 3 seconds. Considering that

1) The serial response has non-deterministic timing
2) The A/D conversion is much more important

I have to be sure that a Serial Data don't breaks my A/D. I thought to disable USART during acquisition. Now comes the question:

If I receive chars on USART while this is not enabled what happens? I read in the Datasheet that i can see and have to clear the Overrun Bit, otherwise "no further data will be received". Is this true ? How can I ignore some data coming from USART ?
I would like a method to say:
*"Ok, now I'm not longer interested in receiving data: if something arrives just trash it, I have to do something else for the next three seconds!" and then, after three seconds, send a string and receive again serial data for one second and.... GOTO "*" Smile !
Thanks a lot for your attention,

Best Regards

Paolo

A lot depends on what else the chip has to do?.
One solution, would be to not use the RS232 interrupt. Instead have a 'timer' interrupt at (say) 256 uSec intervals, and use this to handle the AD. Use a 'clock' code similar to that posted here in the last few days. On the one second clock, call "read_adc(ADC_START_ONLY);", then on the next interrupt, call "read_adc(ADC_READ_ONLY);". Your ADC, will then be read over the period of a few uSec (depending on the ADC clock rate), starting at the timer tick. The timings involved in the 'seperated' ADC operations, are so short, that it is not a problem to call these in an interrupt.
In your main code, sit in a 'polling' loop, waiting for RS232 data (and doing any other 'housekeeping' tasks you need. Provided the loop time of the main code, plus the interrupt time for the ADC handler, does not exceed one byte time of the serial, both events will be handled happily, and your ADC, will be synchronous to the clock, and there is no need to disable the serial.
Equally, unless your need for synchronous events is to a few uSec level, you can perfectly well just handle the RS232 using an interrupt driven receive buffer, and the ADC, using similar timer loop, and all that will happen is that in the specific case of a serial character being received a few uSec before the ADC conversion would trigger, is that the conversion would be delayed by the 'handler' time for the serial. You don't say what processor clock you are using, but typically on a reasonably fast chip, this will only be perhaps 20uSec.

Best Wishes
fadeout



Joined: 28 Jan 2004
Posts: 15

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

PostPosted: Sat Jan 31, 2004 11:26 am     Reply with quote

First of all thanks to you all.
Second... I'm taking to take just a little time to read better your posts and then I'll write again.
fadeout



Joined: 28 Jan 2004
Posts: 15

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

I'll try
PostPosted: Mon Feb 02, 2004 3:17 am     Reply with quote

Well, my clock is 4Mhz. In the next days I'll try to implement yours suggestions.

Thank you a lot.

Best Regards
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