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.

PIC to PC, PIC not recieving data

rk396

New Member
I am trying to make a PIC (18f4550) talk to a PC via hyperterminal. I can get data to the PC no problem, but when i try to receive data at the PIC from the PC. i get nothing. Here is my code.


#include <p18f4550.h>
#include <delays.h>
#include <stdlib.h>
#include <timers.h>
#include <usart.h>

#pragma config USBDIV = 2
#pragma config FOSC = HS //PLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF // PWRT enabled
#pragma config BOR = OFF // disabled
#pragma config BORV = 3
#pragma config VREGEN = ON
#pragma config WDT = OFF // WDT disabled
#pragma config MCLRE = OFF // disabled
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
#pragma config CCP2MX = OFF
#pragma config LVP = OFF // LVP disabled
#pragma config DEBUG = OFF // disabled

#define LEDPin LATBbits.LATB0
#define LEDTris TRISBbits.TRISB0

void main(void)
{
char ch;

TRISC = 0b11000000;
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_OFF &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
64 );

putrsUSART((const far rom char *)"NBLY");
while(1)
{
while(!DataRdyUSART());
ch = ReadUSART();
putcUSART(ch);
}
}

The idea is to get a char from the USART, the redisplay it. I've serached everywhere, and have tried most if not all the suggestions (clear the overrun flag, different clock speeds etc...) It almost seems like the real problem is my terminal program in that it's not sendind the characters.

any help some one can provide would be greatly appreciated.

thanks!
 
Last edited:
To make sure your PC (hyperterminal) is sending out characters you can do the following: With the communication cable to PIC disconnected short out pins 2 & 3 on the RS232 plug at the PC and type any character on the keyboard - you should see the same character appear on the hyperterminal screen.
 
thanks for the reply, i tried it, and all is well, the key i type is echoed back to the screen.... so it looks like i have a firmware problem.
 
Do you have an RS232 level shift chip between the PIC and PC?

Are you using C18 to compile?

Wilksey
 
Last edited:
yes im using the C18 compiler, and i have a Max232 chip between the PIC and PC. It's strange cause the PIC talks to the PC no problem... just not the other way.
 
Do you have it wired correctly? Have you done a loopback on the MAX232 chip to see if the data is being received on the PIC?

A PIC can talk to a PC, and a PC will usually understand it without a level shift, its when the PC transmits back to the PIC that the level shift is really needed. I would not however recommend not using the MAX232 to talk to the PC, just saying it will work!

Wilksey
 
Last edited:
I am assuming 20MHz @ 19200 Bps, this code works fine, just compiled with MPLABX and C18, and ran on Proteus to SIM and it works correctly.

So i'm thinking maybe a hardware issue?

Can you post a schematic on how you have wired your RS232 interface to the PIC including the MAX232?

Wilksey
 
You are correct on all your assumptions, here's a quick schematic of how it's hooked up. I ignored all the hookups to the PIC, and focused only on the max232 to pic.

thanks again for all your help and effort.
 
On your schematic, I assume the caps you are using are 1.0uF?

And your 9 way is wired wrong, 2 is RXD which is receive, which should go to T1OUT, yet it goes to R1IN.

Wilksey
 
good catch... i did my schematic backwards (probably cause i been at this too long). 2 -> 14, 3 -> 13. I've swapped em but to now evail..
 
Hmm, that is bizzare!

I don't think I have an 18F on a board with a 232 shifter any-more, I don't know if anybody else has to try the code out, I am sure the 18F4550 I built just has the USB connector on.

I know simulators are not usually *THAT* accurate, but they usually do a good job of the software, which is why I'm thinking hardware.

Have you tried changing the chips in case you have a faulty MAX232 or PIC?

Wilksey
 
I think Wilksey might have suggested it but in any case try to test the max232 by breaking the connection between the max232 and the pic, and then short the tx and rx lines on the max chip. (on the pic side) This way you now have a loop-back for hyperterminal via the max232. Another thing i use to have problems with is which is tx and which is rx pins on rs232. This you can find by disconnecting the serial cable and then measure on either side the polarity on pins 2 and 3 with respect to pin 5 (the ground). The pin with the negative volts (-5 to -10) is the transmit pin.
 
Ok, so i shorted 11 and 12 and still nothing..... so i went back to my ref. schematic. I didn't have pin 15 connected to ground. made the connection and viola! thanks for the help Wilskey, and Lourens. I learned alot trying to debug this one.
 

Latest threads

New Articles From Microcontroller Tips

Back
Top