Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 3 > Timer for RS232 input loop??

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Timer for RS232 input loop??
Moderator:
RKRM

Post Reply
Follow this topic



Timer for RS232 input loop??

srf posted on 16 Oct 2012 12:19 PM PST
Member
2 Forum Posts

I've been struggleing with how to add a timer to a loop that will exit after a discrete amount of time (say 10 seconds).

What I have going on is I'm collecting input from an RS232 interface to fill up a string (that includes a checksum at the end).

The loop exits when the checksum is received. I also want to exit if I  don't receive it after a discrete amount of time (that 10 second value above).

I tried to implement it using a 8 bit counter that was clocked by a 1 seconds clock with the result that I could get the counter value to 10, exit, but never able to reset the counter back to 0 for the next pass (kept exiting every 10 seconds

How do folks that do this type of thing implement implement a time so your not stuck forever in the serial processing loop forever with garbage in the string buffer?




Re: Timer for RS232 input loop??

Bob Marlowe posted on 16 Oct 2012 01:25 PM PST
Top Contributor
1768 Forum Posts

For receiving data over a serial interface non-blocking the best solution is a combination of Rx driven interrupt and a circular buffer.

If you prefer, another way (easier) is to define for the component a buffer large enough and let int be handled by the internal interrupt which will be enabled automatically. You just have to poll for the buffer containing the required amount of chars.

 

If you still are interrested in exiting a loop: Set up a timer, start it when entering the routine, poll in a loop Rx and timer status and exit when any of them occurs after stopping the timer and if Rx had a char get it and return the value, else return an indication for no char.

 

Happy coding

Bob

 



Re: Timer for RS232 input loop??

srf posted on 18 Oct 2012 06:37 AM PST
Member
2 Forum Posts

If you still are interrested in exiting a loop: Set up a timer, start it when entering the routine, poll in a loop Rx and timer status and exit when any of them occurs after stopping the timer and if Rx had a char get it and return the value, else return an indication for no char.

 

Happy coding

Bob

Actually, that is what I did using a counter and a 1HZ clock. I poll the counter for being greater than 10 seconds, clear things and return to main. Unfortunately, I can not clear the counter and stop it, so every 10 seconds it continues to exit because the counter counts to 10. I've roamed the examples and do not have a clear understanding of why it behaves and played with all kinds of library methods to no avail.






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20