PDA

View Full Version : 16F628 Hardware USART problem



atomski
- 19th May 2004, 20:16
Hello everyone,

I have written this little piece of code for
testing the HW USART on 16F628 @ 4MHz,
because I've expirienced strange
behaviour on 2 of my 628's. I would
appreciate if someone could take a look
and tell me if something is wrong with my
code... Thanks!

PS When I power up the PIC the first
message doesn't come out in HyperTerm,
when I type on the keybd, HSERIN
doesn't seem to work and all I get is
"Type anything to test HW USART..."
every 2 secs.

--
Sincerest regards,

YZ7REA Vladimir M Skrbic
4N7ATV Repeater Administrator
YU7GHZ Radio Club President

NavMicroSystems
- 19th May 2004, 21:34
Are you using an RS232 driver loke MAX232 ?
the HW USART output is inverted as it is designed to work with an RS232 driver.
unfortunately you can't run the HW USART in true mode.

atomski
- 20th May 2004, 06:08
Yes, I am using the inverter hw. As I
mentioned in my previous post I do get
data comming out from the pic, however
nothing is received when I type on the
keyboard. And the first line comming out
from the pic is not sent/seen in HyperTerm
(i.e. I don't see the "greeting" msg)

PS I'm using 16F628/04

Vlad YZ7REA

Kypros
- 20th May 2004, 11:40
Hello Atomski,
try to use some delays
before your greeting, put the line PAUSE 500
and between the following line as indicated.
HSERIN 2000, No_Data, [Ser_data]
PAUSE 500
IF Ser_Data <> 0 THEN

Personally I had used the following and worked fine (for higher baud)

INCLUDE "modedefs.bas"

' ******* Definitions *******
' ------------------------------

DEFINE OSC 16 ' Define clock Oscillator Frequency at 16Mhz
DEFINE HSER_RCSTA 90H ' Enable Hardware USART receive
DEFINE HSER_TXSTA 24H ' Set Hardware USART parameters
DEFINE HSER_BAUD 9600 ' Set baud rate to 9600
define HSER_CLROERR 1
CMCON=%00000111 ' Make PortA digital

' ****** Initialise PORTs ******
'----------------------------------

TRISA = %11110000 ' Set PORTA status (Low byte=Output, for LEDs)
TRISB = %11100010 ' Set PORTB status
PORTA = %00000000 ' Initial state of PORT A
PORTB = %00000001 ' Initial state of PORT B


This might help ... I hope.

atomski
- 20th May 2004, 12:54
I'll give it a try. However, I did try putting
PAUSE 5000 in front of the first HSEROUT
command, but no dice. I could try with
PAUSE 500 between HSERIN and IF/THEN
statements, though. I would appreciate
if someone could run my code on their
hardware and tell me if it worked...
Thanks in advance.

Vlad YZ7REA

atomski
- 21st May 2004, 10:06
Hi I've tried what you suggested, but
nothing signifficant happened. I did add
a label called "Init" at the beginning of
my code right after DEFINE(s) and put the
PAUSE 500, HSEROUT [...], PAUSE 5000
statements there. And voila the welcome
message appeared in HyperTeminal. Why,
I'm not sure but that's what happened...
HSERIN is still not getting anything from
the comm port, though. Oh, another thing,
I added some extra lines in order to
troubleshoot the code and a wierd thing
happened. The led kept blinking at the
steady rate of 1s no matter if I typed or
not. Take a look at the code, please. If
someone has a suggestion on what else
I could try I'm all ears ;)

--
Sincerest regards,

YZ7REA Vladimir M Skrbic
4N7ATV Repeater Administrator
YU7GHZ Radio Club President

Kypros
- 21st May 2004, 11:30
Hello again atomski,

I think that the line

IF Ser_Data <> 0 THEN

is not necessary. Try to remark it and run the code again.

atomski
- 26th May 2004, 07:10
Hey everyone,

Problem solved! HSEROUT and HSERIN
now work flawlesly. The problem was
the rs232 <> TTL converter. I used a
factory made converter I got with one
of my digital diary's accessories. I used
it for years with various devices and it
worked every time like a charm. Now, I
assumed it had a max232 built in, but
after cracking the case open I found out
it wasn't the case. It was made with SMD
transistors and had no pull-up resistors,
rather it was an open collector type. PIC
MCU's abviously don't like this very much
when used with their hardware USART.
I made a max232 converter and now
everything works 100%. I'd like to thank
everyone for their help.

--
Sincerest regards,

YZ7REA Vladimir M Skrbic
4N7ATV Repeater Administrator
YU7GHZ Radio Club President