Adding BYTEs into a STRING Oshonsoft BASIC

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I'm sure I've done it before, but I'm trying to add BYTEs that I'm RECEIVING via SPI, and use them as a STRING.
Can someone give me an outline of how to do it, or point me to a routine in BASIC that show how please.
Cheers, Camerart
 

ericgibbs

Joined Jan 29, 2010
18,841
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
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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
Hi E,
Thanks, I'll give it a go.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi E,
I don't think this is quite right. This find 2x BYTEs HB and LB, but the CODE I'm looking for was writen by 'J' I think and catered for 3x BYTEs.
So if the number is '1' then it add 2x BYTEs before it e,g, '001'
If it increments over '9' then it produces this: '010' and so on.
I'll keep looking, unless what you have posted does work for this.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi,
I found the thread with the CODE written kindly by JohnInTX Here: https://forum.allaboutcircuits.com/...rams-with-interrupts-and-parse.168960/page-16

and here is the CODE:

Code:
'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
When this was written the messages from SLAVE to MASTER were via UART.
Now SPI is used, so possibly a version of E's CODE above mixed with the full CODE on the linked pages.

The message from SLAVE would look something like: e,g, $,123,321,W
which the MASTER would parse out into compass degrees, and QEI degrees.

This is mighty complicated for me, so I'll be staring at it for quite a while.:)
C.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,841
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
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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,
As the PARSE will count the digits, does your method keep the same digit count? e,g, 001 010 100.
C
 

ericgibbs

Joined Jan 29, 2010
18,841
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
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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,
Yes, this is what's needed. thanks.

The main question now, is The FULL main CODE has $STRINGs which are PARSED out, and also have GUARD TIMERS, to stop them blocking in case of erronious messages, so the FULL CODE is needed, and as you know it is long.
Where do I start on changing the UART method of SLAVE to MASTER and the SPI method?
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,841
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
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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,
You make it seems easy. Perhaps this headache is caused by over thinking ;)
Let's see how I get on.
C
 

ericgibbs

Joined Jan 29, 2010
18,841
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.!:oops:

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.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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.!:oops:

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,
"Problem is when you post the full program code text listing it makes my eyes glaze over.! "I know what you mean, mine have glazed so much, they're pretty well laminated:)

Ok, I've probably done it before, but I'll get the 2x PICs to talk SPI, in smaller CODEs and show each sentence in the MASTER terminal.
Good plan.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
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
Hi E,
Your CODEs are much appreciated, but if you don't mind, I would like to try a recent program, that I'm more familiar with first. If I get into difficulties, then of course I'll use yours and proceed from there.

As I'm not able to attach TXT or insert CODE, Are you able to open the CODE I'm talking about, as a DOC file?
I will also make CODE for the SLAVE to exchange messages.
C.
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi E,
Here's the first test, with #16 CODE, NOTE: the SLAVE still has 'ABCD' in it's buffer, till it starts returning the SENT characters.
I see lots of corrections, but it does look like a good start.

NOTE: Just spotted the 'must be included' line in your CODE
C
 

Attachments

Last edited:
Top