Random Serin/Serout issues
I have run across a problem with Serin/Serin2 and Serout/Serout2 to a lesser extent that has been driving me nuts for the last few days. I am guessing it has to do with my configuration and I have tried about 1000 different combinations to no avail.
Here is the problem. On a 16F1826 and an 18F1320 the following code does not return any data but does not stop and wait for the timeout. The code blows through the timeout like there is data there but there isn't. I went down the road of noise on the line to the extent of removing the Xbee that is talking to it and pulling the Serin pin both high and low and changing from true to inverted through a variety of resistors down to 47 ohms with no change in the code's behavior. On the 1320 but not the 1826 I can change the Serin pin to A.2 and it works fine. To confuse it more, a 16F628A works just fine with the same code (changing the osc values and registers to accommodate the different PICS). The code shown is the working code for the 628A with a bunch of stuff commented out that I was using while trying different combinations for the other two PICS.
Include "modedefs.bas"
'CMCON = 7
'ADCON1=7
'define OSC 8
' osccon = %01111110
'OSCCON=%01101010 1826
TRISA=%11111111 ' Set PortA to Output
trisb=%11111111 'Enable internal pull ups
Command var byte
Do
serin2 portb.4,396, 1000, mainpass,[command]
'if command = "R" then
'pause 100
serout2 portb.5, 396, ["5"]
high porta.3
pause 200
low porta.3
'endif
mainpass:
Loop
Maybe unrelated but I had a similar issue with an 18F2525 and Serout. A port C pin would work in the first instance it was used but after a few unrelated IO routines it would stop working (scope showed nothing going on during the time serial data was supposed to be sent). However, it worked just fine on another port C pin. I wish I remember the specifics but I just changed the circuit board to use a different pin. I was hoping if somebody smart enough to straighten me out on the above problem they might have insight as to why one pin would work but the other wouldn't so I don't have to blow a few hundred $ getting board reprints if it happens in the future.
Thanks in advance for any help you can provide.
Re: Random Serin/Serout issues
You need to enable Digital Inputs on the Analog pins.
;_16F1826_
ANSELA = 0
ANSELB = 0
;_18F1320_
ADCON1 = $7F
;_18F2525_
ADCON1 = $0F
Re: Random Serin/Serout issues
That seems to have done it and I don't know why I missed that. I suppose it may be because I have done projects on the 628A exclusively until now and didn't read about the liabilities that come with the new capabilities of the PICS I am working with now. Thanks again.
Re: Random Serin/Serout issues
Re: Random Serin/Serout issues
Quote:
Originally Posted by
Szczepaniec
. . . . and didn't read about the liabilities that come with the new capabilities of the PICS I am working with now. Thanks again.
This seems to ME to be the # 1 mistake of new members. You are in really good company. People in this forum have asked the question " why does anybody use or recommend the old grandpa 16F84 chips ? I would submit it is for the very reason as posted here, no registers require setting to disable analog. Reading data sheets requires some thought and understanding, or at least learning to read them, and although they usually do make sense it takes a while before the really do.
Best Regards
JS