embedded - Simple serial point-to-point communication protocol -
I need a simple communication protocol between two devices (a PC and a microcontroller). PC must be sent to certain commands and parameters nicely. Microcode needs to transmit an array of bytes (data from the sensor).
should be data (besides parity check, I think I need some other data correction method).
Is there a standard solution to do that? (I only need an idea, not a complete solution).
P.S. Any advice is appreciated PPS Sorry for any grammar mistakes, I hope you understand.
Edit 1. I have not decided that this master / slave protocol or both parties can start communicating. The PC should know that when Micro has done any work and can send data. Micro can be continuously voting when the data is ready, or if any work is done, then the micro data can be sent. I do not know which is better and easier.
Edit 2. Hardware and protocols. C-serial standard used in PC, I will use only I will use RXD, TxD and GND signal. I can not use extra wires because microcontrollers AFAIK does not support them. BTW I am using the ATmega 128 chip.
So I will use fixed baud rate, 8 bits of data, 2 stop bits without parity check (or?).
. That's my main question. Thanks for the suggestion, and the protocol I will search about.
I will use it I had good luck with it In the past, I point to the serial for a point To forget to use only other content content, it will probably be overkill.
In addition to using HDLC to prepare the packet, I format my packets like the following: 802.11
How to overcome this using the U8 cmd is? U8 Lane; U8 payload [lane]; The total size of each command packet is LAN + 2
Then you can define the command like
#define TRIGGER_SENSOR The other advantage is that you can add new orders and if you properly design your parser to ignore the undefined commands, The rear compatibility will be. Putting it all together, the packet will look like the following.
// total packet length flags from zero + sflag + 4 U8; Packet Flame packet end start with HDLC U8 CMD / 0x7e; // tells what to do on the other side of the U8 lane; // payload length u 8 payload [lane]; // zero lane u can be 16cc; U8 Efegag;
The system will then monitor the serial stream for flag 0x7e and when it is there you want to see if it is pklen> = 4 and pklen = lane + 4 and that The CRC is valid. Note, do not rely solely on CRC for small packets, you will get too many false positives and length will also be checked. If the length or CRC does not match, then just reset the length and CRC and start decoding the new frame. If it is a match then copy the packet into a new buffer and pass it on to your command processing function. Always reset the length and the CRC when the flag is received.
Use CMD and lane for your command processing function, and then use a switch to handle each type of command. I also need to send a response to a certain event so that the system behaves like a remote procedure call that is running the event.
For example, a sensor device can have a timer or a command to take a read. It will then format a packet and send it to PC and the PC will reply that it has received the packet. If not, the sensor can re-send the device at the expiration time.
In addition, when you are transferring a network, you should design it as a network stack, just do not forget about the points. My post is with HDLC and
Comments
Post a Comment