PDA

View Full Version : HSERIN / SERIN Problem with 16f690



rborsuk
- 24th October 2008, 16:17
I've crawled the forum and have read several post about the 16f690 and serial in, I was wondering if someone could shed a little light on this topic for me. I have a simple setup with a 16f690 and a Max 232. I have tried both the internal oscillator and have just switched to a 3.579 MHZ crystal and still have not had success using HSERIN or SERIN to recieve in a character from Hyperterminal (2400 - 8N1). I can successfully send out characters using both HSEROUT and SEROUT. Below is my code, can someone tell me if I'm missing something? The code will output a character and then stop.
Thank you for any insight.

Rob


Include "modedefs.bas"

DEFINE OSC 3

define HSER_RCSTA 90h
define HSER_TXSTA 20h
DEFINE HSER_BAUD 2400
DEFINE HSER_ODD 1

'DEFINE HSER_SPBRG 25

'define CHAR_PACING 1000

OSCCON= $08


'this is the layout for portb.5 - RB5/AN11/RX/DT

'turn off analog input for port b.5
ANSELH=0
'and any other analog stuff
ANSEL=0

'there's several analog comparators - lets shut them off
'I dont know which one - shut them all off

CM1CON0 =0
CM2CON0 =0
CM2CON1 =0

adcon1=0
'now set it for input
trisb.5 = 1
trisc.0 =1


rxPin VAR portB.5
txPin VAR portB.7
rxVal Var Byte
txVal Var Byte


loop:
pause 1000
'serout txPin,T2400,["A"]
hserout ["A"]
Pause 1000
'High Portb.6
'Pause 1000
'Low portb.6
hserin [rxVal]
'serin rxPin,T2400,rxVal
'pause 500
'serout txPin,T2400,[rxVal]
hserout [rxVal]
'High Portb.6
'Pause 1000
'Low portb.6
pause 1000
goto loop
end

mackrackit
- 24th October 2008, 19:02
The code will output a character and then stop.
Where is the serial input coming from and what is is sending?

skimask
- 24th October 2008, 19:11
DEFINE HSER_ODD 1
How is it working at all?
Get rid of that line...

Archangel
- 26th October 2008, 06:47
From mr_e's PIC MULTICALC . . .


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 92 ' 2400 Baud @ 3.579MHz, 0.21%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically

rborsuk
- 27th October 2008, 16:55
Where is the serial input coming from and what is is sending?

Input is coming from me typing characters in Hyperterminal.

rborsuk
- 27th October 2008, 16:56
How is it working at all?
Get rid of that line...

Okay done. I was trying all kinds of things and forgot to remove that line. Please see my new post below.

Rob

rborsuk
- 27th October 2008, 17:02
From mr_e's PIC MULTICALC . . .


DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
DEFINE HSER_SPBRG 92 ' 2400 Baud @ 3.579MHz, 0.21%
DEFINE HSER_CLROERR 1 ' Clear overflow automatically


Okay. Below is my new code (I've added an LED to port b.6). Here's what happens. A capital 'A' shows on the terminal window, the LED goes on, the LED then goes out, another 'A' shows on the terminal, the LED goes on and there is where it stays. I never touched the keyboard during this time. After this process, it doesn't matter what I type in the terminal window, the light stays on and nothing else happens. Any thoughts?


Include "modedefs.bas"

DEFINE OSC 3

define HSER_RCSTA 90h
define HSER_TXSTA 24h

DEFINE HSER_SPBRG 92
DEFINE HSER_CLROERR 1


OSCCON= $08


'this is the layout for portb.5 - RB5/AN11/RX/DT

'turn off analog input for port b.5
ANSELH=0
'and any other analog stuff
ANSEL=0

'there's several analog comparators - lets shut them off
'I dont know which one - shut them all off

CM1CON0 =0
CM2CON0 =0
CM2CON1 =0

adcon1=0
'now set it for input
trisb.5 = 1
trisc.0 =1


rxPin VAR portB.5
txPin VAR portB.7
rxVal Var Byte
txVal Var Byte


loop:
pause 1000
'serout txPin,T2400,["A"]
hserout ["A"]
Pause 1000
High Portb.6
Pause 1000
'Low portb.6
hserin [rxVal]
'serin rxPin,T2400,rxVal
'pause 500
'serout txPin,T2400,[rxVal]
hserout [rxVal]
Low portb.6
pause 1000
goto loop
end

skimask
- 27th October 2008, 17:16
How about just a simple 'echo-ing' program to make sure everything is working first



Include "modedefs.bas"
DEFINE OSC 3
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 92
DEFINE HSER_CLROERR 1
Char VAR BYTE : led var portb.6 : output led : input portb.5 : output portb.7
Main: HSERIN [Char] : led = 1 : HSEROUT [Char] : pause 10 : led = 0 : GOTO Main
END

Type on the PC, characters should show up on the PC. Led should blink once for each character received/sent-back. Don't type any faster than 54 characters per second.

rborsuk
- 28th October 2008, 16:01
Skimask,
Okay, I put in your program. The light blinks once (when I release from reset - I don't touch anything), no character is displayed and that's it. I tried putting a HSEROUT before your main loop and it does send out a character. Any thoughts about turning off the built in analog stuff?


Rob

skimask
- 28th October 2008, 16:06
Skimask,
Okay, I put in your program. The light blinks once (when I release from reset - I don't touch anything), no character is displayed and that's it. I tried putting a HSEROUT before your main loop and it does send out a character. Any thoughts about turning off the built in analog stuff?

My bad...yes, turn off all of the analog ports...everything over to digital.


Include "modedefs.bas"
DEFINE OSC 3
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 92
DEFINE HSER_CLROERR 1
cm1con0 = 0 : cm2con0 = 0 : ansel = 0 : anselh = 0
Char VAR BYTE : led var portb.6 : output led : input portb.5 : output portb.7
led=1 : pause 500 : led=0 : pause 500 : led=1 : pause 500 : led=0 : pause 500
Main: HSERIN [Char] : led = 1 : HSEROUT [Char] : pause 10 : led = 0 : GOTO Main
END

mackrackit
- 28th October 2008, 16:10
Are you sure the PIC is running? Try a quick "blinky" without any serial stuff.

rborsuk
- 30th October 2008, 01:59
Mackrackit,
Yep, it's running. Follow the rest of my reply.
Skimask,
Sorry for the delay. I wanted to try some additional things. I'll explain in a bit. I tried the new code. It produces two long flashes on the LED and one very quick one. It then does nothing. No characters are displayed on the terminal and I can't enter anything. Thinking that it might be something else, I traded out the Max232 with a Max233 (eliminated the caps and such). Same results. I then tried a new 16F690 (thinking that the other one might have been damaged), same results. Anything we're missing here?

Rob

mister_e
- 30th October 2008, 02:02
Floating MCLR?
LVP is OFF?
Noisy PSU?
Poor contact, low battery, are some other great tests..

You could also begin your program with something like...

START:
HSEROUT ["1,2,1,2 TESTING....",13,10]
FOR MyVAR=0 TO 250
HSEROUT ["MyVAR=",#MyVAR,13,10]
NEXT
GOTO START

skimask
- 30th October 2008, 02:50
Does the F690 run from the external crystal by default?
Try removing DEFINE OSC 3 and see what happens.

mister_e
- 30th October 2008, 02:57
:D default config line is...

device pic16F690, intrc_osc_noclkout, wdt_on, mclr_on, protect_off

We don't see any config fuse setting here, so this would make some sense...

rborsuk
- 30th October 2008, 12:59
This is my config line


__config _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF


Rob

rborsuk
- 30th October 2008, 16:43
Success!!
Okay, same setup. Same code. This time compiling was done with the melabs compiler (instead of mpasm) and downloaded with a pickit2 (instead of an ICD2). I'm going to investigate this more and post my findings.

Rob

mackrackit
- 30th October 2008, 16:59
Success!!
Okay, same setup. Same code. This time compiling was done with the melabs compiler (instead of mpasm) and downloaded with a pickit2 (instead of an ICD2). I'm going to investigate this more and post my findings.

Rob
Great!!

Are you setting the configs in you code or the inc file?

rborsuk
- 30th October 2008, 17:05
I was setting them in the 16F690.INC file in the PicBasic Pro (PBP) folder. That's the right spot, correct?

Rob

mackrackit
- 30th October 2008, 17:24
I was setting them in the 16F690.INC file in the PicBasic Pro (PBP) folder. That's the right spot, correct?

Rob
That is the spot.
The are two sections in that file. One for MELABS and one for MPASAM.

Just wondering if you are modifying the settings for MELAB and not MPASAM?

rborsuk
- 30th October 2008, 18:04
Here's the exact include I was using with mplabs



NOLIST
ifdef PM_USED
LIST
include 'M16F6xx.INC' ; PM header
device pic16F690, intrc_osc_noclkout, wdt_on, mclr_on, protect_off
XALL
NOLIST
else
LIST
LIST p = 16F690, r = dec, w = -302
INCLUDE "P16F690.INC" ; MPASM Header
;* __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_ON & _CP_OFF
__config _XT_OSC & _WDT_ON & _MCLRE_ON & _CP_OFF
NOLIST
endif
LIST


When I switched to melabs, I modified the top one. I'm guessing that the pickit / icd2 wasn't the problem but maybe a difference in the compiler. What do you think?
Rob

mister_e
- 30th October 2008, 18:17
I think you always should comment all default config line (both for MPASM and PM, DEVICE and CONFIG lines) and then set your config fuses in your code.

Way more handy, because you don't need to remember each time which fuses you have hidden for a XYZ project using the same PIC.

Have a look at the following, post #1 and #5 are all you need for now.
http://www.picbasic.co.uk/forum/showthread.php?t=543

Archangel
- 30th October 2008, 18:21
Easier, I think to just comment them out and set them in your code every time. If you do not want to type, then make a file with all the setup code you use most often and open it everytime you start a new project, and save as, before your first compile.
EDIT: Mister_e, fast on the draw!

tomcee
- 31st January 2010, 16:22
Hello:

I am having this same issue; what was the solution?

Thanks,
TomC

tomcee
- 5th February 2010, 04:51
I neglected to set the ANSEL and ANSELH to 0!!!

TomC