PDA

View Full Version : Serial communication fails after long pause



brid0030
- 13th February 2008, 16:52
I'm having a strange problem which I suspect is due to hardware, but who knows. I'm trying to communicate with a palm pilot via RS232 through a MAX232 unit. I have SEROUT2 commands scattered throughout my code and they work until I reach a point in which there is a long (10 second) pause. A SEROUT2 command follows the pause and gives me an error on the palm. When I run the program hooked up to a serial communicator on a PC, I don't get an error, but the SEROUT that follows the pause is mostly garbeldygook. The SEROUT commands that follow are OK.

I've monitored the voltage on the serout pin and it is zero during the pause. I've tried baud rates from 300 to 9600 (strangely 9600 works the best) and the problem remains. Any suggestions as to what is going on during the long pause? Do I need pull-ups or pull-downs on the serial pins?

Here is the code--all simple stuff....



'************************************************* ***************
'* Name : B_Logger.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2008 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 2/6/2008 *
'* Version : 1.0 *
'* Notes : PIC16F688 *
'* : INTERNAL OSC; MCLR OFF *
'************************************************* ***************

'BIRDLOGGER CONTROL PROGRAM
'I2C COMMUNICATION VIA PORTS C4 AND C3
'ANALOG INPUT ON PORTA.0
'DIGITAL INPUT ON PORTC.1 WITH 10K PULLUP
'RS232 COMMUNICATION
'PORTA.5 DATA IN
'PORTA.4 DATA OUT
'PORTA.1 output; start/stop
'PORTA.2 output; maintain power

'DEFINE VARIABLES
B0 VAR BYTE
B1 VAR BYTE

'ALIAS PINS
SDA VAR PORTC.4
SCL VAR PORTC.3
SDIN VAR PORTA.5
SDOUT VAR PORTA.4
REC VAR PORTA.1
PWR VAR PORTA.2
SWITCH var PORTC.1
FLEX VAR PORTA.0

'DEFINE PINS
TRISA = %00100001
TRISC = %00000010

LOW REC
SEROUT2 SDOUT,84,["test 9", 13, 10]
pAUSE 10

MAINLOOP:
SEROUT2 SDOUT,84,["MAIN LOOP", 13, 10]
PAUSE 10
IF SWITCH = 0 THEN trigger 'MONITOR THE SWITCH
PAUSE 10
IF SWITCH = 0 THEN trigger
B0 = B0 +1 'COUNTING VARIABLE TO CONTROL PWR BUTTON
if B0 = 10000 THEN 'ONCE EVERY 2-3 MIN PRESS THE PWR BUTTON TO KEEP CAMERA ON
B0 = 0 'RESET COUNTING VARIABLE
HIGH pwr 'PRESS PWR BUTTON
FOR B1 = 1 TO 20 'LOOP THAT ALLOWS PWR BUTTON TO STAY PUSHED FOR .2 SEC TO OVERCOME BOUNCE COCNTROL
IF SWITCH = 0 THEN trigger 'MAINTAINS SWITCH MONITORING
PAUSE 10
NEXT B1
ENDIF
GOTO MAINLOOP 'RETURN TO THE BEGINNING

End

trigger:
SEROUT2 SDOUT,84,["trigger", 13, 10]
PAUSE 10
HIGH REC 'HIT THE RECORD BUTTON TO ACTIVATE RECORDING
Pause 250 'PAUSE TO OVERRIDE BOUNCE CONTROL
LOW REC 'RELEASE RECORD BUTTON
Pause 500 'RECORD FOR 1/2 SECOND
HIGH REC 'HIT RECORD BUTTON AGAIN TO STOP RECORDING
Pause 250
LOW REC 'RELEASE RECORD BUTTON
Pause 10000 'LONG PAUSE TO LET CAMERA STORE VIDEO
SEROUT2 SDOUT,84,["recording done", 13, 10]
Pause 10
REPEAT
SEROUT2 SDOUT,84,["waiting...", 13, 10]
pAUSE 100
UNTIL SWITCH = 1
SEROUT2 SDOUT,84,["back to loop", 13, 10]
GOTO MAINLOOP

brid0030
- 13th February 2008, 17:57
I have to revise what I said above. It is not the pause that causes serial communication to fail but the toggling of PORTA.2. When I comment out the HIGH REC and LOW REC stuff the serial comm works. I'm still in the dark as to what is going on tho. Why should toggling a pin on another port affect serial communication? I've also got problems getting the input on PORTC.1 to work. I've got a pull-up tied to the port and a switch connecting to ground. The pin reads high on my volt-meter but the program runs as though it is always low. Craziness abides.

skimask
- 13th February 2008, 18:09
I have to revise what I said above. It is not the pause that causes serial communication to fail but the toggling of PORTA.2. When I comment out the HIGH REC and LOW REC stuff the serial comm works. I'm still in the dark as to what is going on tho. Why should toggling a pin on another port affect serial communication? I've also got problems getting the input on PORTC.1 to work. I've got a pull-up tied to the port and a switch connecting to ground. The pin reads high on my volt-meter but the program runs as though it is always low. Craziness abides.

I don't see ANY ANSEL, ADCON0, ADCON1, CMCON0, CMCON1 register settings anywhere in there...
Take a look at the datasheet and see if your fix is anywhere around there.

brid0030
- 13th February 2008, 18:25
Right, I just figured that out. I'll post the solution as it trickles in.

brid0030
- 13th February 2008, 18:56
OK, so CMCON0 = 0 and ANSEL = 0 solved everything.

See http://www.picbasic.co.uk/forum/archive/index.php/t-561.html.

I'm such a rookie....