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

Verify that the data received by Uart

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



Joined: 30 Jan 2008
Posts: 197

View user's profile Send private message

Verify that the data received by Uart
PostPosted: Fri Feb 03, 2017 2:58 pm     Reply with quote

Hi, I am receiving data through the Uart, but sometimes I receive garbage, I need to verify that the data received are ascii (0-9, A-F) and are different, discard them, how could I do this?

Thank you...
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Fri Feb 03, 2017 3:28 pm     Reply with quote

Look in the manual for 'is_among', and it's associated functions.

Either setup your own string for the characters you want, or use one of the supplied variants (is_alnum etc.). If this returns 'false', reject the character.
temtronic



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

View user's profile Send private message

PostPosted: Fri Feb 03, 2017 5:46 pm     Reply with quote

hmm 'sometimes garbage'....

Are you using the internal oscillator AND a fast baud rate ? It could be the timing is off just a tad..


Jay
benoitstjean



Joined: 30 Oct 2007
Posts: 566
Location: Ottawa, Ontario, Canada

View user's profile Send private message

PostPosted: Sat Feb 04, 2017 7:53 am     Reply with quote

Your explanation is very vague. Post a specific example of what is being transmitted, what you are expecting to receive from that transmission and what is actually being recieved.

Given that you haven't provided much details, how can you determine if 0-9 and A-F isn't garbage as well? Garbage is random therefore random can be anything, including what you're actually looking for. So how will you know that the data received is valid or not? Again, without any details on your scenario, it's somewhat impossble to troubleshoot.

You also haven't specified the UART speed you are using, its configuration as well as your device's crystal/clock speed, CCS version and PIC type.

Also perhaps clock is not the ideal speed for a perfect UART calculation and eventually the UART is out of sync.

Ben
temtronic



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

View user's profile Send private message

PostPosted: Sun Feb 05, 2017 6:20 am     Reply with quote

You don't say where the data is coming from but I'd use PC running a terminal program to look at the 'data'. That way it will confirm/deny that the 'data' actually being sent is 100% correct.
I've got a 15 year old PC running Win98SE and it's sole purpose is doing that. NOTHING else on the PC...no internet, no games,noexcell, etc. Just the terminal program...and QB45.

With 'random garbage' you have to systematically debug, confirm this works, that doesn't....
..otherwise you'll spend hours or days and THEN discover...oops, forgot to conent the cable up to the correct comport...

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19548

View user's profile Send private message

PostPosted: Sun Feb 05, 2017 10:25 am     Reply with quote

Lets take a deep breath, and 'step back.

For a standard serial connection, data should almost never be anything other than what is sent. For 99.999% of the time.

Now, if you are seeing 'garbage' then the big problem first is understanding 'why'.

Then simply rejecting anything other than hex, won't really be helpful. Problem is that as benoitstjean says, if the garbage is 'random', then it is equally likely to be accepted by a test for 0-9 and A-F, as rejected. So (for instance), '1' gets added, and a '1' gets turned into a '2'. It'll still be accepted, but will be wrong data.

Now there is a test in the 'isamong' suite for 'isxdigit', which tests that a character is a hex digit. This is useful if (for instance), you want to find the part of a message that contains the hex numbers, but the point being made is that if you are genuinely seeing 'garbage', you need to find 'why', before trying to filter the characters....
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