• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Transfering DATA between two pics via SPI OSHONSOFT

jjw

Member
send something from master once.
in the slave read buffer full bit until it is 1
then data=SSPBUF
print data
stop
 

camerart

Active Member
send something from master once.
in the slave read buffer full bit until it is 1
then data=SSPBUF
print data
stop
Hi J, [ TRANSMITTER ]

Ok,
I'm sure you're suggesting that PRINT DATA is from the SLAVE, but as mentioned in #139 I doubt that HSEROUT will work in the circumstances.

I will try if BUFFER BIT = 1 then LED = 1, and see what happens.

C.
 

camerart

Active Member
Hi J, [ TRANSMITTER ]

No LED flash:(

Here's the 2x programs: Would you proof read them please, as there's been plenty of chances for errors.
The
EDIT: Added
I tried this on a second PCB, same result.

The RLED in SLAVE below shown by arrow, never comes on.

MASTER:
'main: '////////////////////////////////////////////////////////////////

'READ DATA from AZIMUTH (4431)
'Toggle rled

WaitMs 10000 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Hserout "SEND123", CrLf

SPICSOn
SLAVEpic = 0 'SLAVE PIC ON (NOTE SLAVE is CAPITAL LETTERS?)
SPISend 123
SLAVEpic = 1 'SLAVE PIC OFF
SPICSOff
Hserout "SENT", CrLf

'Goto main
------------------------------------------------------------------------------------------------------------------------
SLAVE:

LOOP:

Toggle yled

If SSPSTAT.BF = 1 Then
rled = 1 <--------------------------------------------------------<<<<<
DATA = SSPBUF
Endif

WaitMs 5000

rled = 0 'If SSPSTAT.BF = 0 Then yled = 0
WaitMs 5000


Goto LOOP
-----------------------------------------------------------------------------------------------------------------------
 

Attachments

Last edited:

jjw

Member
Hi J,
With these: I got a hint on MISO.
C.
What is the hint?
You can't use spisend, spireceive on the hw slave.
The slave is a passive device. It outputs SSPBUF on masters clock.
Try a small pause between SSPsend and SSPreceive on master
 

camerart

Active Member
What is the hint?
You can't use spisend, spireceive on the hw slave.
The slave is a passive device. It outputs SSPBUF on masters clock.
Try a small pause between SSPsend and SSPreceive on master
Hi J,
HINT: This is the first time, I've noticed anything on the ANALYSER MISO line.

Ok, I changed SLAVE to this:

I added [ waitms 10 ] in MASTER and only ever see [ 255 ]
C
 

Attachments

jjw

Member
Hi J,
HINT: This is the first time, I've noticed anything on the ANALYSER MISO line.

Ok, I changed SLAVE to this:

I added [ waitms 10 ] in MASTER and only ever see [ 255 ]
C
The slave waits for 8 or 9.
What does the master send?
 

camerart

Active Member
The slave waits for azilb or azihb. What are they?
Hi J,
The purpose of the SLAVE PIC is to READ an incremental encoder, which it does. The result of that will be 2x BYTEs of AZI (Azimuth) I just used AZILB because it was still there from encoder tests.

NOTE: I've just seen that I asked this question in January:banghead:
C
 

jjw

Member
If SSPBUF = azilb Then <------ what is the value of azilb
SSPBUF = azi.LB
Else
If SSPBUF = azihb Then <------ what is the value azihb
SSPBUF = azi.HB
Endif
Endif

If the master does not send the value of azilb or azihb the program gets never past this.
The naming of variables like azilb, azihb and then using azi.lb azi.hb is confusing.

Edit: found azilib is 1, azihb is 2
Try to send 1 from master, then 2
Show the whole Slave procram.
 
Last edited:

camerart

Active Member
If SSPBUF = azilb Then <------ what is the value of azilb
SSPBUF = azi.LB
Else
If SSPBUF = azihb Then <------ what is the value azihb
SSPBUF = azi.HB
Endif
Endif

If the master does not send the value of azilb or azihb the program gets never past this.
The naming of variables like azilb, azihb and then using azi.lb azi.hb is confusing.

Edit: found azilib is 1, azihb is 2
Try to send 1 from master, then 2
Show the whole Slave procram.
Hi J,
The MASTER can't SEND the values, because it doesn't know them, as they are generated in SLAVE.

I've tried many variations to get this to work, including your suggestions, so far I don't think anything has gone from SLAVE to MASTER along the MISO track, apart from 255.

SLAVE:
I used AZI as the ENCODER result, being AZIMUTH (=0-359) which is a WORD, and is split into 2x BYTEs, AZI.LB and AZI.HB

Pleas EDIT the programs, and I'l test them, with whatever VARIABLEs you choose.

Here' are the 2x programs:
C.
 

Attachments

Last edited:

jjw

Member
Hi J,
The MASTER can't SEND the values, because it doesn't know them, as they are generated in SLAVE.

I've tried many variations to get this to work, including your suggestions, so far I don't think anything has gone from SLAVE to MASTER along the MISO track, apart from 255.

SLAVE:
I used AZI as the ENCODER result, being AZIMUTH (=0-359) which is a WORD, and is split into 2x BYTEs, AZI.LB and AZI.HB

Pleas EDIT the programs, and I'l test them, with whatever VARIABLEs you choose.

Here' are the 2x programs:
C.
Surely the master can send anything.
The azilb and azihb have fixed values 1 and 2 in the slave program.
Try SSPSend 1, SSPSend 2
—----------------
From the slave

SLAVE:
Dim azi As Word
Dim azilb As Byte
Dim azihb As Byte
Dim DATA As Byte '??????????????????????????
azilb = 1. -<--------
azihb = 2. <--------
 
Last edited:

camerart

Active Member
Remove this from the master:
azilb = 121
SSPBUF = azilb

Add this:
SSPSend 1.

remove SSPSend azilb
Hi J,
Like this? ( I presume you meant [ SPIsend 1 ] )
Result:
C.
-----------------------------------------------------------------------------------------------------
main: '////////////////////////////////////////////////////////////////

'READ DATA from AZIMUTH (4431)
Toggle rled

SPICSOn
SLAVEpic = 0 'SLAVE PIC ON (NOTE SLAVE is CAPITAL LETTERS?)
SPISend 1
WaitMs 10
SPIReceive azilb
Hserout "4620AZILB- ", #azilb, CrLf
SLAVEpic = 1 'SLAVE PIC OFF
SPICSOff

Goto main
-----------------------------------------------------------------------------------------------------
 

Attachments

jjw

Member
This shows SPIsend 1
Can you show also the result for SPIReceive

Edit: you can shorten waitms 10 to waitus 40 for example, so send an receive fits on the same screen.
 
Last edited:

jjw

Member
I found something interesting in the manual!
After the Slave is selected ( SLAVEpic=0), keep it at 0 permanently.


From the manual:
1.When the SPI is in Slave mode, with
the SS pin control enabled,
(SSPCON<3:0> = 0100), the SPI
module will reset if the SS pin is set to. <<<<< !!!!!!!!!!!!!!!!
VDD.
2: If the SPI is used in Slave mode with
CKE = 1, then the SS pin control must be
enabled.
3: When the SPI is in Slave mode with SS pin
control enabled (SSPCON<3:0> = 0100),
the state of the SS pin can affect the state
read back from the TRISC<6> bit. The
peripheral OE signal from the SSP module
into PORTC controls the state that is read
back from the TRISC<6> bit (see
Section 11.3 “PORTC, TRISC and LATC
Registers” for information on PORTC). If
Read-Modify-Write instructions, such as
BSF, are performed on the TRISC register
while the SS pin is high, this will cause the
TRISC<6> bit to be set, thus disabling the. . <<<<<<<< !!!!!!!!!!!!!!!
SDO output
 

EE World Online Articles

Loading

 
Top