PDA

View Full Version : MAX232 and DB9 connecter



Tomas
- 2nd March 2004, 00:34
Hi there,

I have connected pin 5 of the the DB9 to GND.
My crydtal speed is 4MHz.

But don't know which DEFINEs to include in the code and no idea what "TRUE" mode is and how to do it, sorry.
Where do i set this mode? I have told that 9600 will not work for a 4MHz crystal and so changed the mode to 4800, see the code below.
Have tested the Hyterterm, COM-Port, Serial Cable it is as explained no problem.
The problem might be with MAX232, one of the pins gives only 0V and the other one gives between the range of -1.5V up to -8.6V.

Pin 12 (R1 OUT) of the MAX232 which is connected to pin 26 (RX) of '877 gives 0V

Pin 11 (T1 IN) of MAX232 which is connected to pin 25 (TX) of '877 gives 2.80V and 4V

Pin 13 (R1 IN) of the MAX232 which is connected to pin 3 of DB9 gives almost 0V

Pin 14 (T1 OUT) of the MAX232 which is connected to pin 2 of DB9 gives between -1.5V up to -8.6V


What do you think where should i look for mistakes?

I just want to get the code below work to see my first "Hellow World"

' PicBasic Pro program to send "Hello World" on serial port

' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
'Define LOADER_USED 1

'Include "modedefs.bas" ' Mode definitions for Serout
TRISC = %00000010

loop: Serout2 PORTC.6,4800,["Hello",10,13] ' Display "Hello", next line
Pause 500 ' Wait .5 second

Serout2 PORTC.6,4800,["World",10,13,10,13] ' Display "World", skip a line
Pause 500 ' Wait .5 second

Goto loop ' Do it forever
End


Best Regards,
Tom.

NavMicroSystems
- 2nd March 2004, 01:38
Your MAX232 is probably defective.

Try the following with PortC.6 of the PIC directly connected to Pin 2 of the PCs DB9 (and GND connected to Pin 5 of DB9)


' 4800 Baud 8N1

DEFINE OSC 4

loop:
Serout2 PORTC.6,$40BC,["Hello",10,13]
Pause 500
Serout2 PORTC.6,$40BC,["World",10,13,10,13]
Pause 500
Goto loop
End

The Mode is marked RED


You might also want to try a different Pin (i.e. RB4) and try to add a 4k7 pullup.


There is one thing I have found a while ago:

If you have tried the HSEROUT statement your PIC might behave strange when using SEROUT or SEROUT2.

If there is a HSEROUT statement somewhere in the Code (even at a position normal program execution never gets to) causes that the PICs internal USART remains connected to the Port Pin.

To solve this erase your PIC and start coding at a new (blank) project.

Tomas
- 2nd March 2004, 15:25
Hi, there thanks for the reply.
I have tried it as explained, connecting PORTC.6 direct to DB9 pin 2. And still could not the the message.
I'm not sure if it is the MAX232 chip which is cousing the problem, MAX232 behavs as follows:

Wheb TX (RC6) from '877 is connected to pin 11(T1 IN), pin 14(T1 OUT) gives -10.2V, this pin is connected to pin2 of the DB9 connecter. (Am i sending a negative voltage level).

But pin 7(T2 OUT) gives 9.6V and this pin is left float.
This connection is supposed to work, it doesn't look like it at the moment.

Where can i find a working code just for testing purpose? A code which sends and receives data.

Cheers,
Tom.

NavMicroSystems
- 2nd March 2004, 16:08
Tom,

this is a working piece of code for direct connection (no MAX232)

loop:
Serout2 PORTC.6,$40BC,["Hello",10,13]
Pause 500
Serout2 PORTC.6,$40BC,["World",10,13,10,13]
Pause 500
Goto loop
End

this is a working piece of code for use with MAX232

loop:
Serout2 PORTC.6,$BC,["Hello",10,13]
Pause 500
Serout2 PORTC.6,$BC,["World",10,13,10,13]
Pause 500
Goto loop
End

both the versions have been tested on a 16F876

Are your settings in hyperterm correct?


There is one more thing:

If you are using your Loader cable for connection with Hyperterm it wont work.
Hyperterm sets Pin4 at the COM Port to +12V which causes a LOW-Level at the MCUs MCLR Pin.
Your MCU will not start as long as Hyperterm is connected

Tomas
- 2nd March 2004, 16:22
Hi again,
What cabel can i use? The cable i have is connected to my project board and COM1
Cheers,
Tom

NavMicroSystems
- 2nd March 2004, 16:34
For a quick test just take two wires,

one from PortC.6 to Pin 2 on the DB9
one from GND to Pin5 of the DB9

I'm sorry Tom,
but we are discussing all the same things over and over.

Tomas
- 2nd March 2004, 18:49
Hi,
Well i was not talking about the connection between the '877 and DB9.
I was told that the cable i'm using (to connect my project board and the computer) at the moment might not work so how do i connect the DB9 from my board with the serial port (COM 1) in my computer?
Can i just use to wires, pin 2 and 3 from DB9 on my project board to connect to the pins 2 and 3 of the computers serial port. This seems a bit unusall to me.

Cheers,
Tom

NavMicroSystems
- 2nd March 2004, 19:11
It is impossible to answer your questions without having had a look at the schematic of your "project-board"

brenda
- 5th March 2004, 18:28
hi,

pin 2 of PC serial com (DB9) is RX.... so you have to connect here the TX of your board

pin3 of PC serial com(DB9) is TX... so you have to connect here the RX of your board

pin 5 of PC serial com(DB9) is GND... so yuo have to connect here the GND of your board.

hope this help
brenda

charudatt
- 22nd March 2006, 10:59
Just wanted to raise another querry on this old thread , without starting a new one.

I am interested in interfacing the above mentioned Inclinometer to the PIC and displaying the relevant information on the LCD.

My target MCU is 16F877A @ 20Mhz.

One of the problems I am facing is how to interface the PIC at 115,200 or 56,700 baud to read the information from this sensor.

Any help would be appreciated.

regards

sougata
- 25th March 2006, 16:02
Hi Charu,

Please post your crystal frequency. The baud rate generator works for certain rates at certain crystal frequecy. Otherwise you have to do away with the hardware USART and have a asm based routine. It is also possible with PBP. But then you are left with little processing or housekeeping