PDA

View Full Version : pic18f252 hserout some times is incomplete



edysan
- 19th June 2006, 14:38
Ciao everybody.

With your help I fix my last bug, and I am back again with a strange problem in the same code.

Now the code it works fine, but some time HSEROUT is incomplete.

This is the result of runing of my code:
...
07335744556311114188340130000
07335744556311114188340130000
07335744556311114188340130000
073357445563111107335744556311114188340130000 <- this is wrong
07335744556311114188340130000
07335744556311114188340130000
07335744556311114188340130000
...

Can you help me?

Ingvar
- 19th June 2006, 16:41
I've seen it when using Hyperterminal with a high baudrate, lots of data and a slow computer. It was ofcourse not the HSERIN that was to blame. Try a different terminalprogram. If this isn't your setup, i have no idea what's going on. I've never had any problems with HSEROUT. The only thing i can think of that possibly could be called a problem with HSEROUT is that you can loose data if you end the program right after a HSEROUT statement .....

HSEROUT Blah,blah ...
END

The HSEROUT will not complete since the END will kill the OSC before the last character is sent. A PAUSE after HSEROUT will cure that problem.

/Ingvar

edysan
- 19th June 2006, 17:00
Thanks for answer.

I use the same code with PIC16F876 and works fine.
The problem is only on PIC18F525, and is verry random (never in the same point).
I will tay to explain better what I wont to have from my code:
A lot of numbers are saved on EEPROMs, when the acquisition are stoped I need to transfer this numbers on PC. I do this with Hserout. The Pic read the EEPROM and send this numbers to PC. I need to read, on my PC software, the same lengt of caracters, if the lenght of string are difrent I have a lot of errors, and missing data.
This problem of incomplete string are present in all PC application (Hiperterminal, CodeDesigner/Debug, etc...).

This is a part of my code.

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

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

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

Bruce
- 20th June 2006, 17:09
You don't show it in your example, but do you have DISABLE before the
loopdata interrupt sub-routine?

Darrel Taylor
- 20th June 2006, 23:57
Another thing you can't really tell from the partial program, is if the program can "Fall into" the interrupt handler without an interrupt. As shown, it would.

That might cause stack underflow problems.

.

edysan
- 21st June 2006, 00:55
Ciao.

Yes, I have DISABLE before the loopdata interrupt sub-routine.

My code run for nothing in dummy:, when receive an character from PC run the interupt and read data from EEPROM end send it to PC with HSEROUT.
I dont think can "Fall into" the interrupt handler without an interrupt.

Some times (verry rare) my code works without problem, but most of times I have this random error.
The same code with PIC16F876 works fine.

Thanks.
I wait any way other ideas.