Proc spi_rd_pt()
pz = 10
ss = 0
WaitUs pz
SSPBUF = mastout.HB
While Not SSPSTAT.BF
Wend
slavinp.HB = SSPBUF
WaitUs pz
SSPBUF = mastout.LB
While Not SSPSTAT.BF
Wend
slavinp.LB = SSPBUF
WaitUs pz
ss = 1
Hserout "From Slave Azi=", #slavinp, CrLf 'test only
SSPBUF = 0
End Proc
Hi E,hi C,
This file has SPI recv sub.
E
Code:Proc spi_rd_pt() pz = 10 ss = 0 WaitUs pz SSPBUF = mastout.HB While Not SSPSTAT.BF Wend slavinp.HB = SSPBUF WaitUs pz SSPBUF = mastout.LB While Not SSPSTAT.BF Wend slavinp.LB = SSPBUF WaitUs pz ss = 1 Hserout "From Slave Azi=", #slavinp, CrLf 'test only SSPBUF = 0 End Proc
'ShowDegrees: Types out 3 digits of passed value in a 3 character field with leading zeros
Proc ShowDegrees(value As Word)
If value < 100 Then 'needs at least one leading zero
Hserout "0"
Endif
If value < 10 Then 'needs another leading zero
Hserout "0"
Endif
If value < 360 Then
Hserout #value, CrLf 'will type 1,2,or 3 remaining digits of 0 <= value <= 359 degrees
Else
Hserout "---", CrLf 'will type out --- as an error message
Endif
Return
End Proc
Dim gps As String
Dim compass As String
main:
'for generating test code ONLY
gps = "12"
'this line is the Code that does the work
gps = RightStr("000" + gps, 3)
'So assume your gps SPI value was '27'
'add "000" to the leftside so that would be '00027'
'then select the right side 3 characters ie: '027'
Hserout gps, " ",
'for generating test code ONLY
compass = "1"
'this line is the Code that does the work
compass = RightStr("000" + compass, 3)
'So assume your Compass SPI value was '27'
'add "000" to the leftside so that would be '00027'
'then select the right side 3 characters ie: '027'
Hserout compass, CrLf
Goto main
Hi E,hi C,
The way I do it is this way, simple and short, shows two examples in the Code clip.
Code:Dim gps As String Dim compass As String main: 'for generating test code ONLY gps = "12" 'this line is the Code that does the work gps = RightStr("000" + gps, 3) 'So assume your gps SPI value was '27' 'add "000" to the leftside so that would be '00027' 'then select the right side 3 characters ie: '027' Hserout gps, " ", 'for generating test code ONLY compass = "1" 'this line is the Code that does the work compass = RightStr("000" + compass, 3) 'So assume your Compass SPI value was '27' 'add "000" to the leftside so that would be '00027' 'then select the right side 3 characters ie: '027' Hserout compass, CrLf Goto main
Hi E,hi,
As you Read each 'gps' char from the SPI receive, you 'build' the 'gps' data String.
then use
gps = RightStr("000" + gps, 3)
So if if you only received 2 data bytes, "1" and "2" , the input String to the above Code line would be "12".
the Output would be "012"
Is this what you are asking.
E
Hi E,hi C,
Over the past 8 years we have covered this topic many times, with working Master and Slave programs using SPI communication protocols.
You should have enough programs and information on file, just to Copy and Paste these subroutines.
E
Hi E,hi C,
As I have said before 'bite sized chunks'.
If you have a Coding problem, write a short program on the topic in question, so that you get all the bugs out.
Problem is when you post the full program code text listing it makes my eyes glaze over.!
I have to try to visualise your hardware setup , what peripherals you have connected, what is the format the data etc....
E
So write a short program which uses dummy test data Inputs and the Outputs the data you expect, then post the program so that I can run it.
Hi E,hi,
I have placed all the setup code in an include file.
Put these two Basic files in the same Folder. [delete the .txt extension]
Use the debug style basic for your debugging work.
E