I just figured out to transfer data in my project is using synchronous communication. But, i need to change data to frame. FYI my project is to transfer image from OV7670 (camera module) to PC using RS-232. Thank's :)
generaly there are a two methods, how to make a comunication packet from data stream. First method is by using text packets. Text packets can include special chars for packet start (optional) and for packed end (usually Enter). But packet like this can not contain a general data (usually only visible characters from ASCII). General data has to be converted to text (using HEX or DEC representation, for example). This method is great for small packets, it offers great potential for debuging.
Better method for You is to use a general data packet. I don't know, how big are Your pictures, but text representation of the picture can double the size of picture. And RS232 is not so fast.
You can use one of the standard binary protocols, but my recomendation is to create Your own protocol. Your new protocol should designed using this rules:
1, You have to define a minimal time pause in between packets which is longer, than maximal delay between any two bytes in packet
2, every packet shoud begin with header - fixed sequence of bytes, which You can simple recognise in receiver
3, optionaly You can send the number of data bytes
4, then You can send the data
5, at the end of data I recomend to add some type of checksum.
Receiver waits for start of transmission. If there is a delay between bytes longer than minimal value, receiver just has to clear buffer and waits for the new start. After the header is receved, receiver check the header and if it is OK, then waits for data.
End of packet is detected using minimal delay between bytes or using known packet size (which can be included in packet itself). If the whole packet is in buffer, then You just check the checksum and if it si OK, You are done.
This method I used for design of several protocols and it works good. I also recomend to imlpement some mechanism to ensure, that packet in the receiver is OK. You can send a special OK packet (for example) from receiver to transmitter and repeat the transmission when a timeout occurs.
But if it is possible, consider to use other bus. I think that for example Ethernet is better for Your case.