Continue to Site

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.

  • 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

Status
Not open for further replies.
Hi J,
I'm not sure what you mean, but I added LBHB = 5 after the DIM, and nothing changed.
C.
LBHB has nothing to do with azi.lb which the master tries to read.

slave:

lbhb = SSPBUF
If lbhb = 5 Then
SSPBUF = azi.LB' this value is read by the master and is zero
Else
Goto loop
Endif

master:

SPISend lbhb
WaitMs 100
SPIReceive azi. LB ' <---- azi.LB is 0
Hserout "AZI.LB ", #azi.LB, CrLf
 
In the slave put azi=azi+1 after SPIReceive azi. lb
Then you should see in the master azi changing 0,1,2,3...
 
In the slave put azi=azi+1 after SPIReceive azi. lb
Then you should see in the master azi changing 0,1,2,3...
Hi J,
SPIReceive azi.lb is in the MASTER? I tried it and no result.
I added a HSEROUT to the SLAVE and it didn't count.

Here is a SLAVE program that does count:
____________________________________________________________________________
Dim azi As Word

get_count:
WaitMs 1000
Toggle rled
'''If SSPSTAT.BF = 1 Then

'''SSPBUF = CAP2BUFL
azi.LB = CAP2BUFL
azi.HB = CAP2BUFH

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

Goto get_count
_____________________________________________________________________________
And gets this:
C.
 

Attachments

  • SLAVE Count.jpg
    SLAVE Count.jpg
    68 KB · Views: 277
Hi J,
SPIReceive azi.lb is in the MASTER? I tried it and no result.
I added a HSEROUT to the SLAVE and it didn't count.

Here is a SLAVE program that does count:
____________________________________________________________________________
Dim azi As Word

get_count:
WaitMs 1000
Toggle rled
'''If SSPSTAT.BF = 1 Then

'''SSPBUF = CAP2BUFL
azi.LB = CAP2BUFL
azi.HB = CAP2BUFH

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

Goto get_count
_____________________________________________________________________________
And gets this:
C.
SSPReceive and SSPSend are in the master.
All data transfers are initiated by the master.
Add to slave SSBUF=azi.lb
Remove lbhb=5 from master
Should see something in the master.
 
SSPReceive and SSPSend are in the master.
All data transfers are initiated by the master.
Add to slave SSBUF=azi.lb
Remove lbhb=5 from master
Should see something in the master.
Hi J,
I did get a COUNT from the SLAVE using the terminal, but not in the MASTER.

Can you EDIT these from your #61 so I can be clear please? I'll test them.
________________________________________________________________________________
SLAVE:

lbhb = SSPBUF
If lbhb = 5 Then
SSPBUF = azi.LB' this value is read by the master and is zero
Else
Goto loop
Endif
-----------------------------------------------------------------------------------------------------
MASTER:

SPISend lbhb
WaitMs 100
SPIReceive azi. LB ' <---- azi.LB is 0
Hserout "AZI.LB ", #azi.LB, CrLf

____________________________________________________________________________
C.
 
Try this in slave.

get_count:
WaitMs 1000
Toggle rled
'''If SSPSTAT.BF = 1 Then

'''SSPBUF = CAP2BUFL
azi.LB = CAP2BUFL
azi.HB = CAP2BUFH
SSPBUF=azi. lb ' <---- add this

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

Goto get_count
—-------------------
in MASTER:

' SPISend lbhb <----- delete this
WaitMs 1000
SPIReceive azi. LB
Hserout "AZI.LB ", #azi.LB, CrLf
 
Try this in slave.

get_count:
WaitMs 1000
Toggle rled
'''If SSPSTAT.BF = 1 Then

'''SSPBUF = CAP2BUFL
azi.LB = CAP2BUFL
azi.HB = CAP2BUFH
SSPBUF=azi. lb ' <---- add this

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

Goto get_count
—-------------------
in MASTER:

' SPISend lbhb <----- delete this
WaitMs 1000
SPIReceive azi. LB
Hserout "AZI.LB ", #azi.LB, CrLf
Hi J,
Result of above test.
C.
________________________________________________________________
MASTER: Chip selects
'CSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSS
Symbol dataswitch = LATD.7 'RX 2to1 switch 1=GPS 0=HC-12
Symbol compss = LATD.6 'AK8963C
Symbol altmtr = LATD.5 'BMP280 BAROMETER/TEMP
Symbol lcd5110 = LATD.4 '5110 LCD
Symbol radset = LATD.3 'RADSET 0=COMMAND ON 1=DATA ON
Symbol azim = LATD.2 'SLAVE PIC C/S (SLAVE RC6)
'CSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSS
 

Attachments

  • SLAVE left_ MASTER right.jpg
    SLAVE left_ MASTER right.jpg
    144.1 KB · Views: 291
Hi J,
Result of above test.
C.
________________________________________________________________
MASTER: Chip selects
'CSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSS
Symbol dataswitch = LATD.7 'RX 2to1 switch 1=GPS 0=HC-12
Symbol compss = LATD.6 'AK8963C
Symbol altmtr = LATD.5 'BMP280 BAROMETER/TEMP
Symbol lcd5110 = LATD.4 '5110 LCD
Symbol radset = LATD.3 'RADSET 0=COMMAND ON 1=DATA ON
Symbol azim = LATD.2 'SLAVE PIC C/S (SLAVE RC6)
'CSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSCSS
This looks like the receiver?
Is'nt the incremental encoder in the transmitter?
 
Last edited:
This looks like the receiver?
Is'nt the incremental encoder in the transmitter?
Hi J,
We are only talking about the Transmitter here. (The receiver is very similar but with SERVOS and no encoder)

Here is the full MASTER program:
C.
 

Attachments

  • 18LF4620 8Mhz TX 2XPIC HC-12 GPS BMP280 AK8963C 5110 J 080219 2000.bas
    19.4 KB · Views: 289
Hi j,
Here's a logic analysis, showing somethings wrong. I'm checking.
C.
 

Attachments

  • SPI.jpg
    SPI.jpg
    116.3 KB · Views: 257
Hi J,
I repaired the PCB, and here's the result :)
It looks like it's working, I'll add the AZIHB, and re'check.
Thanks. sorry for the mix ups, I've got two double PCBs, with different program, so I'm surprised I haven't been more mixed up.
C.
 

Attachments

  • SLAVE left MASTER right.jpg
    SLAVE left MASTER right.jpg
    71.2 KB · Views: 293
Hi,
So far all of the tests involving SPISEND, always SPIRECEIVES whatever value is SENT

The best results so far are from these programs, with the SLAVE COUNT at AZILB=100 AZIHB = 1. The correct result, only happens approx 1 in 15 seconds.

'________________________________________________________________________
Section from MASTER 4620:
Dim azi As Word
Dim azilb As Byte
Dim azihb As Byte

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

''''READ DATA AZIMUTH (4431)

''''azim = 0 'CHIP SELECT 4431 ON (As reminder, not in program)

SPIReceive azilb
WaitMs 100
SPIReceive azihb
WaitMs 100

''''azim = 1 'CHIP SELECT 4431 OFF (As reminder, not in program)

Hserout "AZILB= ", #azilb, CrLf
WaitMs 100
Hserout "AZIHB= ", #azihb, CrLf
WaitMs 100

Goto main '<<<<<<<<<<<<<<<<REMOVE<<<<<<<<<<<<<<<<<
____________________________________________________________________________________________
 

Attachments

  • 18F4431 8MHz INT COUNT 0_359 SPI J 100219 1300.bas
    2.4 KB · Views: 264
  • '18F4431 8MHz INT COUNT 0_359 SPI J 100219 1300.jpg
    '18F4431 8MHz INT COUNT 0_359 SPI J 100219 1300.jpg
    89.3 KB · Views: 265
  • 18LF4620 8Mhz TX 2XPIC HC-12 GPS BMP280 AK8963C 5110 J 100219 1300.jpg
    18LF4620 8Mhz TX 2XPIC HC-12 GPS BMP280 AK8963C 5110 J 100219 1300.jpg
    47.8 KB · Views: 269
You have to sync the master and slave to know what will be read.
When the master reads from slave ( Spiread ), SSPBUF in the slave is cleared.
The next read will be zero, if the slave has not written a new value to SSPBUF.
 
You have to sync the master and slave to know what will be read.
When the master reads from slave ( Spiread ), SSPBUF in the slave is cleared.
The next read will be zero, if the slave has not written a new value to SSPBUF.
Hi J,
I'm trying different ideas, around your programs.
Did you note that in #75, I used AZILB and AZIHB as well as AZI.LB and AZI.HB?

NOTE: I assume for SPIREAD you mean SPIRECEIVE.
C.
 
Yes, Spireceive.
Slave has to write a new value to SSPBUF before Spireceive in the master ( now 100ms )
Something like this in Slave:

loop:
azi. lb =...
azi. hb=...
while SSPBUF= 0
wend
if SSPBUF = 1
SSPBUF = azi. lb
else
if SSPBUF = 2
SSPBUF = azi.hb
endif
endif
waitms 100
goto loop

Master:

loop:
waitms 1000
spisend 1
waitms 100
receive azi. lb
waitms 100
spisend 2
waitms 100
receive azi. hb
goto loop
 
Hi J,
These compile and program ok, but produce zero.
I had to add AZILB AZIHB because as you pointed out, it doesn't accept SPISEND = 1.
I'll try variations tomorrow.
MASTER:
_____________________________________________________________________
Dim azi As Word
Dim azilb As Byte
Dim azihb As Byte

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

'READ DATA from AZIMUTH (4431)

WaitMs 1000
SPISend azilb
WaitMs 100
SPIReceive azi.LB
WaitMs 100
SPISend azihb
WaitMs 100
SPIReceive azi.HB

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

Goto main '<<<<<<<<<<<<<<<<<<<<REMOVE<<<<<<<<<<<<<<<<<<<<
__________________________________________________________________________________
SLAVE:
Dim azi As Word
Dim azilb As Byte
Dim azihb As Byte
azilb = 1
azihb = 2


get_count:

azi.LB = 0 'azi.LB =...Not sure what goes here
azi.HB = 0 'azi.HB =...
While SSPBUF = 0
Wend
If SSPBUF = azilb Then
SSPBUF = azi.LB
Else
If SSPBUF = azihb Then
SSPBUF = azi.HB
Endif
Endif
WaitMs 100

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

Goto get_count
 
Hi J,
These compile and program ok, but produce zero.
I had to add AZILB AZIHB because as you pointed out, it doesn't accept SPISEND = 1.
I'll try variations tomorrow.
MASTER:
_____________________________________________________________________
Dim azi As Word
Dim azilb As Byte
Dim azihb As Byte

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

'READ DATA from AZIMUTH (4431)

WaitMs 1000
SPISend azilb
WaitMs 100
SPIReceive azi.LB
WaitMs 100
SPISend azihb
WaitMs 100
SPIReceive azi.HB

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

Goto main '<<<<<<<<<<<<<<<<<<<<REMOVE<<<<<<<<<<<<<<<<<<<<
__________________________________________________________________________________
SLAVE:
Dim azi As Word
Dim azilb As Byte
Dim azihb As Byte
azilb = 1
azihb = 2


get_count:

azi.LB = 0 'azi.LB =...Not sure what goes here
azi.HB = 0 'azi.HB =...
While SSPBUF = 0
Wend
If SSPBUF = azilb Then
SSPBUF = azi.LB
Else
If SSPBUF = azihb Then
SSPBUF = azi.HB
Endif
Endif
WaitMs 100

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

Goto get_count
It produces zero because you write zero to SSPBUF, azi. lb =0
azi.hb=0
I meant that azi. lb, azi. hb are the values from QEI.
I just did not look what the variables are.
Spisend 1 works, but Spisend = 1 not.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top