Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 12th November 2003, 01:15 PM   (permalink)
Default Serial Communication Problem. Need some help please.

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?
Attached Images
File Type: gif 44.gif (9.4 KB, 274 views)
__________________
I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

- Stephen King
Beefer3 is offline  
Old 12th November 2003, 01:30 PM   (permalink)
Default

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.
evandude is offline  
Old 12th November 2003, 01:38 PM   (permalink)
Default

By the way I do have the pin connections right. The schematic shows ra2 being used. I am using ra3.
__________________
I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

- Stephen King
Beefer3 is offline  
Old 12th November 2003, 02:49 PM   (permalink)
Default

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
ivancho is offline  
Old 12th November 2003, 03:19 PM   (permalink)
Default

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.
__________________
I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

- Stephen King
Beefer3 is offline  
Old 12th November 2003, 05:14 PM   (permalink)
Default

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
__________________
I like to tell people I have the heart of a young boy. Then I say it\'s in a jar on my desk.

- Stephen King
Beefer3 is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 04:24 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker