Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18F and USART

Status
Not open for further replies.
also make sure you have hyper terminal set to the same baud rate that you are using on the pic! i got caught out with that

LG
 
Ian Rogers, did you use Hyper Terminal to test it? I copied the code and it is still not working for me.

What speed are you setting Hyperterminal?... Should be 9600..
 
hi adrianvon,
I assume you have the correct level shifting hardware between the PIC and the PC's serial port.?
E
 
Could the problem be from the USB to RS232 convertor cable or the driver?

According to the tables in the datasheet I have to hand for the 18F4550 (page 249), for 9600 baud and Fosc=20Mhz, Sync=0, BRG16=0, BRGH=1, SPBRG=129 :)

Should BRGH be 0 or 1.

also make sure you have hyper terminal set to the same baud rate that you are using on the pic! i got caught out with that

What speed are you setting Hyperterminal?... Should be 9600..

The oscillator used is 20MHz and the baud rate is set to 9600. So that shouldn't be the problem.

I assume you have the correct level shifting hardware between the PIC and the PC's serial port.?

What is "level shifting hardware" please? Are you referring to the MAX232 IC ?? Sorry for asking such stupid questions but this is the first time trying to use UART.

I don't know what possible could be wrong. This morning I changed the PIC, changed the MAX232 with ST232 and re build the circuit, but still giving problems :(
 
hi,
The 'RS232 serial' levels from a PIC are 0/+5V and are of the opposite 'sense' of the signals the PC serial input expects, ie: +/-9v [ typical]
A Max232 IC is used between the PIC and the PC serial i/o
 
The 'RS232 serial' levels from a PIC are 0/+5V and are of the opposite 'sense' of the signals the PC serial input expects, ie: +/-9v [ typical]
A Max232 IC is used between the PIC and the PC serial i/o

Yes I did connect a MAX232 IC between the PIC and the laptop. Today I also changed it with an ST232 just to make sure the problem wasn't from this IC.

What RS232 converter do you have... Some work with 0.1uf caps and some do not!!! I think you have a hardware issue now..

I am using a Manhattan USB to serial, like the one in the link below:

http://www.manhattan-products.com/en-US/products/708-usb-to-serial-converter

How should I know what capaciyor values to use please?
 
I am using a Manhattan USB to serial, like the one in the link below:
The way I read the details of the link you posted, suggests that is already fully compatible as a 'RS232 serial' port, so it would expect standard RS232 signals, using a MAX 232 or equivalent.

Do you have a diagram to post of the PIC/MAX232 to PC wiring.?
 
I edited the attached diagram to show how the connections were made:
 

Attachments

  • Untitled.png
    Untitled.png
    161.7 KB · Views: 214
I am going to re-install the Hyper Terminal and it is asking for the following details. What shell I input please?
 

Attachments

  • Untitled.png
    Untitled.png
    32.3 KB · Views: 176
I edited the attached diagram to show how the connections were made:
hi,
If I am reading your diagram correctly, you have the 9 way 'D' connector wired the wrong way around!
Pin 5 is Ground, pins 2 and 3 are Tx and RX

It should be as this image.

db9_pin_name.png
 
hi,
If I am reading your diagram correctly, you have the 9 way 'D' connector wired the wrong way around!
Pin 5 is Ground, pins 2 and 3 are Tx and RX

It should be as this image.

db9_pin_name.png


Sorry I did a mistake while editing the diagram. I re-uploaded the diagram.

Regarding post #51, what shell I input please?
 
Regarding post #51, what shell I input please?

hi adrian,
I do not use hyper terminal, Ian is the best guy to ask.
Noted your corrected drawing..:)
E
 
Thanks for your help :)

I was reading on how to set hyper terminal and it looks like it only works with Windows XP. Is that true? because I am using Windows 7 (64bit). Can I use PuTTY instead?
 
You need to set Hyper terminal to use a direct COM connection... When you plug your USB/RS232 cable, you should get a enumerated port number... ie.. COM7 or something..

Yes!! You can use putty... But the same applies.... Once you configure the virtual com, you can use any terminal software...
 
Ian Rogers, the coding below is the one you gave me:

Code:
if(PIR1bits.RCIF == 1) // if the USART receive interrupt flag has been set
    {
        Temp_Instruction = RCREG;

        while(!TXSTAbits.TRMT);
            TXREG =Temp_Instruction; // echo received data back to sender
        }
    }

I was following the tutorial in the link below, where it states that PIR1.RCIF must be 1 to indicate that the data is received. Hence, it should be while PIR1.RCIF=0 so it keeps looping till data is received. The received data is then moved to a variable. From that variable it is then moved to TXREG (i.e. before the while(!TXSTAbits.TRMT); ).
He then used while(PIR1.TXIF == 0); to wait for data to be transmitted.

Although I did follow these steps (just in case) it is still not working.

Are the RCREG and TXREG registers cleared automatically when data is received/transmitted ?? or do I have to clear then manually ?

**broken link removed**
 
It might be that your cable is being installed as Com-5 or something, have you checked the device manager in windows? Make sure whatever port your cable has been allocated by windows, is the same as you have set in your terminal software :)
 
Are the RCREG and TXREG registers cleared automatically
Yes... The RCIF is cleared when the register is read.... The TXIF isn't being used... The reason I don't use it is the TXIF is set BEFORE the TXREG is empty... So I use the TRMT flag, this is cleared when the TXREG is empty, which is what we need..

I have tested the software as posted!!! If you are using C18 and used the OpenUSART(), WriteUSART() and ReadUSART() that they provide, you'll see that the software is okay..
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top