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 support@ccsinfo.com

How to use uart Receive interruption (rda)
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
qwwe



Joined: 17 Sep 2017
Posts: 59

View user's profile Send private message

PostPosted: Tue Oct 03, 2017 10:22 am     Reply with quote

Hello,
Now that I'm in the sisr example.
I wrote the program, I want to know how to clear the buffer we defined for the one at the beginning of the program.
To wastes in memory.
Such as arrays where once we put the null character to clear the garbage.
jeremiah



Joined: 20 Jul 2010
Posts: 1315

View user's profile Send private message

PostPosted: Tue Oct 03, 2017 11:12 am     Reply with quote

Depends on what you mean by clear the buffer. Generally to clear it from a buffer perspective, you just do

while(bkbhit){ bgetc(); }

And that reads out all the data resetting the buffer to empty. It doesn't actually put nulls anywhere.

If you actually want to put values in the buffer as well as set it to empty, then you need to:

1. disable the interrupt so you can't put received data on
2. do a for loop through the buffer, setting each array element to the value of your choosing
3. ensure that next_in = next_out to reset the buffer to empty
4. re-enable interrupts
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Oct 04, 2017 12:43 am     Reply with quote

Or (of course), to just reset the buffer so it is seen as having no data, with the minimum instructions, just use:
Code:

   disable_interrupts(GLOBAL);
   next_in=next_out;
   enable_interrupts(GLOBAL);


bkbkit will then say there is no data in the buffer.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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