Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

USB-RS 232 and hyperterminal

Status
Not open for further replies.

sana_akhtar

Member level 2
Joined
Apr 21, 2012
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
Hey

On the last part of project ... sigh

Using PIC16F877A, I used UART with PC and tried my code on proteus 8. Using virtual terminal on
proteus its working fine. Now when I linked it with PC through USB-Rs 232, installed successfully prolific driver and usb has been detected, it isnt giving anything on hyperTerminal. Even when HyperTerminal is giving the option of the port (COM4) on which USB has been connected. What is the possible problem here?

I tried FTDI driver, but it didnt work with this USB.
 

PA3040

Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,929
Did you check loop back by connecting pin 3 and 4 pf DB9

Try with putty terminal software
 

hemnath

Advanced Member level 3
Joined
Jun 24, 2012
Messages
700
Helped
61
Reputation
120
Reaction score
57
Trophy points
1,308
Location
Chennai
Activity points
6,566
In Device Manager, check the port number when usb is connected.

In hyperterminal, change the port number to as defined in device manager.

DB9 is a serial port connector which commonly used for serial port.

Best wishes :)
 

sana_akhtar

Member level 2
Joined
Apr 21, 2012
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
I did this before.. still not working.
Does hyper terminal support USB-RS 232 communication ?

- - - Updated - - -

I tried two other software, teraterm and putty. Both says that "unable to open port connection". So it means there is some connection problem. Where do I need to do settings, in code or in serial communication(PC) ?
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,123
Helped
14,379
Reputation
29,022
Reaction score
13,132
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,176
I tried two other software, teraterm and putty. Both says that "unable to open port connection". So it means there is some connection problem. Where do I need to do settings, in code or in serial communication(PC) ?
If you can't open virtual port COM4 in teraterm or putty, it won't open in Hyperterminal either. So something seems to be confused with your tests.

To check the virtual COM port function in your PC sytematically, you can:
- Unplug the USB adapter
- Open device manager and check that COM4 isn't assigned to a device
- Plug the USB adapter, the device manager should re-enumerate the devices and show the USB adapter as virtual COM port device
- Now you can connect to the virtual COM port, but onyl with one application at a time.
 

sana_akhtar

Member level 2
Joined
Apr 21, 2012
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
thanks. It has opened but showing nothing :/
WHYYYY????

- - - Updated - - -

here is the UART code I am using

Code:
/*  File:     UART.c
    Purpose:  To provide UART functionality for PIC uC
*/

#include "Includes.h"

void InitUART(void)
{
	TRISC6 = 1;   					// TX Pin
	TRISC7 = 1;   					// RX Pin
	
	SPBRG = ((_XTAL_FREQ/16)/BAUDRATE) - 1;
	BRGH  = 1;                   	// Fast baudrate
	SYNC  = 0;						// Asynchronous
	SPEN  = 1;						// Enable serial port pins
	CREN  = 1;						// Enable reception
	SREN  = 0;						// No effect
	TXIE  = 0;						// Disable tx interrupts
	RCIE  = 1;						// Enable rx interrupts
	TX9   = 0;						// 8-bit transmission
	RX9   = 0;						// 8-bit reception
	TXEN  = 0;						// Reset transmitter
	TXEN  = 1;						// Enable the transmitter
}


void SendByteSerially(unsigned char Byte)  // Writes a character to the serial port
{
	while(!TXIF);  // wait for previous transmission to finish
	TXREG = Byte;
}

unsigned char ReceiveByteSerially(void)   // Reads a character from the serial port
{
	if(OERR) // If over run error, then reset the receiver
	{
		CREN = 0;
		CREN = 1;
	}
	
	while(!RCIF);  // Wait for transmission to receive
	
	return RCREG;
}

void SendStringSerially(const unsigned char* st)
{
	int i;
	
	for (i=0; st[i]!='\0';i++)
	{
		while(!TXIF);
		SendByteSerially(st[i]);
	}
}



Code:
#ifndef __UART_H
#define __UART_H

#ifndef _XTAL_FREQ
	#define _XTAL_FREQ   4000000  // Hz
#endif

// Comm Setup
#define BAUDRATE 9600  //bps
// 8 bit data mode with one stop bit
// No flow control, no parity bit

//Function Prototypes
void InitUART(void);
void SendByteSerially(unsigned char);
unsigned char ReceiveByteSerially(void);
void SendStringSerially(const unsigned char*);

#endif
 

sana_akhtar

Member level 2
Joined
Apr 21, 2012
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
here is all the code


Code:
#include <htc.h>
#include "uart.h"
#include "Includes.h"

#ifndef _XTAL_FREQ
 #define _XTAL_FREQ 4000000
#endif

void main(void)
{	
       
	InitUART();   

	while(1)
	{
		SendStringSerially("hello world");								
	}
}




Code:
#ifndef __INCLUDES_H
#define __INCLUDES_H

// Define CPU Frequency
// This must be defined, if __delay_ms() or 
// __delay_us() functions are used in the code
#define _XTAL_FREQ   4000000  

#include <htc.h> 
#include "UART.h"
#include "ISR.h"


#endif


Code:
#ifndef __ISR_H
#define __ISR_H

void interrupt ISR(void);


#endif
 

sana_akhtar

Member level 2
Joined
Apr 21, 2012
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
didnt work :(

- - - Updated - - -

can this be because of time delay between controller and port ????

- - - Updated - - -

it just gave output once. I have written the output in while loop so it should have displayed it continuously. but it isnt.
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,454
Helped
295
Reputation
590
Reaction score
278
Trophy points
1,363
Location
France 01800
Activity points
10,297
hello

try before the basis , send charactere..
Code:
.....
while(1)
{
 SendByteSerially('H');
 SendByteSerially('E');  
 SendByteSerially('L');  
 SendByteSerially('L');  
 SendByteSerially('O');
 SendByteSerially(13);  // CR
 SendByteSerially(10);  // LF

 Delay_ms(500);
 }
}



your code is working, tested on a terminal (19200 bds) via bluetooth link, but too much speedy
to see result on screen, add a delay and CR LF
Code:
void main(void)
{    
       
    InitUART();   

    while(1)
    {
        SendStringSerially("hello world");
 SendByteSerially(13);  // CR
 SendByteSerially(10);  // LF
 Delay_ms(500);
 }
}
 
Last edited:

El_Paco

Member level 1
Joined
Mar 7, 2002
Messages
38
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
363
Hi - i read your topic.
yes it can be because of time delay - usb fifo size...

First i would check if your connection is working from pc side.

Did you check loop back by connecting pin 2 and 3 at the profilic db9 connector.



If connection is stable to this point you should see the sign you typed in receive window.

The next point is to check if you have connected the PIC correct to the level converter and also the level converter correct to the RS232 Port ....

RX --> TX / TX --> RX

please post a schematic to see if the real wiring is correct.

if all this did not work --> throw away your profilic adapter and use a ftdi - do fine setting of fifo delay time in apapter / advanced setting ;-)
this joke has a real background - i had many trouble with differen hardware serial datalogger in conjunction with profilic...
the FTDI based adapter can be tuned really fine for your requrements, which is not possible with the profilic, i think.

some notes to your main.

Use a delay between every "Hello World" for test of 100ms.
Only for profilic topic to test

I think in your case it is hardware ( connection error) more than a profilic driver error.

If you have a scope then test:

the levels of the signals your level converter
Test if signals come in/out
Measure period time of the uart bit - to see if your baudrate setting is correct.
Check if this is the same as in your terminalprogram.





So i hope i can help you..

Best regards,
Paco
 

sana_akhtar

Member level 2
Joined
Apr 21, 2012
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
it works sometimes and sometimes not. Also when it works, it stop suddenly at different times.
:(

- - - Updated - - -

I think there is some timing synchronization problem. When i disconnect hyper terminal and connect it after sometimes, it shows receive data. But when then stop at random times. If I disconnect for long time, it will show receive data for more time.
Now how to solve this? I inserted 100ms delay but of no use.
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
49,123
Helped
14,379
Reputation
29,022
Reaction score
13,132
Trophy points
1,393
Location
Bochum, Germany
Activity points
283,176
Pull down UART lines of PIC using 10ks.
Which lines? logic-level UART is idling high, so it should be pulled up (if necesary). RS232 is idle low, but don't need pull-down resistors.
 

sana_akhtar

Member level 2
Joined
Apr 21, 2012
Messages
47
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,606
didnt worked ... it must be having some serious problem? some configuration error?Also I am using timer0 with external input. When timer0 get an input, UART stops receiving. Is there any link between this?
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,454
Helped
295
Reputation
590
Reaction score
278
Trophy points
1,363
Location
France 01800
Activity points
10,297
hello,

looka this example of using a USB-RS232 cable converter TREND TU-S9

RS232 level Output is on the DB9 (9 pins!) connector
and i a m using an adaptater to get pin 2,3,5 to connect to my UART PIC Tx,RX
and GND !!

i installed the corresponding Driver ( software part deliver with this product as a litle CD)


I can test the termina by shorting pin 2 and 3 ob DB9 connector
All i type on keyboard appears on display..( as echo)
it is the first step to do..

you must see, on your PC
peripheriques systemes
Port COM & LPT
Prolific USB-to-Serial com ( COMXX)
Periph_syst.jpg
XX is the port number linked to USB -RS232

so, on your terminal, (i used Terminal VBRAY).
you must use COMxx ( COM5 in my case)
Terminal_Vbray_COM5.jpg

if it don't works .. go back

Solve this probleme before testing with your PIC..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top