I need to use STX, ETX, Length, Data, Checksum , CMD(Command) bytes in my protocol structure. Data and Length will be variable fields where length refers to length of data. I am new to Embedded c and just need an idea, where i can start as I am confused that, what kind of data(structure of data) user should sent over uart to initiate communication with micro controller. The protocol structure I am trying to develop is as follows:
STX|CMD|LENGTH|DATA|CHECKSUM|ETX.
Thanks in advance.
The serial communication between a PC and a peripheral microcontroller is a case.
The simplest, might be the serial 1byte send command without response expected. If a response is required it could return an ACK/NACK to the comamand or data.
The modbus protocol (ASCII/RTU) over serial lines is very well documented and used for many years in vast applications.
The classic IP network has already given solutions to brief communications with simple protocols like ICMP and UDP.
a. IP+ICMP echo Serial medium + SLIP + IP header(20bytes) + ICMP header(8bytes) + N data bytes This ICMP implementation requires 20+8=28bytes for header and N data bytes @9600 for 4 data bytes the time needed is about 32ms @9600 for 32 data bytes the time needed is about 60ms @115200 for 4 data bytes the time needed is about 2.8ms @115200 for 32 data bytes the time needed is about 5.2ms
b. IP+UDP echo Serial medium + SLIP + IP header(20bytes) + UDP header(8bytes) + N data bytes same speed ...
The overhead to accept/buffer/process IP+ICMP/UDP header is typical and not an issue. Even the cheksum in many cases is optional or can be implemented with simple math.
Instead of an Ethernet network adapter you can use the classic serial port either physical as COM1 or virtual by USB to Serial adapters. The slip driver is available (or can be implemented) at Embedded microcontoller side and is available on PC side like Win/XP and almost in all Unix/Linux OS, but is missing on win7/8/10.
Using the IP set the device/service can be expanded to the Internet of Things era.
...
Review chapters on how Asynchronous Serial works, levels, start bits, stop bits, parity, data bits etc. Some books/datasheets from the 1970's or 80's might be illuminating.
Review chapters of data representations, structures, binary numeric forms, etc. Pretty foundational stuff. If you don't grasp this stuff building protocols is going to be a bit difficult.
Discuss with professor/tutor, or review any number of texts on computer architectures, micro-controller design, etc.