PDA

View Full Version : How do I receive serial data as HEX, not as a string, using the UART



ekeefe
12-08-2009, 05:17 AM
Hello,

I am looking for a suggestion on receiving HEX data using the UART of the Propeller. The objects I have looked at and the example code all require a terminator and use string handling code to parse.

What I need to do is receive a serial message from a device that is in the format:

$AA $55 $00 $06 $01 $53 $74 $61 $72 $74 $03 $14


$AA $55 - The start sequence

$00 $06 - The number of bytes to follow not including the last two (checksum)

$01 - the function to perform

$53 $74 $61 $72 $74 - The data (even though this is the hex equivalent of 'Start', I need to treat the data as raw hex

$03 $14 - The checksum (sum of all bytes, rolls over at $FF $FF)

The code I have seen so far chokes at the $00 (NULL, as a string function should). I need bytes to be received at 9600 bps. Each message can be of varying length.

Any help would be great. If you need further information, please ask.

Thank you,

ED

p.s. The device being controlled is an industrial 'Thermo-Shock' test oven.

MagIO2
12-08-2009, 05:47 AM
Functions rx and tx in the serial objects are used to transfer raw byte data.

So, you should have a loop that waits for $aa, $55 first. If your loop did not recognize it simply reads characters until it finds this pattern.

Next step is to receive the 2 bytes which tell you how long the message is and put that into a word sized variable.

Then a repeat loop makes sense, which simply receives that number of bytes. Maybe you can already create the checksum here step by step.

After that you can compare the checksum with the one you calculated. If everything is fine you can do what ever you want to do with the data. If not immediately go back to step 1.

Depending on propability of transmission errors it might make sense to use the rxtime function, which only waits for a given time.


Helpful information would be to know your level of knowledge in software development. Or in other words: Is what I said enough to get you started?