Yes, you are right. Fixed it.Hi J2,
Testing CODE at #157in Oshonsoft:
Error: Needs HSEROPEN 9600. added, marked <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Error: See attached:
C.
Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x02
Define CONFIG2L = 0x0e
Define CONFIG2H = 0x2e
Define CONFIG3L = 0x1c
Define CONFIG3H = 0x1d
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
AllDigital
Dim data As Byte
Dim spidatareceived As Bit
Dim x As Byte
Dim msg As String
Symbol spi_cs = LATC.6
Symbol spi_cs_direction = TRISC.6
initialize_ports
initialize_variables
initialize_spi_slave
initialize_qei
Hseropen 9600
WaitMs 100
enable_interrupts
While x > 0
If spidatareceived = 1 Then
initialize_spi_master
send_spi_data CAP2BUFL
LATB = CAP2BUFL
Hserout "PORTB/CAP2BUFL/SSPBUF(DEC): ", #LATB, CrLf
data = LATB
msg = HexStr(data)
Hserout "PORTB/CAP2BUFL/SSPBUF(HEX): ", msg, CrLf
msg = "%"
If data.7 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
If data.6 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
If data.5 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
If data.4 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
If data.3 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
If data.2 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
If data.1 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
If data.0 = 1 Then
msg = msg + "1"
Else
msg = msg + "0"
Endif
Hserout "PORTB/CAP2BUFL/SSPBUF(BIN): ", msg, CrLf
initialize_spi_slave
spidatareceived = 0
Endif
Wend
End
On Low Interrupt
If PIE1.SSPIE = 1 And PIR1.SSPIF = 1 Then
PIR1.SSPIF = 0
If SSPSTAT.BF Then
data = SSPBUF
If data = 0xff Then
spidatareceived = 1
Endif
data = 0
Endif
SSPCON.SSPOV = 0
Endif
Resume
Proc initialize_ports()
ANSEL0 = 0
ANSEL1 = 0
TRISA = %11011100
TRISB = 0
TRISD = 0
End Proc
Proc initialize_variables()
x = 1
spidatareceived = 0
End Proc
Proc initialize_spi_master()
PIE1.SSPIE = 0
TRISC = %00010000
spi_cs = 1
SSPSTAT = %01000000
SSPCON = %00100010
End Proc
Proc initialize_spi_slave()
SSPSTAT = %01000000
SSPCON = %00100100
TRISC = %01110000
IPR1.SSPIP = 0
PIE1.SSPIE = 1
End Proc
Proc send_spi_data(data As Byte)
spi_cs = 0
SSPBUF = data
While SSPSTAT.BF = 0
Wend
SSPSTAT.BF = 0
spi_cs = 1
End Proc
Proc enable_interrupts()
INTCON.PEIE = 1
INTCON.GIEH = 1
INTCON.GIEL = 1
INTCON.GIE = 1
End Proc
Proc initialize_qei()
POSCNTH = 0
POSCNTL = 0
QEICON = %10000000
QEICON = %10010100
DFLTCON = 0
MAXCNTH = %00000100
MAXCNTL = 0
End Proc
Last edited:
