PDA

View Full Version : serout out of order on 12F675



Ricardo
- 28th April 2008, 05:35
IŽm trying to send data from PIC to BS2 via serout2 but the values are sistematically been altered.

The 12F675 is generating the sequence:
0,1,2,3,4,...,255

And the BS2 is receiving:
128,129,130,131, ... , 157,158,159,128, 129,130,...

I verified and OSCCAL was not erased.
Things got better when i include the line:

Define OSCCAL_1K 1

on the code, but the problem did not dissapear at all.

here are the codes:

12F675 code:


include "bs2defs.bas"
Define OSCCAL_1K 1 ' Set OSCCAL for 1K Device

ANSEL=%00000000
CMCON=%00000111

Trisio = %11111111 ' Set all ports as inputs
Trisio.4 = 0 ' Set port GP4 as output

saida CON 4

i var byte

pause 1000
loop:
for i = 0 to 255
serout2 saida,16780,[i]
pause 100
next

pause 2000
goto loop
end


The BS2 code:


' {$STAMP BS2}
' {$PBASIC 2.5}

entr PIN 1
entr_mode CON 16780 'entrada baudmode = 2400/8N1 INV
PAUSE 10

p VAR Byte

Start:
SERIN entr,entr_mode,[p]
DEBUG DEC p," "
GOTO Inicio


Seems to me that is some timing problem. I overnight on this problem without a solution. I must be missing something trivial, but I cant figure out what!

IŽll appreciate any help

mister_e
- 28th April 2008, 05:50
What happen if you place

GPIO=0 just before the PAUSE 1000?

Did you tried to connect your PIC directly to your PC?

Ricardo
- 28th April 2008, 17:14
Thank you for your comment, I will try your suggestion. Just a note: the code works fine on an 16F688 using the same I/O pin GP4.(with minors modifications: TRISIO replaced by TRISA, ANSEL replaced by ADCON1, CMCON line removed)

Ricardo
- 28th April 2008, 17:15
Thank you for your comment, I will try your suggestion. Just a note: the code works fine on a 16F688 using the same I/O pin GP4.(with minors modifications: TRISIO replaced by TRISA, ANSEL replaced by ADCON1, CMCON line removed). I didn't try to connect directly to my PC.

paul borgmeier
- 28th April 2008, 21:20
Serout2 sends LSB first – your HSB appears to be the one that is corrupted. This screams “timing issue” to me. If you are using the Internal Oscillator (which it appears you are), you might want to switch to a XTAL for reliable timing. If that is not possible, consider a slower baud rate or get a good scope and play with the OSCAL value until the timing works (at the given temperature – it will change if the temperature changes).
HTH,

Ricardo
- 28th April 2008, 23:59
Paul,

Based on your comment, I assumed that the pic basic was reading the stop bit as the MSB of the data. My conclusion is that the pic clock was too fast. So I reduced the OSCCAL from its 3460h original value to 3450h and it worked on the first try! Now IŽll play a litle bit more with the OSCCAL to find the midpoint to (hopefully) garantee that the circuit will be stable over temperature changes.

Thank you for your valuable help!

Ricardo
- 29th April 2008, 00:02
What happen if you place

GPIO=0 just before the PAUSE 1000?

Did you tried to connect your PIC directly to your PC?

Putting GPIO=0 have no effects on the output, but I can learn on the process. What is the purpose of this line?

paul borgmeier
- 29th April 2008, 01:16
>> Putting GPIO=0 have no effects on the output, but I can learn on the process. What is the purpose of this line?

Mister-E wanted to make sure you were idling low, which is good practice.