PDA

View Full Version : Serial comm Problems



Fossil
- 30th December 2003, 08:11
Hi, I am currently doing my final year project and have been having problems with the serout2 and serin2 commands. At first, I written a simple program which is when I pressed 1 button of chip A, the led on chip B will light up. It works but whenever I press it after resetting both chips, the the first press of the button will not work, it will only work on the second time.

I solved the problem by sending a blank message before starting the program. But now I seem to be stuck with the same problem again when I did a more complicated again.

DEFINE OSC 4
ADCON1=7
TRISA=%00111000
TRISB=%00000001
TRISC=%00011000
PRESS VAR BYTE
REC VAR BYTE
PORTA=$00
PORTB=$00
PORTC=$00

BEGIN: PRESS=5
SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
PAUSE 50
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.0
PAUSE 250
LOW PORTA.0

READY: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
HIGH PORTA.0

REPLY: IF PORTA.3=0 THEN
PAUSE 300
IF PORTA.3=0 THEN
PRESS=1
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.2
PAUSE 100
LOW PORTA.2
LOW PORTA.0
ELSE
PRESS=2
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.1
PAUSE 100
LOW PORTA.1
LOW PORTA.0
ENDIF
ELSE
GOTO REPLY
ENDIF
GOTO READY
END

DEFINE OSC 4
ADCON1=7
TRISA=%00000100
TRISB=%00000001
TRISC=%00011000
PRESS VAR BYTE
REC VAR BYTE
PORTA=$00
PORTB=$00
PORTC=$00

BEGIN: PRESS=5
PAUSE 50
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SEROUT2 PORTC.5,3313,["ABC",PRESS]
SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
HIGH PORTA.0
PAUSE 250
LOW PORTA.0

READY: IF PORTA.2=0 THEN
LOW PORTA.0
LOW PORTA.1
SEROUT2 PORTC.5,3313,["ABC",PRESS]
HIGH PORTA.3
PAUSE 150
LOW PORTA.3
ELSE
GOTO READY
ENDIF

RECEIVE: SERIN2 PORTC.4,3313,[WAIT("ABC"),REC]
SELECT CASE REC
CASE 1
HIGH PORTA.0
CASE 2
HIGH PORTA.1
CASE ELSE
GOTO RECEIVE
END SELECT
GOTO READY

END

Can anyone help me with this problem?

Darrel Taylor
- 30th December 2003, 09:18
Hi Fossil,

I think it's just a simple problem. Since your using (300 baud true), the output needs to idle high for a short time, about 7ms (2 bit periods) minimum before sending the first data. So, at the beginning of your program use.

HIGH PORTC.5
pause 10

I think that should fix it.

HTH,
  Darrel

Fossil
- 2nd January 2004, 06:16
Ok thanks alot. It didn't really work but it triggered an idea. :)

Darrel Taylor
- 2nd January 2004, 08:37
Well, don't keep us in the dark. How did you fix it?

Fossil
- 7th January 2004, 03:29
Originally posted by Darrel Taylor
Well, don't keep us in the dark. How did you fix it?

Opps. Didn't notice your last reply. Actually I just send out preamble bits before sending out the data I want to send. So before sending, I send out '01010101' first. And it works.