You need to send 10 bits, and since you send a byte at a time, you need to send 16 bits. The big question is how much speed is a priority, and how synchronized are the sender and receiver? I can think of 3 answers, depending on these conditions.
Regular sampling, unknown join point
If the device works all the time, you are not sure when you are going to connect (you can join at any time in sequence), but the sampling rate is slower than the communication speed, so the size does not matter to you. I think I will probably do it as follows. Suppose you are trying to send ten bits of abcdefghij (each letter is one bit).
I would send pq0abcde , then pq1fghij , where p and q are error checking bits . Thus:
- no separator required (you can specify which byte you are reading 0 or 1)
- you can pinpoint any 1-bit error so that you know about bad data.
I try my best to find a good error correction code, so I think I just set the pa parity bit for bits 2,3 and 4 (0, ab above) and qa parity bit for 5 6 and 7 (c, d, e above). This may be clearer with an example.
- Suppose I want to send 714 = 1011001010.
- Divide by 2 10110, 01010
- Add bits to indicate first and second bytes 010110, 101010
- calculate the parity for each half: p0 = par (010) = 1, q0 = par (110) = 0, p1 = par (101) = 0, q1 = par (010) = 1
- bytes then 10010110, 01101010
Then you can find many different error conditions, quickly check which byte you send if you lose synchronization, and none of the operations takes a very long time in the microcontroller (I would parity with an 8 search query table).
Dense data, known junction point
If you know that the reader starts at the same time as the writer, just send 4 ten-bit values as 5 bytes. If you always read 5 bytes at a time, then there is no problem. If you want even more space saving and have good sample data, I would compress using huffman encoding .
Dense data, unknown junction
In 7 bytes, you can send 5 ten-bit values with 6 spare bits. Send 5 values:
- byte 0: 0 (7 bits)
- byte 1: 1 (7 bits)
- byte 2: 1 (7 bits)
- byte 3: 1 (7 bits)
- byte 4: 0 (7 bit)
- byte 5: 0 (7 bit)
- byte 6: (8 bit)
Then whenever you see 3 lines in a line for the most significant bit, you know that you have bytes 1, 2 and 3. This idea takes up 1 bit in 56, so it can be made even more efficient, but you would for sending more data at the same time. For example (5 consecutive, 120 bits sent in 16 bytes):
- byte 0: 0 (7 bits) 7
- byte 1: 1 (7 bits) 14
- byte 2: 1 (7 bits) 21
- byte 3: 1 (7 bits) 28
- byte 4: 1 (7 bit) 35
- byte 5: 1 (7 bit) 42
- byte 6: 0 (7 bit) 49
- byte 7: (8 bit) 57
- byte 8: (8 bit) 65
- byte 9: (8 bit) 73
- byte 10: (8 bit) 81
- byte 11: 0 (7 bit) 88
- byte 12: (8 bits) 96
- byte 13: (8 bits) 104
- byte 14: (8 bit) 112
- byte 15: (8 bit) 120
This is a pretty funny problem!