camerart
Well-Known Member
Hi J,Is this from the master?
You have not set TRISCD for SDO in the slave.
Yes, from the MASTER
If you revisit #25 SLAVE I have clarified the comments, you should see that SDO is set correctly.
C.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Hi J,Is this from the master?
You have not set TRISCD for SDO in the slave.
The Define SPI... override the TRIS's and now:Hi J,
Yes, from the MASTER
If you revisit #25 SLAVE I have clarified the comments, you should see that SDO is set correctly.
C.
Hi J,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!
Ok, the master and slave are working!Hi J and M,
I'm not sure what I'm doing regarding INs and OUTs, but I always think I'm putting 1=IN and 0=OUT.
Anyway, here's the result of the test. [HSEROUT from the MASTER] READ on a Terminal]
C.
Hi J,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
SSPCON is needed in the slave program.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,SSPCON is needed in the slave program.
Hi J,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
In the slave read the SSPBUF until you get the numberHi 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.)
C.
' 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.Hi j,
Will you explain what actually happens in your CODE in #24 please?
C.
Hi j,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,I can't follow the logic.
You have goto loop, but no label loop.
The master sends lbhb, but its value is unknown.
Show both programs, master and slave.
Hi J,Maybe it works, azi.lb is 0 in the slave program.