??? 02/16/07 06:56 Read: times |
#133103 - Look for the start sentinel Responding to: ???'s previous message |
You need to look at the bits you are reading. Unfortunately, your code can't cope with any leading bits that are wrong, thus when you output the data, it is wrong. There's a couple of ways of coping with this - usually you have to look for the start sentinel sequence - then you know you've got the start, then you are sync'ed. To this end, you can just read bits into memory then look for the start sentinel and decode from there, or have your interrupt routine a bit smarter and it looks for the start sentinel. I did this many (>10) years ago on a '2051, but I cannot recall the exact method I used. I might have the code hidden away, so I'll check at some later stage. The start sentinel is there for a reason, also with a little more code you can read the card in both directions by looking for the start and end sentinels. Again ,I cannot recall if I implemented this. You can't expect just to read bits from the card reader and expecting it to be synchronised. I'd probably use a window detector method - shift the bits into a byte, mask and test for the start sentinel or the end sentinel in reverse for each bit until you find a sentinel. Then use a finite state machine to control the sequence. |