Electronic – Microcontroller writes additional data on high-frequent writes

atmegacommunicationmicrocontrollerrs232

I'm using C-Control Pro 128 which contains a atmega processor. I've connected the rs232 interface with my PC and read the incoming data, having the following program executed on the controller:

void main(void) {
  Serial_Init(0, SR_8BIT | SR_1STOP | SR_EVEN_PAR, SR_BD9600);
  Serial_Write(0, 1);
  Serial_Write(0, 2);
}

I'd expected the controller to output the bytes 1 and 2. Instead, I receive the following:

1
2
119
119

If I write e.g. eight bytes instead of two, 119 is appended eight times to the actual data. If I write only one byte, only the one byte is transmitted, so all works correct.

The number 119 is independend from the value of the bytes and from the baud rate.

If I add a sleep instruction between the write commands (about 50ms), the problem does not occur.

Has anyone had a similar problem or any idea where the problem could be located?

Best Answer

The way to diagnose these sorts of problems is to cut them in half. Whose fault is this? The C-Control or the PC? If we can look at the actual data sent on the wire, we can tell whereabouts the fault lies.

Start by sending a simple, easily identifiable character, over and over again. I like to use the one used as an example on the Wikipedia's RS232 page because you can easily see what the waveform is supposed to look like.

K RS232

Now you'll need an oscilloscope. If you can't afford one, I highly recommend the Saleae Logic analyser. It's not that expensive, and it will save you literally days off your life. Look at the waveform on the bus, and check that it matches the waveform you expct. Check for any rogue characters transmitted afterwards.

Assuming everything looks OK, then the problem is somewhere in the PC. If the rogue 119 characters appear, then you know the problem is in the C-Control