rs232 with hardware USART
hey all
I am trying to interface a PIC16F876A with the PC using the hardware USART, using a max232. I can send data from the pic to PC no problems at all, but i can't get communication from PC to the pic.
So i wrote the following which should echo back binary numbers:
*******
DEFINE OSC 20
' Set receive register to receiver enabled
DEFINE HSER_RCSTA 90h
' Set transmit register to transmitter enabled
DEFINE HSER_TXSTA 20h
' Set baud rate
DEFINE HSER_BAUD 9600
DEFINE HSER_ CLROERR 1
datain var byte
TRISC.6 = 1
TRISC.7 = 0
main:
HSERIN [datain]
Hserout [datain]
goto main
End
********************
Now what it does is just echo back '0's, and furthermore it echos 0's constantly, wether anything is sent from the PC or not.
What is going wrong here?
Thanks for your help
Re: rs232 with hardware USART
hi.
I just used the below code on a pic18f4550 with max232 chip, running a 20mhz crystal, and i am getting no communication at all in either direction
I have no clue what could be wrong. i tried anouther brand new ic, but to no avail.
I also read the pbp manual and couldn't find the answer there.
It would be very kewl to get this working.
Thanks.
Device = 18F4550
Xtal 20
DEFINE HSER_BAUD 9600
TRISB.6 = 0
TRISB.7 = 1
DEFINE HSER_ CLROERR 1
datain var Byte
main:
HSerIn [datain]
HSerOut [datain]
GoTo main
End
Re: rs232 with hardware USART
Shadowlight69
I'm also facing the same issue (and have been stuck for weeks now). The main issue (so far as I can understand) is that the processor timing is more complicated with this family of chips. The processor in your case is probably not running at 20MHz. The way to tell is to set a loop to flash an LED with a longish pause between flashes (say "pause 5000" for instance) and see how long it actually takes to flash. If it is not 5 seconds then your processor is not running at 20 MHz. My problem is trying to figure out from the fuses what the processor IS running at.
Can I ask you to start this as a new thread? We'll get help quicker that way.
Thanks,
DD.
Re: rs232 with hardware USART
shadowlight69 , Is that the actual program you are trying to run? If so "Xtal 20" is not a command but, "DEFINE OSC 20" is.
Dave Purola,
N8NTA
Re: rs232 with hardware USART
Just a reminder: Hardware serial port USART in PICs require a pull UP resistor to work as they send Data TRUE.
Re: rs232 with hardware USART
Joe S. , What? "Hardware serial port USART in PICs require a pull UP resistor to work " I have never heard of such a thing.. The USART port's on all of the MicroChip processors are capable of sinking as well as sourcing current... At least the last time I read them.... Better read your data sheet's Joe.
Dave Purola,
N8NTA
Re: rs232 with hardware USART
Data TRUE idles high, Data inverted idles Low - Hserin receives data TRUE. Hardware usart receive is an input. It neither sources or sinks current, although there may be chips with internal pullups. I know the chips I have used will not receive without the pullup.
Re: rs232 with hardware USART
If he has the PIC connected to a max232 hooked to a PC serial port the RX pin should already be held at logic 1 through the max232.
http://www.rentron.com/Files/bMAX232.gif
PIC to PIC using the hardware UART the tx pin on both will idle high so that works also without a pull-up. Even bit-banged serial should hold the tx pin at the idle logic state during idle periods.
But;
Device = 18F4550
Xtal 20
Indicates he's probably using the Proton compiler, so I would post the question there. It's most likely a configuration problem. Without config options in your code you're using whatever defaults they have in the include file, so it's probably not running at 20MHz.
Re: rs232 with hardware USART
Joe S. I thought you were talking about the output of the USART. The input requires a digital digital which should be supplied by the source of the other communicating device. If it is an open collector type output from the other device then, yes there should be some type of pullup device to produce the source current for driving the USART input. Sorry for the confusion on my part of the reply.
Re: rs232 with hardware USART
Quote:
Originally Posted by
Dave
Joe S. I thought you were talking about the output of the USART. The input requires a digital digital which should be supplied by the source of the other communicating device. If it is an open collector type output from the other device then, yes there should be some type of pullup device to produce the source current for driving the USART input. Sorry for the confusion on my part of the reply.
Hi Dave,
I seldom test devices together until ready to use them, So I Have to use the resistor or my serial lcd will not even boot, Bruce's synopsis explained it very well so as to include both camps, that the max232 serves that pull up function. And yes Dave I do make lots of mistakes and stand corrected without bruised ego. Bottom line is I think we are all trying to help. I brought up the idle status because I have tripped over that too many times. Maybe it is not the OPs problem, getting to the problem usually requires eliminating what it is not. To that end, We have posted.
To the OP:
Have you got it working yet?
Did we help?
will your PIC blink an LED ?
What configs are you using . . Default / roll your own ?