The Define SPI... override the TRIS's and now:
Trisc.6 = 0 should be input
Trisd.3 = 0 should be input
Trisd.1 = 0
Trisd.2 = 1
Remove all Spi defines and SpiPrepare from the slave program!
The Define SPI... override the TRIS's and now:
Trisc.6 = 0 should be input
Trisd.3 = 0 should be input
Trisd.1 = 0
Trisd.2 = 1
Remove all Spi defines and SpiPrepare from the slave program!
The way I remember TRISS settings is that 1 looks like I (start of Input) and so I know that setting TRISS to 1 makes it an input. You seem to be setting pins to 0 for an input.
Ok, the master and slave are working!
The ins and outs were correct in the Tris's, but the define SPI's messed them.
Now to read the 16bit azimuth, write azimuth.HB to SSBUF,
read it in the master, then azimuth. LB
Some conversation between master and slave is needed for this.
For example master could send 1 and when slave reads 1 it puts the highbyte into SSBUF, master reads it and then the same with 2 and the lowbyte
Ok, the master and slave are working!
The ins and outs were correct in the Tris's, but the define SPI's messed them.
Now to read the 16bit azimuth, write azimuth.HB to SSBUF,
read it in the master, then azimuth. LB
Some conversation between master and slave is needed for this.
For example master could send 1 and when slave reads 1 it puts the highbyte into SSBUF, master reads it and then the same with 2 and the lowbyte
Hi J,
These tests are only between 18F4620 and 18F4431 when I put them into the bigger program with more SLAVEs, there needs to be a C/S for the AZIMUTH SLAVE (18F4431)
Perhaps I'll try one BYTE first. LB
NOTE: In tests I edited out SSPCON. Should it be in?
C.
Hi J,
These tests are only between 18F4620 and 18F4431 when I put them into the bigger program with more SLAVEs, there needs to be a C/S for the AZIMUTH SLAVE (18F4431)
Perhaps I'll try one BYTE first. LB
NOTE: In tests I edited out SSPCON. Should it be in?
C.
Ok, the master and slave are working!
The ins and outs were correct in the Tris's, but the define SPI's messed them.
Now to read the 16bit azimuth, write azimuth.HB to SSBUF,
read it in the master, then azimuth. LB
Some conversation between master and slave is needed for this.
For example master could send 1 and when slave reads 1 it puts the highbyte into SSBUF, master reads it and then the same with 2 and the lowbyte
Hi J,
I've tried various variations, of what you suggest, but so far only 1x BYTE received.
MASTER:
If I SPISEND a number (BYTE) to the slave, so the SLAVE can act accordingly, then SPIRECEIVE 'say' AZIMUTHLB I get the number not the expected AZIMUTHLB. This is puzzling. (Can you explain how your test #24 works please.)
Hi J,
I've tried various variations, of what you suggest, but so far only 1x BYTE received.
MASTER:
If I SPISEND a number (BYTE) to the slave, so the SLAVE can act accordingly, then SPIRECEIVE 'say' AZIMUTHLB I get the number not the expected AZIMUTHLB. This is puzzling. (Can you explain how your test #24 works please.)
In the slave read the SSPBUF until you get the number
( for example 1) then write the azi. LB into SSPBUF.
Something like this.
It reads the azi.lb once a second.
Code:
' In the master:
loop:
spisend 1 ' I dont know if 1 should be a variable with a value 1
waitus 100 ' wait for the slave to act
spireceive azi.lb
hserout #azi.lb,crlf
waitms 1000
goto loop
'In the slave
loop:
' get the azi.lb from QEI here
d= SSPBUF
if d=1 then
SSBUF=azi.lb
else
goto loop
endif
It is a simple program to test that the data transfers between master and slave.
The master sends the numbers from 1 to 10 to slave and reads them back from the slave. The numbers coming back are shown on the terminal.
Hi J,
following #52: Because I always seem to receive a 1 if I SPISEND 1, I used a VARIABLE (LBHB) I also avoided 1, as I could RECEIVE 1 as a COUNT, so I chose 5 for LB and 7 for HB.
Using this:
SLAVE:
get_count:
WaitMs 1000
Toggle rled
''If SSPSTAT.BF = 1 Then
lbhb = SSPBUF
If lbhb = 5 Then
SSPBUF = azi.LB
Else
Goto loop
Endif
It is a simple program to test that the data transfers between master and slave.
The master sends the numbers from 1 to 10 to slave and reads them back from the slave. The numbers coming back are shown on the terminal.
The MASTER is a section of a long program (I'll post it if asked)
Here:
_________________________________________________________________________________________
Dim azi As Word
Dim lbhb As Byte
lbhb = 5