Protocols used to talk between an embedded CPU and a PC

前端 未结 8 1944
梦谈多话
梦谈多话 2021-01-31 20:21

I am building a small device with its own CPU (AVR Mega8) that is supposed to connect to a PC. Assuming that the physical connection and passing of bytes has been accomplished,

8条回答
  •  滥情空心
    2021-01-31 20:40

    If I wasn't expecting to need to do efficient binary transfers, I'd go for the terminal-style interface already suggested.

    If I do want to do a binary packet format, I tend to use something loosely based on the PPP byte-asnc HDLC format, which is extremely simple and easy to send receive, basically:

    Packets start and end with 0x7e You escape a char by prefixing it with 0x7d and toggling bit 5 (i.e. xor with 0x20) So 0x7e becomes 0x7d 0x5e and 0x7d becomes 0x7d 0x5d

    Every time you see an 0x7e then if you've got any data stored, you can process it.

    I usually do host-driven synchronous stuff unless I have a very good reason to do otherwise. It's a technique which extends from simple point-point RS232 to multidrop RS422/485 without hassle - often a bonus.

提交回复
热议问题