PDA

View Full Version : Slave/Master communication problems



jmescajadillo
- 12th September 2006, 17:20
I'm using a program of master/slave structure using serial communications.

This is the slave program (The comments were made on its original language, Spanish):

include "modedefs.bas"
trs var PORTC.6 'Variable que identifica PORTA.0
F var BYTE
T var BYTE 'Numero de traje
A var BYTE 'Variables de Botones
T=0
trisa = 255 'Configura PORTA pata todas las entradas
ADCON1 = 0 'PORTA es analógica
DEFINE ADC_BITS 8

loop:
Low PORTB.5
Low PORTB.6
Low PORTB.7

Low PORTB.0
Low PORTB.1
Low PORTB.2 'boton1
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=11
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

High PORTB.5
Low PORTB.6
Low PORTB.7

Low PORTB.0
Low PORTB.1
Low PORTB.2 'boton2
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=12
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

Low PORTB.5
High PORTB.6
Low PORTB.7

Low PORTB.0
Low PORTB.1
Low PORTB.2 'boton3
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=13
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

Low PORTB.5
Low PORTB.6
Low PORTB.7

High PORTB.0
Low PORTB.1
Low PORTB.2 'boton4
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=14
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

High PORTB.5
Low PORTB.6
Low PORTB.7

High PORTB.0
Low PORTB.1
Low PORTB.2 'boton5
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=15
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

Low PORTB.5
High PORTB.6
Low PORTB.7

High PORTB.0
Low PORTB.1
Low PORTB.2 'boton6
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=16
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

Low PORTB.5
Low PORTB.6
Low PORTB.7

Low PORTB.0
High PORTB.1
Low PORTB.2 'boton7
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=17
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

High PORTB.5
Low PORTB.6
Low PORTB.7

Low PORTB.0
High PORTB.1
Low PORTB.2 'boton8
ADCIN 0,A
F=A-50
IF (A<50) THEN
T=18
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

Low PORTB.5
High PORTB.6
Low PORTB.7

Low PORTB.0
High PORTB.1
Low PORTB.2 'boton9
ADCIN 0,A
F=A-50

IF (A<50) THEN
T=19
Serout trs,n9600,[#T] 'trs var PORTC.6 pin 17
Pause(50)
Serout trs,n9600,[#F] 'trs var PORTC.6 pin 17
Pause(50)
Endif

Goto loop

End

The transmission results are shown on the file "Recepcion 3.jpg", attached in this post.

This is the Master program that pretends to grab these results and send it to the computer:

include "modedefs.bas"

NT Var BYTE
FT Var BYTE
TX Var PORTC.6
RX Var PORTC.7

seguir:
serin rx,n9600,NT
serin rx,n9600,FT
serout tx,n9600,[#NT,"-"]
serout tx,n9600,[#FT,10,13]
goto seguir
END

The results are shown on the file "Transmision 3.jpg", also attached in this post.

Once you saw the files and programs, you can see the magnitude of the problem. The results of the master program does not match the ones on the slave. While the slave send the correct parameters and results, the master sends another that are incorrect. I think it's a matter with the serin and serout commands, something that I just missed. Please help me with this and I'll be grateful, because this is part of my universitary thesis!

Regards and thanks for your attention...

Juan Escajadillo

mister_e
- 12th September 2006, 23:09
Try..


serin rx,n9600,#NT
serin rx,n9600,#FT

jmescajadillo
- 13th September 2006, 20:56
Try..


serin rx,n9600,#NT
serin rx,n9600,#FT


I've already tried this way due to a little knowledge of the serin command, but it got worse: it doesn't transmit anything on the hyperterminal program! Please suggest me something else to solve my problem.

Thank you anyway

Juan Escajadillo

P.S: I'm using two pics: the PIC16F873A for the slave, and the PIC16F876A for the master. They have similar pin structure... and they work! How do I know when one of my PICs is deffective?