• Welcome to Andy's Workshop Forums. Please login or sign up.
 
May 23, 2024, 05:59:02 am

News:

SMF - Just Installed!


C++ styled Serial Communication

Started by Craftplorer, April 04, 2016, 07:50:30 am

Previous topic - Next topic

Craftplorer

Hi,
i was wondering if someone could help me with my serial communication of my microcontroller project. I dont really need a high throughput(~18 Bytes a second) or low latency so i was thinking of an circular buffer(FIFO) to keep the messages without interrupting the main program for a long time. But i have problems with defining the start/stop byte. I have values which reach from 0-255 so a start bit like 0xFF dosent work.
The simplest solution would be to use 9 bits instead of 8 and just use the MSB for start and stop.
I was also thinking of bit stuffing but no so sure about it.
Any ideas or questions?

I have a seconds question which would be why the reflow project use  eeprom_write_ instead of  eeprom_update_?https://github.com/andysworkshop/awreflow2/blob/master/atmega8l/Eeprom.h

Andy Brown

In general if you have a byte-oriented stream protocol and you want to encode metadata within it then you select a byte to use as a control byte and use the next byte as an instruction as to what to do. For example, you might select 0xFF as the control byte and then use the next byte for example as 0=start, 1=stop, 2=0xFF. Then if a receiver joins the stream at any point and the first byte they read is 0, 1 or 2 they discard it (because it's ambiguous) and start reading at the next byte.

I'm unsure if that's what you were asking for. You also mentioned circular buffers but I can't relate start/stop codes to that because circular buffers normally use offsets or pointers as the read/write position indicators.

Quote
I have a seconds question which would be why the reflow project use  eeprom_write_ instead of  eeprom_update_?https://github.com/andysworkshop/awreflow2/blob/master/atmega8l/Eeprom.h


No reason. Both calls do the job. If you anticipate getting near the 100000 write cycle level and you might be writing the same data as the cell already contains then update is the better choice.
It's worse than that, it's physics Jim!