Transfering DATA between two pics via SPI OSHONSOFT

Status
Not open for further replies.
send something from master once.
in the slave read buffer full bit until it is 1
then data=SSPBUF
print data
stop
 
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.
 
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

  • 18f4431 8MHz TX SLAVE QEI SPI 200719 1400.bas
    3.4 KB · Views: 331
  • 18F4620 8MHz XTL TX QEI 200719 1400.bas
    3.1 KB · Views: 360
Last edited:
Hi J,
With these: I got a hint on MISO.
C.
 

Attachments

  • MASTER.txt
    337 bytes · Views: 315
  • Result.jpg
    188.8 KB · Views: 347
  • SLAVE.txt
    344 bytes · Views: 328
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
 
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

  • SLAVE.txt
    464 bytes · Views: 328
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?
 
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
C
 
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:
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

  • 18f4431 8MHz TX SLAVE QEI SPI 210719 1100.bas
    2.9 KB · Views: 315
  • 18F4620 8MHz XTL TX MASTER QEI SPI 210719 1100.bas
    3.3 KB · Views: 313
Last edited:
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:
Remove this from the master:
azilb = 121
SSPBUF = azilb

Add this:
SSPSend 1.

remove SSPSend azilb
 
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

  • SPIsend 1.jpg
    195.5 KB · Views: 338
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:
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.
Hi J,
MOSIMISO
C
 

Attachments

  • MOSIMISO.jpg
    188.4 KB · Views: 334
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
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…