Go Down

Topic: Reliable communications for small memory microcontrollers (Read 213 times) previous topic - next topic

mjbmikeb2

Hi, does anyone have any recommendations for a reliable communications protocol for a PC/Mac to an atmega328 that doesn't depend on a high memory footprint solution such as TCPIP?

The comms chain will probably look like this:
Mac running Python program > USB to serial converter > Xbee (series 1) > Xbee > serial cable > atmega328
The computer will be polling the atmega328 about once per minute.

The baud rate will be 57600 (to enable occasional over the air programming), but the average data once running rate will only be about 300 bytes per minute, but I need to know that the messages are getting through (or failing).

Adding ACK/NAK and checksums to something like Firmata would create yet another custom protocol, so I would prefer to use an existing standard if at all possible. 

Thanks
Mike

robtillaart

to make a protocol reliable you should follow the steps also taken in TCP/IP -> something like

layer 0 : single bytes

layer 1: group bytes into a packet
* add start and stop byte => determine packet from stream
* add a CRC byte => check packet is OK

layer 2 : get stream of packets right
* add sequence number => check no packet is missing
* send ACK/NACK for every packet with sequence nr.
* optionally add address bytes
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

mjbmikeb2

I found an Xmodem library (http://mrp3.com/xmodem.html) that looks like the sort of thing that will do the job. The minimum packet size is 128 bytes, and the library is designed for writing to SD cards, but can probably be simplified.

robtillaart

xmodem is a file transfer protocol, don't know if that matches your needs

- http://en.wikipedia.org/wiki/XMODEM -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

mjbmikeb2

A file is just an array of bytes that has a name.
The contents of the file could be anything such as a serialised struct or something human readable.

Go Up