PDA

View Full Version : can't get serin to work



kenpo
- 15th April 2007, 23:02
I feel like a noob, yes, i know every week someone asks about serial, I looked, still can't get it, I'm an idiot.

here's my code, I'm sure it's obvious, or I hope it's obvious what I'm doing wrong...
as per the example in the help file I'm using a 22k resitor, I have portB.2 going for serout, and portb.3 for serin on a 16f628a, internal 4mhz oscillator.

I'm trying to test via hyperterminal on xp, I get nothing output via the pic, and typing numbers does zilch.
I'd just liek to enter the number ONE or TWO and have the leds turn on as such.

should be basic....

define OSC 4

DataRec Var byte
testNum Var byte

testNum = 7

main:
SERIN2 PORTB.3,396,[dec1 DataRec]
SEROUT PORTB.2,N2400,[#testNum,10]

if DataRec > 1 then
HIGH porta.0
else
LOW porta.0

endif

'------------------------
if DataRec > 2 then

high porta.1

else
low porta.1
endif
pause 2000
goto main

any and all help WITHOUT hitting me is great

skimask
- 15th April 2007, 23:15
internal 4mhz oscillator.

That's probably the key right there. If you've got a 'scope, write a program to toggle and LED at a known rate, then 'scope it. If not, put a crystal or some sort of oscillator on it. That internal 4mhz might not be 4mhz. You probably have to tweak your OSCCAL value a bit to get it to work. Try 300 baud and see what happens. The slower you go, the more tolerant you can be of being off frequency.

mister_e
- 15th April 2007, 23:37
It's just too bad that there's no OSCCAL or OSCTUNE on that one :(

Serial com=crystal

OR manually set the USART SPBRG value and find the one that work :eek: not something i would use...


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
DEFINE HSER_SPBRG 25 ' 2400 Baud @ 4MHz, 0.17%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

Pause 500

Start:
FOR SPBRG=15 to 30
HSEROUT ["SPBRG=",#SPBRG]
PAUSE 250
NEXT
GOTO Start

you may try to use the same method but with SEROUT2.

Good luck!

PS: Use Microcode Studio serial communicator (F4), easier ....

skimask
- 15th April 2007, 23:46
It's just too bad that there's no OSCCAL or OSCTUNE on that one :(

Wow...do I look like an idiot or what... :D

mister_e
- 15th April 2007, 23:48
mmmmmmmmm, YES?

Don't worry, we already knew it... LMAO!

Archangel
- 15th April 2007, 23:50
any and all help WITHOUT hitting me is great

Boy, that's an incentive killer, where is the fun if we can't slap you around a little . . :) ?
Seriously, does your PIC do anything? Have you set the config fuses properly, as I do not see anything in your code to do that I'm guessing you are setting them manually when you program? How old is your proto board, have you used a VOM to check every connection? And as mister_e suggests, use a crystal or a resonator, much mo bedda for serial communications. Lastly remember to put END at the program's end, just for hoots.

Archangel
- 15th April 2007, 23:51
Wow...do I look like an idiot or what... :D

We can't see with that mask on . .

skimask
- 15th April 2007, 23:56
Boy, that's an incentive killer, where is the fun if we can't slap you around a little . . :) ?

I....can.....take.....it.....Just.....a.....little .....more.....
Red wire...blue wire...red wire....blue wire....which one?
Been wrong before, I'll be wrong again...most likely within the hour...

I didn't know the 16F628A didn't have an osccal or osctune. The 3 projects I've done so far with it luckily didn't need to be tweaked and worked at 300 baud on the internal oscillator. I'm sure I would've figured it out quick if I had tried 2400 baud or higher. And I somehow got a good bunch of 628A's because these projects have all been working well at all temp's, +100F down to -20F. Does the internal freq change with temp? I'm sure it does. Don't care as long as it keeps working!

But to be sure, a crystal is the way to go...

Archangel
- 15th April 2007, 23:59
Sorry Skimask, I just had ta pick on you a little . . Just because tomorrow's Moanday . . .

mister_e
- 16th April 2007, 00:00
I didn't know the 16F628A didn't have an osccal or osctune.

Bah, don't worry, you should have a cup of cofee first ;)
http://www.mister-e.org/Pics/cofee.jpg

LMAO!

Archangel
- 16th April 2007, 00:04
Bah, don't worry, you should have a cup of cofee first ;)
http://www.mister-e.org/Pics/cofee.jpg

LMAO!
He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He He , Touche'

skimask
- 16th April 2007, 00:23
SWEET!
And wait 'till you see the plates on my car!

kenpo
- 16th April 2007, 01:45
Thanks so much guys!!

I shall try both lowering the baud rate and using an external 4mhz crystal.

it makes sense that it would need a correct oscillator and not the internal one, I'm still just working my way up from simple blinking on and off.....

I have no idea what OSCCAL or OSCTUNE are, but that's what the helpfile and google are for.

THANKS!!!!!!

mister_e
- 16th April 2007, 02:16
OSCCAL and/or OSCTUNE are some register available on some PIC model which allow you to fine tune the internal OSC.

But bear in mind that ALL internal OSC will shift depending of temperature, humidity, gas price, wind direction leap year and so on. If your application is not timing critical, they are really useful, unless cross your fingers ;)