Maker Pro
Maker Pro

Trying to send RS232 with PIC sends incorrect data in TeraTerm

OK, you do have a scope on hand.




This is too busy to trouble shoot hardware with.

Try this:

while( TRUE)
{
output_low(PIN_B4);
delay_ms(1);
output_high(PIN_B4);
printf("A"); // replace this line with a serial_char_out('A');
delay_ms(1);

}

On your two channel scope, put one channel on PIN_B4 and the other
channel on the serial out pin.

Sync your scope on the raising edge of PIN-B4.

It should look something like:

B4 +---------------------------------------------------+
______| |____________

------+start+-01--+ 02 04 08 10 20 +-40--+ 80 +stop-.---
Sout |_____| |_____._____._____._____._____| |____|

Here is the scope output:
http://www.bitzphoto.com/ECE445/scope.png
PS: I haven't looked at the old messages, but it this hardware your own
design and construction ??

If you are referring to the USB to serial, no it is a sparkfun part:
http://www.sparkfun.com/commerce/product_info.php?products_id=198

The overall circuit for our intended project is our design; however
right now it has been stripped down to PIC-MAX-CONVERTER-PC blocks
until we find out our problem. It is right now just a breadboard
implementation.
 
R

Roger Hamlett

Jan 1, 1970
0
Well I'm a poor college student, so 20 dollars is expensive to me ;-)

The datasheet for the part indicates USB to rs232 functionality; and
the chip that resides on the breakout board is the cp2102 which lists
as its applications rs232 to USB on its datasheet.
Hint. Common mistake.
Same one in CCS.
They have their setup line called '#use RS232', but in fact it sets the
chip up to produce TTL asynch serial, which _requires_ the MAX232 (or
similar), to 'generate' RS232 signalling. In fact the same software setup
is used with different hardware, to provide RS485, or a number of other
similar standards.
The CP2102, is exactly the same. It _does not_ provide USB to RS232
functionality, it provides USB to asynch TTL serial, and also requires a
MAX232 or similar transceiver to generate 'RS232'. If you look at the data
sheet for the chip, it shows an 'external RS232 transceiver' _after_ the
chip, to generate RS232 signalling levels, and signal polarity.
Now you are talking about a 'breakout board', which suggests you are
accessing the CP2102 directly. If so, it's connections, want to go
_directly_ to the PIC, without the MAX232 transceiver. This would explain
the signals being inverted, since each MAX232 inverts the signals, as well
as shifting the voltage levels used, and you have one missing. You need to
either run with none (TTL signalling), or with _two_ - RS232 signalling
between these. Check the voltages being produced from the 'breakout box',
with the scope. I suspect you are going to find these are basically 5v
levels. If so, get rid of the MAX232. I just hope you have not damaged the
chip, since the MAX232, delivers +/-12v signalling, and if I am right, you
have been feeding this into a chip rated for 5v signalling...
Note that this _correctly_ says this is a _USB to serial_ adapter,_not_ a
USB to RS232 adapter. Get rid of the MAX232 on the PIC.
I am not sure what snalling polarity is. Our connections to the
Max232 have been checked by many people, and we have done so according
to the numerous schematics we have found. Also, we know that the Max
works at least for data sent out from the PC and shorted back 'round
through the pins.
The problem is that you don't need the MAX232, since you are not using
RS232 signalling anywhere...

Best Wishes
 
D

Donald

Jan 1, 1970
0

Wow, I even impressed my self !!!

Ok, the PIC board works as programmed.

So whats wrong with the CP2102 board.

I have these CP2102 boards here as well. Works fine for me.

By your scope trace I see that this is a 5 volt system.

The CP2102 is a 3 volt system. Are the CP2102s 5V tolerant ??

So, I imagine that you had the CP2102 board connected directly to the
Sin and Sout pins of the PIC.

Are these scpoe traces with the CP2102 and PIC connected together ??

Just guessing, check that loading of the CP2102 and PIC.

donald
 
Hint. Common mistake.
Same one in CCS.
They have their setup line called '#useRS232', but in fact it sets the
chip up to produce TTL asynch serial, which _requires_ the MAX232 (or
similar), to 'generate'RS232signalling. In fact the same software setup
is used with different hardware, to provide RS485, or a number of other
similar standards.
The CP2102, is exactly the same. It _does not_ provide USB toRS232
functionality, it provides USB to asynch TTL serial, and also requires a
MAX232 or similar transceiver to generate 'RS232'. If you look at the data
sheet for the chip, it shows an 'externalRS232transceiver' _after_ the
chip, to generateRS232signalling levels, and signal polarity.
Now you are talking about a 'breakout board', which suggests you are
accessing the CP2102 directly. If so, it's connections, want to go
_directly_ to thePIC, without the MAX232 transceiver. This would explain
the signals being inverted, since each MAX232 inverts the signals, as well
as shifting the voltage levels used, and you have one missing. You need to
either run with none (TTL signalling), or with _two_ -RS232signalling
between these. Check the voltages being produced from the 'breakout box',
with the scope. I suspect you are going to find these are basically 5v
levels. If so, get rid of the MAX232. I just hope you have not damaged the
chip, since the MAX232, delivers +/-12v signalling, and if I am right, you
have been feeding this into a chip rated for 5v signalling...


Note that this _correctly_ says this is a _USB to serial_ adapter,_not_ a
USB toRS232adapter. Get rid of the MAX232 on thePIC.


The problem is that you don't need the MAX232, since you are not usingRS232signalling anywhere...

Best Wishes

I will definitely check the voltages coming out of the Tx pin on the
USB to serial board. We actually ruined a PIC and we had assumed it
was because the Tx pin was delivering 12V, and thus added the Max; but
I guess it was some other mistake. I will let you know what I find.

The chips have worked fine when shorting the lines, as late as today,
so I hope that means that the incorrect delivery voltage has not hurt
it.

I guess the old saying, about what happens when you assume, is true.
I had assumed that since it was creating 9 pin serial it was creating
RS232 level signals. It will be interesting to see if removing the
middle man is the solution we were hoping for.
 
Wow, I even impressed my self !!!

Ok, thePICboard works as programmed.

So whats wrong with the CP2102 board.

I have these CP2102 boards here as well. Works fine for me.

By your scope trace I see that this is a 5 volt system.

The CP2102 is a 3 volt system. Are the CP2102s 5V tolerant ??

So, I imagine that you had the CP2102 board connected directly to the
Sin and Sout pins of thePIC.

Are these scpoe traces with the CP2102 andPICconnected together ??

Just guessing, check that loading of the CP2102 andPIC.

donald

As Roger pointed out above somewhere, we were running our signals
through a max 232, when apparently the cp2102 wants 5v signals.
Tomorrow we will try out removing the Max chip.
 
J

jasen

Jan 1, 1970
0
When I first read this thread, my immediate "conclusion" was that it
was probably something in the USB to Serial adapter. (I've never had
much luck with those...)

It would be interesting to try the circuit out on a dumb terminal,
like one of those old TeleVideo or Qume or Wyse terminals.

Or even a PC with a real serial port...
As for the characters, it starts off with (1) incorrect character, and
then the rest are a repeating sequence. (Again, incorrect) - but it
makes you wonder what the heck the first character is doing? The 6
for 12 argument personally doesn't sway me all that much.

I guess you could try slowing down the baud rate on each end, to say
300 Baud or so and see if that works. If the real cuplrit is sloppy
timing, the errors should be less critical at the lower baud rates.

Not true. more than 10% total timing error will break any baud rate
(assuming 8n1 line discipline)

Bye.
Jasen
 
R

Roger Hamlett

Jan 1, 1970
0
jasen said:
Or even a PC with a real serial port...


Not true. more than 10% total timing error will break any baud rate
(assuming 8n1 line discipline)
Less than this. Assuming the receiver tries to sample at the centre of the
bit time, and synchronises from the falling edge of the start bit, the
maximum total error allowed, is enough to cause 1/2 bit time error in 8
1/2 bit times (it is like the difference between the number of fence
posts, and fence panels - you sample in the middle of each bit time, so
for 8 bit data, there are just 7.5 bit times from the end of the start bit
to the last sampling location). 6.25%. Even using 7bit data, you still
only have a maximum of 7.14%. Less in both cases with parity enabled (5.5%
for 8 bits with parity). Remember also that the clocks on UART's on a
normal PC, are often slightly in error (systems with the 'spread spectrum'
feature enabled in the BIOS, often exhibit a percent or more timing
error...), and you can see why an absolute 'maximum' error of 4% in the
timings at the other end, is often used as a good guide.

Best Wishes
 
I forgot to respond on here, but this was indeed the issue. Removing
the Max removed the problem. Now on to more important coding!


Thanks much.
 
Top