Transfering DATA between two pics via SPI OSHONSOFT

Status
Not open for further replies.
Hi J,
Working
There are some patient people here, but a big thanks to JJW.
Camerart

____________________________________________________________________________________
SLAVE:
Dim azi As Word

get_count:

Toggle rled

azi.LB = CAP2BUFL
azi.HB = CAP2BUFH
While SSPBUF = 0
Wend
If SSPBUF = 1 Then
SSPBUF = azi.LB
Else
If SSPBUF = 2 Then
SSPBUF = azi.HB
Endif
Endif
WaitMs 100

Hserout "AZILB=", #azi.LB, " ", "AZIHB=", #azi.HB, CrLf

Goto get_count
_________________________________________________________________________________________
MASTER:
Dim azi As Word

main: '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
rled = 1
WaitMs 100
rled = 0
WaitMs 100

'READ DATA from AZIMUTH (4431)

WaitMs 1000
SPISend 1
WaitMs 100
SPIReceive azi.LB
WaitMs 100
SPISend 2
WaitMs 100
SPIReceive azi.HB

Hserout "AZI.LB=", #azi.LB, " ", "AZI.HB=", #azi.HB, CrLf

Goto main
 
Last edited:
Hi,
I've just come back to this thread, and now see that my optimism in #81 has been dashed, because even though this works with HSEROUT/IN, it needs to work with SPI
EDIT: I've re-read this post, and now I think it may be what I need, so I'm testing it again.
EDIT EDIT: First attempt failed, I'm puzzled why the SLAVE PIC doesn't need a CS?

C.
 
Last edited:
The slave does not need SS, if it is the only slave, then SS can be permanently ON.
Don't you see on master Hserout what is coming from slave?
 
The slave does not need SS, if it is the only slave, then SS can be permanently ON.
Don't you see on master Hserout what is coming from slave?
Hi J,
The SLAVE is the only SLAVE, but not the only MODULE addressed by SPI. CS/SS is used to time the READing of each module. I thought the SLAVE SS could be used to READ the SLAVE at the correct time in the program.

I don't see on the MASTER (18F4620) what is coming from the SLAVE, but I do see what is HSEROUT from the SLAVE (18F4431) by using a computer Terminal (e,g Tera term)

C.
 
Then you have multiple slaves and need to use SS on all devices.

Mike.
Hi M,
I consider a SLAVE as one that has been set up as a SLAVE, e,g,
______________________________________________________________________________
• Serial Data Out (SDO) • Serial Data In (SDI) • Serial Clock (SCK) Additionally, a fourth pin may be used when in a Slave mode of operation: • Slave Select (SS)
______________________________________________________________________________
And MODULES e,g, COMPASS which is simple switched on with CS
______________________________________________________________________________

C.
 
Can you not see why all modules need an SS pin?

Mike.
Hi M,
I can see why all modules need a CS/SS PIN, but I don't know how to set up 2xPICs as MASTER SLAVE. I have an SS track on my PCB between the 2x PICS

I didn't know that CS and SS meant the same thing.
C
 
Last edited:
Your master and slave setup has been ok before, because some data has been received from the slave.
Check all chip select and sdi / sdo connections for all SPI devices.
 
If I remember correctly, only the slave pic has hardware SS. The master has to have 1 pin per slave and select the correct one before communicating.

Mike.
 
Your master and slave setup has been ok before, because some data has been received from the slave.
Check all chip select and sdi / sdo connections for all SPI devices.
Hi J,
No DATA has ever been received by the MASTER PIC from the SLAVE PIC yet.

The slave had a RADIO MODULE that transmitted the QEI AZIMUTH into a computer Terminal, to show the INCREMENTAL ENCODER is working [ HSEROUT "AZI", strazi, crlf ] , but the setting for transferring SSBUF has not yet been done correctly. All the other MODULES e,g, Compass are working on SPI ok.
C.
 
If I remember correctly, only the slave pic has hardware SS. The master has to have 1 pin per slave and select the correct one before communicating.

Mike.
Hi M,
The MASTER has 1PIN/SLAVE including the PIC SLAVE. The PIC SLAVE SS is PIN44, All correct.
C
 
You wrote this in #75
"Hi,
So far all of the tests involving SPISEND, always SPIRECEIVES whatever value is SENT"

So the master got back what it had sent.
It means, that the slave did not put anything to SSPBUF, but the data was moving.
 
Whereto is the slave cs connected.
Show the define SPI's in the master.
Hi J,
Just spotted this!
I don't have CS set in the DEFINE SPI in MASTER.

Checking #75, you're correct, I'm getting mixed up. So we've had it kind of working before, good.

I change a few things and come back.
C.
 
You wrote this in #75
"Hi,
So far all of the tests involving SPISEND, always SPIRECEIVES whatever value is SENT"

So the master got back what it had sent.
It means, that the slave did not put anything to SSPBUF, but the data was moving.
Hi J,
I think my comment at #75 was incorrect.

See 2x attached programs, with the result, but this is because of HSEROUT in 4431 not SEND RECEIVE.
C.
 

Attachments

  • 18f4431 8MHz SLAVE QEI SPI 120719 0800w.txt
    2.4 KB · Views: 285
  • 18F4620 8MHz XTL TX QEI 120719 0800.txt
    3.5 KB · Views: 268
  • TEST.jpg
    115.7 KB · Views: 275
Last edited:
I think you have changed something.
Make a simple test.

SPIsend 5
SPIreceive data
Hserout data
SPIsend 10
SPIreceive data
Hserout data
 
In test.jpg you print the slave data.
If you want to test SPI, print the data in the master.
 
I think you have changed something.
Make a simple test.

SPIsend 5
SPIreceive data
Hserout data
SPIsend 10
SPIreceive data
Hserout data
Hi J,
DATA not accepted.
NOTE: To clarify, I changed the 18F4620 MASTER.

In the TEST.jpg both are shown, e,g for the 4620 "4620AZILB=" for the 4431 "4431AZILB="
C.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…