# Serial Communication Problem. Need some help please.

Status
Not open for further replies.

#### Beefer3

##### New Member
Hey everyone

I am having some trouble with RS232 communication with a 16F84A. Can someone shed some light on this?

Here is my code:

DEVICE 16F84A
INCLUDE "MODEDEFS.BAS"

PORTA = %00011

SWITCH:
PORTA.2 = 0
IF PORTA.2 = 1 THEN
SEROUT PORTA.3 , 16780 , [ "HELLO WORLD" , 13 ]
ELSE
GOTO SWITCH
ENDIF

END

and this is what I get in return on the terminal program

«￾￾…ýQa[gwå

I am using this schematic. Hopefully this is right.

Can anyone help?

#### Attachments

• 9.4 KB Views: 407

#### evandude

##### New Member
this probably won't fix your problem, as the fact that you're getting SOMETHING in hyperterminal means that it's mostly working...
but to keep things simple, the only pins you actually need on the serial cable are the TX, RX, and ground for serial communication, as long as you don't use any hardware handshaking... I usually leave the rest unconnected.

getting the wrong text in hyperterminal is often a sign that the baud rate isn't matching up with that of the PC. perhaps you could try the old standby, 9600 8-N-1. make sure both the PC and PIC are set to the same baud rate.

#### Beefer3

##### New Member
By the way I do have the pin connections right. The schematic shows ra2 being used. I am using ra3.

#### ivancho

##### New Member
What inputs are you getting?
THere are three main problems on your program. :wink:

:arrow: First you set PORTA = %00011 , that meands RA0-RA1 are inputs and RA2-RA4 are outputs. When you do:
Code:
PORTA.2 = 0
IF PORTA.2 = 1 THEN
You are writing a 0V to the RA2 pin. That is correct can be done since you defined it as an output. But then you go on and try to read the output you just wrote to. You can write outputs but you can't read them per say.....logically you read inputs and manipulate the outputs.

So no way to tell what the PortA.2 will give you. That is why you aer lucky you are actually getting something.

:arrow: Second little mistake..... You are mixing two commands together. SEROUT2 and SEROUT. The form for SEROUT2 is:

SEROUT2 DataPin{\FlowPin},Mode,{Pace,} {Timeout,Label,}[Item...]
Where the mode is calculated and a 16780 gives you a 2400 Inverted baud rate.
The SEROUT comand's form is like:

SEROUT Pin,Mode,[Item{,Item...}]
where the Mode is a Fix number you choose from 0-15. For a 2400 inverted baudrate you choose the 4, or since you are including the modedefs.bas then you can choose the N2400.

What you are doing is mixing them up.... perhaps you meant to use SERIN2

:arrow: The last Little problem is the Inverted part. SInce you are using the MAX232, this chip shifts the voltages for you. Therefore any serial data you want to send must go out in TRUE mode. Otherwise the data you send will be all wierd like what you are getting. If you connect the PIC straight (no max232) from the pin to the port (thru a 2.2K resistor) then you must send the data inverted, because according to the RS232 protocol a 1 is between -12V and -5V and a 0 is between +5 and +12V.

Let you fix the problem and let me know how it goes.

I hope it helps you some.

Ivancho

#### Beefer3

##### New Member
Ivancho
thanks. i did make the change on the port. i now have it set up as 00111, but i still get the same jibberish. i will try you other suggestions. thanks again.

#### Beefer3

##### New Member
Ivancho
I change the value of 16780 to 396 and everything works!!!! It was the inversion problem.

Now I am off to tackle reading from the serial port!!!!!

I might be back.

Thanks

Status
Not open for further replies.