Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
When you write 8 bytes, do those 8 bytes arrive at the PC correctly, then you receive 8x 119 ? – Rocketmagnet Apr 21 '12 at 20:24
Yes, first the whole correct block, then the 8x119. – Yogu Apr 21 '12 at 20:25
1  
Do you have a logic analyser or an oscilloscope ? – Rocketmagnet Apr 21 '12 at 20:27
Ok, I'll look at the oscilloscope graph. – Yogu Apr 21 '12 at 20:30
2  
Just send one byte, preferably something with a distinctive pattern, like the letter K – Rocketmagnet Apr 21 '12 at 20:32
show 3 more comments

1 Answer

up vote 5 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.