PDA

View Full Version : pic18f252 hserout problem



edysan
- 16th June 2006, 14:28
Ciao everybody.

I try to migrate from pic16f876 to pic18f252. The software witch run on 16f876 is fully working, but when I transfer to 18f252 dont works.
I try to expalin more bette the situation. My programm are witing a number with an interrupt from PC, if receive the right code then read some data from EEPROM and sent it to PC with HSEROUT.
It works without limit on 16f876. I can read thousent numbers.
On 18f252 works only for 26times, after this nothing!?!

I need some help, please.

PS. Sorry about my english.

Bruce
- 16th June 2006, 16:16
Post a sample of your code that doesn't work on the 18F part.

edysan
- 16th June 2006, 17:01
This is a part of my code.
As I write first my code works for 26 times only. This limit are only with 18f252, (not with 16f876).

DEFINE OSC 20
DEFINE HSER_CLROERR 1
DEFINE HSER_BAUD 57600
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
...
INTCON = %11000000
PIE1.5 = 1
...
ON INTERRUPT GoTo loopdata
...
loopdata:
While RCIF
B1=RCREG

IF B1=48 Then HSerout ["Speed is ...",10,13] ' caracter ascii 48= "0"

IF B1=49 Then ' caracter ascii 49= "1"
For m=1 TO 16
I2CRead sda_A,scl_A,ctl,mem_addr+(m-1),[data[m]]
Next m

'*** this is the problem!?!
HSerout [DEC2 data[1],DEC2 data[2],DEC2 data[3]...,10,13]
'*** this is the problem!?!

mem_addr=mem_addr+16
GoTo dummy
EndIF
...
Wend
Resume
Enable
...
dummy:
For X = 0 TO 300
PauseUs 200
Next X
GoTo dummy
...

Can be a problem of a buffer?
Thanks again.

Bruce
- 16th June 2006, 17:36
mem_addr=mem_addr+16
GoTo dummy '<--- this will be a problem
EndIF
...
Wend
Resume
Enable < -- do not GOTO outside of this block

Be sure you have DISABLE before your interrupt service routine, and ENABLE
after your interrupt service routine, and you stay within this block until you're
finished with the interrupt service.

Do NOT jump or GOTO outside the DISABLE ENABLE block. If you do, you have
problems with the stack, and you're landing in a code section that will loop
right back to the start of your interrupt service routine.

You may get away with this on a 16F part since it will re-cycle back to the
beginning of the stack. On the 18F part, it stops at the last location, and you
cannot push another address onto the stack.

edysan
- 16th June 2006, 20:46
With the first test, looks to be ok. Now it works.

Thanks.
edysan, Italy