Syncing SSPBUF in Oshonsoft.

Thread Starter

camerart

Joined Feb 25, 2013
3,831
I have watched for several years. Your programming definitely has. I just wish you could move away from Oshonsoft as it's too limiting for your requirements now. Even Swordfish is more forgiving
Hi I,
Thanks to you and others from forums etc, I've got this far.
If you only knew how difficult programming is for me, especially since adopting PROCEDURES. INCLUDES etc, which drive me nuts, but I now use them.
It's possible that the CODE I already have is ok, but I've just shortened the SPI STRINGS, so may have disturbed the program enough to spoil it.
EDIT: Vladimir's Oshonsoft including the SIM, has helped me immensely over the years, so I support his efforts. Also, I've tried changing a number of things, e,g, changing to Linux, (then back to Windows) and find it much easier to stay in my rut.
C
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,831
You were involved with the SPI thread that Eric Nigel and I were chipping away with on the SPI LCD over at ETO..
All was written in Oshonsoft.

As per your "transfers" you are using a second pic as the slave, yes? how are you organizing the data on device 2?
Hi I,
Yes, I have the ETO CODE, and am probably using similar.

PIC2 has a CS/SS around SSPBUF section.

A mate of mine, is 'tidying up' my CODEs, and he's using a more sophisticated routine, but I tend to accept it instead of undertsanding it.

In this case we are talking about GPS and QEI (Incremental encoder) sent to PIC1 via SPI
The GPS is saved as a STRING in a BUFFER, I have manually converted the GPS to S2M (SLAVE to MASTER) e,g, s2m(0) = gps(7) [being the first TIME CHAR. then added 2x QEIDEG BYTES to S2M.

EDIT: While posting this, I noticed a $ which is the first GPS BYTE, that I've removed, and may be the cause of this problem?
C.

---------------------------------------------
'-------------------- INIT SENTENCE BUFFER ------------------
'Sets up index and flags for next sentence. Overwrites
'old buffer data
'May be used by main (non-interrupt code) when PIR1.RCIE = 0

IRQinitBuf:
rxpsn = 0 'init index
buf_fill = 0 'stop filling until $
buf_done = 0 'not done filling buf
RXerr = 0 'no error

RCSTA.CREN = 1
RXIRQchar = RCREG
RXIRQchar = RCREG
PIE1.RCIE = 1
Return
--------------------------------------------

-----------------------------------------
''CHIP SELECT
Function SPI_RD_WR(rd_adr As Byte) As Byte 'SLAVE ONLY
SSPBUF = m2s(0)
While Not SSPSTAT.BF 'PIC
Wend
'While STATUS.3 'STATUS.3=0 When register ready. Must have this or WAIT ??<<<<<<<
'Wend
While Not SSPSTAT.BF 'PIC
Wend
s2m = SSPBUF
End Function
----------------------------------------
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Hi,
A bit of progress :)

Here's a section of CODE plus the result, terminal view.

It shows a £ at position 16, which should be position 0, but is at least consistent.
Now to correct it!

EDIT: While Not SSPSTAT.BF EDIT: 1 = Receive complete, SSPBUF is full

C
Code:
slave4431_cs = 0  'CS ON
WaitMs 10

    For spipsn = 0 To 34
        SSPBUF = 0  ' m2s  '(spipsn)
        While Not SSPSTAT.BF
        Wend
        If m2s(spipsn) = "£" Then Goto pound
    Next spipsn

    pound:
    For spipsn = 0 To 34  '49  'GPS=31 $-W INC QEI=2 BATVOLT=1 SPARE DATA=1<<£
        SSPBUF = m2s(spipsn)
        While Not SSPSTAT.BF EDIT:  1 = Receive complete, SSPBUF is full
        Wend
 
        s2m(spipsn) = SSPBUF  '£ ADDED
        Hserout "S2M(SPIPSN)  ", #spipsn, "  ", s2m(spipsn), CrLf  '£
    Next spipsn

    qeideg.LB = s2m (31)  '(46)<<<<<<<<<3'TEST with these 4x BYTEs OUT!!!£
    qeideg.HB = s2m (32)  '(47)<<<<<<<<£

    qeideg = qeideg / 4

    data1 = s2m(33)
    data2 = s2m(34)

slave4431_cs = 1  'CS OFF
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,831
camerart said:

Hi N,
The project I've been working on for years has a number of skills, that I have improved on, but sadly my programming skills haven't improved much.
C

I have watched for several years. Your programming definitely has. I just wish you could move away from Oshonsoft as it's too limiting for your requirements now. Even Swordfish is more forgiving
Hi,
Regarding my programming skills:
I'm still trying to figure out why the String buffer CHARs aren't in their correct positions!
I've had to adopt FUNCTIONS and PROCEDURES, that have been explained to me , but I find very uncomfortable.

In the programs here, there is one PROCEDURE with [BYREF] in it plus some VARIABLES, that make little sense to me, and could be the problem here. I've attached the explanation.
The chances of me ever being able to use this and understand what it's doing, is very slim, and I don't like stuff in my programs, that I don't understand, and why I haven't adopted Arduinos and their mystery libraries.

The image in #29 shows S2M(0) at 16, now it's at 10??
Anyway, I'm still
 

Attachments

Last edited:

nsaspook

Joined Aug 27, 2009
16,330
camerart said:

Hi N,
The project I've been working on for years has a number of skills, that I have improved on, but sadly my programming skills haven't improved much.
C


Hi,
Regarding my programming skills:
I'm still trying to figure out why the String buffer CHARs aren't in their correct positions!
I've had to adopt FUNCTIONS and PROCEDURES, that have been explained to me , but I find very uncomfortable.

In the programs here, there is one PROCEDURE with [BYREF] in it plus some VARIABLES, that make little sense to me, and could be the problem here. I've attached the explanation.
The chances of me ever being able to use this and understand what it's doing, is very slim, and I don't like stuff in my programs, that I don't understand, and why I haven't adopted Arduinos and their mystery libraries.

The image in #29 shows S2M(0) at 16, now it's at 10??
Anyway, I'm still
It's pretty simple with data transfer protocols to data buffers (arrays). You need to know what starts the beginning of the transfer (index 0) and when to end the transfer (index x). If you use standard length transfers, the end-point is easy to test as the buffer index for the next data transfer should increases per data transfer. The beginning of the transfer (set the array index to data index position zero) can be signaled in-band by a special data symbol(s) from the sending device or out-of-band by something like an external interrupt from the sensing device. After the transfer you can include data integrity bytes to check the transfer happened without error (the contents per byte are correct) even if the number of data transfers were correct.

Fundamental programming data structures shows how this is mapped into computer memory

1686132291005.png
1686132333158.png
The key to understanding programming is not CODE, it's understanding data structures and their manipulation due to events internal, external or programmatic.
If you want to improve your programming skills, study data structures.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,831
It's pretty simple with data transfer protocols to data buffers (arrays). You need to know what starts the beginning of the transfer (index 0) and when to end the transfer (index x). If you use standard length transfers, the end-point is easy to test as the buffer index for the next data transfer should increases per data transfer. The beginning of the transfer (set the array index to data index position zero) can be signaled in-band by a special data symbol(s) from the sending device or out-of-band by something like an external interrupt from the sensing device. After the transfer you can include data integrity bytes to check the transfer happened without error (the contents per byte are correct) even if the number of data transfers were correct.

Fundamental programming data structures shows how this is mapped into computer memory

View attachment 295942
View attachment 295943
The key to understanding programming is not CODE, it's understanding data structures and their manipulation due to events internal, external or programmatic.
If you want to improve your programming skills, study data structures.
Hi N,
I was 'talking' to a Ukranian girl here last week (I'm in the UK) and we couldn't string a sentence together between us, until she used her translate APP on her phone (Very clever)
In a similar way, you appear to be able to undertsand CODEs, DATA structures and protocols, where I don't, and after 40 years of programming still can't. I pick the odd bit up, and sometimes remember, but it's not natural for me, and I accept this.

Thanks for your efforts.

Regarding the problem I'm having, can you guess where the problem is most likely to be, so I can perhaps focus in on it?
C
 

Ian Rogers

Joined Dec 12, 2012
1,136
Hi C. I think your problem can be solved by placing your slave data in a specific location and each time the SPI calls send the data in one location.

I'll explain.

In oshonsoft you can set a variable to a specific location. Lets assume we use 0x70 and leave room for the whole string.

Dim nmea[50] As string @ 0x070
when you "ask" for a byte at location 7 in the string, 0x70 + 0x7 are added and that character is sent. Underlined below

NMEA sentence -- $CDDSC,12,3380400790,12,06,00,1423108312,2019, , , S, E *6A

This way the Master will know at what location specific data is.

So the master will ask for data at address 0xA and the slave sends the char at 0x7A ( 0x70 + 0xA) which is 3
Do you follow?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Hi C. I think your problem can be solved by placing your slave data in a specific location and each time the SPI calls send the data in one location.

I'll explain.

In oshonsoft you can set a variable to a specific location. Lets assume we use 0x70 and leave room for the whole string.

Dim nmea[50] As string @ 0x070
when you "ask" for a byte at location 7 in the string, 0x70 + 0x7 are added and that character is sent. Underlined below

NMEA sentence -- $CDDSC,12,3380400790,12,06,00,1423108312,2019, , , S, E *6A

This way the Master will know at what location specific data is.

So the master will ask for data at address 0xA and the slave sends the char at 0x7A ( 0x70 + 0xA) which is 3
Do you follow?
Hi I,
I do sort of follow, and it sounds like a good idea, I'll have to read it a few times.

Can the MASTER actually ask for DATA from a particular memory location via SPI?
This kind of rings a bell, as I'm sure previously SSPBUF had a memory address in it's routine, but it's vague.
C
 

Ian Rogers

Joined Dec 12, 2012
1,136
Can the MASTER actually ask for DATA from a particular memory location via SPI?

C
No.. The slave adds the incomming address to 0x70 and sends back that character
SPI:- Master send address.. slave sends garbage (lose dummy )
SPI:- Master send dummy.. slave sends data pointed to character required.
If you leave a bit of a gap between transmissions the slave will be able to GET the correct character and place it in the SSPBUF before the master sends the dummy..
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Hi I,
I can almost understand your suggestion now, and am trying to implement it.

This is what I have done previous to your suggestion:
SLAVE: The incoming GPS sentence is placed in [ GPS() ] and the SPI DATA from the GPS() sentence is 'kind of' PARSED out into [SPI() ] shown in the Screen shot.

I think your suggestion is similar, but misses out my GPS() to SPI() routine.

I'm guessing that your 0x70 address is an example.
When looking at this screen shot of memory, can you choose 3x memory addresses that I can use for SPI please?


C.
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Hi,
From the D/S, a BYTE address can be specified, but not a STRING!
------------------------------------------------------------
If necessary, variable address can be specified during declaration:
Dim x As Byte @ 0x050

It is possible to use one-dimensional arrays for Byte, Word, Long and Single variables. For example:
Dim x(10) As Byte
---------------------------------------------------
C.
 

Ian Rogers

Joined Dec 12, 2012
1,136
The location was just a suggestion... If you do this in "C" a = &gpsbuffer; this will stick the 1st address location of gpsbuffer int a, but I'm not sure how to do this in oshonsoft. It may be as easy as "SSPBUF = gpsbuffer[index]". I would have to test it.
I'm pretty sure you can assign the string variable to a specific location.

In fact Vladimir HAS given the ablility of string access
datasheet said:
For experienced users, it is worth noting that a string variable can actually be treated as a byte array, if needed.
For example:
string_var = "1234567"
string_var(3) = "a"
After the execution of this example, string_var variable will contain the string "123a567".
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
The location was just a suggestion... If you do this in "C" a = &gpsbuffer; this will stick the 1st address location of gpsbuffer int a, but I'm not sure how to do this in oshonsoft. It may be as easy as "SSPBUF = gpsbuffer[index]". I would have to test it.
I'm pretty sure you can assign the string variable to a specific location.

In fact Vladimir HAS given the ablility of string access
Hi I,
I've got working old CODE where speech marks are used, but that's a different style, and uses MSG1 which has the STRING "ABCD" in it.

Previously you mentioned giving time for the buffer to fill! There is a BIT that 'says' when it full, and is in my CODE.
--------------------------------------
While Not SSPSTAT.BF
Wend
------------------------------

I think the SLAVE is acting ok, and I can see it working in the SIM, as my image in #30, the error arises at SPI transfer.
C.
 

nsaspook

Joined Aug 27, 2009
16,330
Hi,
In previous replies, it was suggested that the SSPBUF rotated, until the 1st CHAR, which I tried, with the earlier error of not in SYNC.

Once I realised, that both SPI exchanged sentences 1st BYTEs are named 0, I have just got them to exchange ok, but very slowly.

I don't find this as easy as earlier suggested!
C
As long as it works, Its gold. :D
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Hi,
I can't understand, why if the 1st CHAR in the SLAVE BUFFER is £ and the 1st CHAR in MASTER BFFER is 1, and the SLAVE CS goes ON, then the SPI CLOCK starts, why doesn't the 1st step, show a £ appear in the MASTER and 1 arrive in the SLAVE, then the next CHARS in sequence of each BUFFER?
C
 

Ian Rogers

Joined Dec 12, 2012
1,136
C.. Explain to my why there should be a £ in the SSPBUF slave right from the get go. Do you preload the buffer before the master is ready? If you don't preload the slaves SSPBUF then it could be anything.

I'm a bit flumoxed with this as SPI is the most straight forward of the serial transmissions.

Explain what you are actually doing... I seem to see that a string in the master and a string in the slave are being exchanged.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
C.. Explain to my why there should be a £ in the SSPBUF slave right from the get go. Do you preload the buffer before the master is ready? If you don't preload the slaves SSPBUF then it could be anything.

I'm a bit flumoxed with this as SPI is the most straight forward of the serial transmissions.

Explain what you are actually doing... I seem to see that a string in the master and a string in the slave are being exchanged.
Hi I,
Your flumoxed!! :)
At the moment I'm reading the GPS with SLAVE, so from $ to W =44 CHARS
Temporarily, I PARSE the wanted BYTES:
------------------------------------------------------
s2m(0) = "£" '£ [TOT 35 BYTES ]
s2m(1) = gps(7) 'Time
s2m(2) = gps(8) 'Time
s2m(3) = gps(9) 'Time
s2m(4) = gps(10) 'Time
s2m(5) = gps(11) 'Time
s2m(6) = gps(12) 'Time
s2m(7) = gps(14) 'Time
s2m(8) = gps(15) 'Time
s2m(9) = gps(19) 'Lat
s2m(10) = gps(20) 'Lat
s2m(11) = gps(21) 'Lat
s2m(12) = gps(22) 'Lat
s2m(13) = gps(24) 'Lat
s2m(14) = gps(25) 'Lat
s2m(15) = gps(26) 'Lat
s2m(16) = gps(27) 'Lat
s2m(17) = gps(27) 'Lat
s2m(18) = gps(28) 'Lat
s2m(19) = gps(30) 'N
s2m(20) = gps(32) 'Lon
s2m(21) = gps(33) 'Lon
s2m(22) = gps(34) 'Lon
s2m(23) = gps(35) 'Lon
s2m(24) = gps(36) 'Lon
s2m(25) = gps(38) 'Lon
s2m(26) = gps(39) 'Lon
s2m(27) = gps(40) 'Lon
s2m(28) = gps(41) 'Lon
s2m(29) = gps(42) 'Lon
s2m(30) = gps(44) 'W
s2m(31) = POSCNTL 'QEIDEGLB
s2m(32) = POSCNTH 'QEIDEGHB
s2m(33) = 12 'Bat volt
s2m(34) = 123 'Spare DATA
-----------------------------------------------
Which includes 4x BYTES 31-34 for other things, so 35 BYTES, sitting in SLAVE BUFFER (updates off)

In the MASTER is M2S(0 to 34) = 35 BYTES in it's BUFFER, fixed at the moment.

In MASTER is a SEROUT showing each S2M BYTE received as a list Here:

C.
 

Attachments

Top