Continue to Site

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.

uart driver for pic16f877a

Status
Not open for further replies.
An RS-232 cable is just wires with a plug at each end, it doesn't convert the voltages at all. There are some devices with a built in TTL level converter built in to one of the plugs but most do not have this.

The PC expects RS-232 levels at it's input pins and produces RS-232 levels at it's output pins. RS-232 is a higher voltage system than the PIC uses, typically swinging from +12V to -12V to represent low and high bits.

The PIC produces levels of 0V to 5V at it's output and expects levels of 0V to +5V at it's input, logic low is 0V and logic high is 5V.

So the voltages are translated by the MAX232 so 0V in gives +12V out and 5V in gives -12V out and the same in reverse. Without translating the levels and reversing the polarity the PIC will not communicate with the PC.

Brian.
 

Hi,

Thanx for the information. I checked the board now and found that MAX-232 IC is integrated with the pic board. So I need to install hyperterminal and check. I need to know how exactlty the hyperterminal works. Whatever the user enters through the hyperterminal is reflected back in pic16f877a and vice versa right?Also which register takes the data from the hyperterminal?Please clarify the operation.


Thankyou
 

You must understand that Hyperterminal is just a program (and not a particularly good one!) to send data between the PC to the serial port, it doesn't do anything clever.

The characters you type in the Hyperterminal window are sent to the PC serial port where it leaves in RS-232 standard, the MAX232 on your board converts it back to 5V levels and connects it to the PIC RX pin. So what you type in Hyperterminal should appear in the PICs RCREG register.

When you write something to the PIC TXREG register, it is sent out through the TX pin to the MAX232 which converts it to RS-232 standard, This is sent to the PC where it is displayed in the Hypertermial window.

The send and receive in Hytperterminal work independently of each other so if you want to 'reflect' the data back, you wait in the PIC for data in the RCREG then copy it to the TXREG. This makes characters leave Hyperterminal, arrive at the PIC and get returned so they show in Hyperterminal's window. Be careful because if you have "echo typed characters locally" enabled in Hyperterminal it will show the characters you type WITHOUT sending them through the serial port at all which might be confusing because it makes it look as though the PIC is working even if you disconnect it! I suggest you turn "flow control' off (none) to avoid handshaking problems.

Brian.
 

    V

    Points: 2
    Helpful Answer Positive Rating
Hi,

Thanks for the information.Actually Windows 7 does'nt have this hyperterminal application so I downloaded the exe files. But the installation is not happening properly. It asks for host IP and when I give the IP address it shows "cant connect to the IP on port 23". I am not aware of the configuration. If you have the setup for hyperterminal please share it and also the steps to run the application.


Thankyou
 

Hyperterminal is in my opinion a poor program, it was designed as a very basic way of communicating with dial-up BBS back in the early 1990s and has little support for other communication systems. I suggest you try this link instead:
http://realterm.sourceforge.net/

Realterm is a much more versatile program and it will display hex values as well as ASCII which makes it far more useful for debugging programs.

Brian.
 

Hi,

Ya I ll download it and try. Please send the hyperterminal setup also if you have. Will get back to you.


Thankyou
 

Hyperterminal is on my PC but I would never use it. A program that asks my telephone area code before letting me talk down a wire to a protoboard has no place amongst my software tools!

In theory all you have to do is set the baud rate to match the PIC and select the correct port if you have more than one.

Brian.
 

Hi,

I have downloaded the realterm setup. But I don't know how to use it. Please help me. I have attached the snapshot of the window. There are a lot of parameters. Please let me know which of those should be set. And also is it required to add the uart codes for the communication to happen? If so where should I include the files. What input has to be given in the black window which is shown?Please let me know about the hardware connections as well.We need to just connect the RS-232 cable to pic microcontroller right? Please help.

PFA

Thankyou
 

Those settings are correct, just change the baud rate to 9600 so it uses the same speed as your PIC and if necessary, change the port number to that of your serial interface. The black box is where you type characters in to be sent to the PIC and where the reply from the PIC is shown.

Brian.
 

Hi,

Ya I have set the baud rate to the same speed used by PIC.But there are a lot of settings which I am not understanding. Right corner of the window there is a parameter called 'status' in which TXD(3),RXD(2) and many other symbols are there.Does that imply that we need to make some hardware connections?There are a number of parameters like display,port,pin,capture,send.Each thing has many settings in it which I am not aware of. Is there any readme manual for the settings?If so please upload it so that I can follow all the settings to be done.The only hardware connection is the RS-232 connection right?

Thankyou
 

Click on '?' for help!

The status window is just for information, it shows the logic state of the pins on the serial socket. Don't worry about them. As long as you have "Hardware flow control/ none" checked it will ignore everything except the data in and out pins. A standard connection to PIC is 8 data bits, no parity which is the default setting anyway so all you need to set is the baud rate and the number of the port on your PC. Anything arriving from the PIC will appear in the black window and anything you type there will be sent to the PIC.

At least when you see this you will understand how little control Hyperterminal gives you!

Brian.
 

Hi,

Ya I got to know that the realterm has a lot of good control when compared to hyperterminal as I went through its features.But I have certain doubts regarding it. I need to upload the uart communication files in this window for the communication to happen is it?What exactly the send and capture options in the window do?Because I came across an option called 'dump files to port' and a 'file' option to upload files. I wanted to know what exactly it does.And the communication port in my PC is COM1. Can I give the same in the port column?Other than RS-232 no other hardware connection is required right?Please clarify


Thankyou
 

"Dump files to port" lets you send the entire contents of a file to the serial port. First select the file by clicking on the '...' box, then click on "send file" to start the transmission.

"Send Numbers" lets you enter the number code for a character, for example 41 for 'A'. It's useful for data that you can't enter directly by pressing a key on your keyboard.
"Send ASCII" does the same but uses the characters you type in.
In both of these, put the numbers (separated by spaces) or characters in the box before clicking the appropriate 'send' button.

"Capture" just records all the activity to a file, enter the file name and click on "Start overwrite" to create or overwrite an existing capture file erasing it's previous contents, or, "Start Append" to add new data to the end of an existing file.

"File" just records all your activity to a log so you can see what steps you took when something happened.

No hardware is needed, all the program does is interface between you and the serial port.

Brian.
 

Hi,

I tried to send the file by giving the path of the file in the 'dump files to port' tab but it is showing an error message telling 'error-32'.What does that imply?I am not able to type anything in the black window also. Please let me know the reason for this.I have just connected the PIC kit debugger to the USB port of my PC. And I am not getting any response in the watch window of MPLAB software which I am using for PIC16F microcontroller.ie the RCREG is not getting updated.Please help

Thankyou
 

Error 32 usually means a sharing violation, is the file you are trying to send already open in another application?

I suggest removing the PC port from the equation and try using the PicKit UART tool to see if the 16F877A is actually communicating or not.

Brian.
 

Hi,

My uart application comprises of .h and .c files. But in realterm s/w it asks to upload only one file at a time right?What am I supposed to do in this context?Ok I will try to send it without the PC port.

Thankyou
 

Hi all,

I am using the hyperterminal to check for the basic communication with PIC. I have written the code for transmission. I am transmitting the string "hello" to TXREG. I can see this data reflecting in the TXREG buffer in the watch window. But I am not able to get this data on to my hyperterminal screen. I checked the working of rs232 cable by shorting the TX RX pins of the DB9 connectors and found that whatever I am typing gets echoed on the hyperterminal screen. But I am unable to establish the communication with PIC though I get data in TXREG buffer. Please help!!!!!!


Thankyou
 

OK, lets go back a step.

You are verified the PC was talking and listening by shorting the pins on the DB9 connector, that's good. First, confirm that what you type is NOT echoed when you remove the short becuse there is a setting in Hyperterminal that copies the keyboard straight to the screen and I want to check you really are seeing data going down the cable and back again, not just locally echoed inside the PC.

After that, repeat your test but this time, remove the PIC and link together the connection that went to the TX and RX pins (pins 25 and 26 if you are using the DIP package). What I want to test is whether the data path right up to the PIC is working properly so we can eliminate an electrical fault. Again, without pins shorted you should not see anything you type appear on the screen but when they are shorted, everythng you type shuld appear. The PIC must be removed to do this test, you are only testing the circuits connected to the TX and RX pins at this stage.

Let me know what happens.

Brian.
 

Hi,

Let me tell you clearly, the problem I am facing. Ya I shorted together the TX(RC6),RX(RC7) pins together and got the data reflecting in the RCREG buffer successfully. Later I also shorted the TX connected to R1OUT(pin 12) of MAX-232 IC and RX pin connected to T1IN(pin 11) of the IC and got the data being transmitted from TXREG to RCREG successfully. But when I short the output pins of the MAX-232 IC, T10UT(pin 14) and R1IN(pin 13) of the MAX-232 IC, I am not getting the data on receive buffer register(RCREG). What is the problem? Does it imply that the MAX-232 IC is not functioning properly? Please clarify!!

Thankyou
 

Provided the PC is not connected at the same time, you should get data 'looped back' if you link pins 13 and 14 of the MAX232. If it isn't working, check you have about -10V (must be negative with respect to ground) on pin 6. This will verify if the charge pump is running which is essential to RS232 operation.

In summary:
1. linking the PIC TX and RX pins with the MAX232 disconnected should give you loop back from TXREG to RCREG.
2. linking MAX232 pins 13 and 14 with the PC disconnected should give you loop back from TXREG to RCREG.
3. linking MAX232 pins 11 and 12 with the PIC disconnected should give you loop back from keyboard to screen in Hyperterminal.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top