Syncing SSPBUF in Oshonsoft.

Thread Starter

camerart

Joined Feb 25, 2013
3,831
That was my worry... But it matters not. Say you send send "0x0" from the master, you can send send "S2M(0)" on the next run.

Master sends 0x0 receives dummy.
Master sends 0x1 receives S2M(0).
Master sends 0x2 receives S2M(1).
.
.
Master sends 0x23 receives S2M(0x22)... Done.

so use the address to send the correct array element.
Hi I,
I'm off to my mates soon, where we can try this.
Thanks.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Hi,
Here's a Data analyser shot, showing the S2M (SLAVE to MASTER) array in the SLAVE, starting with '£', which is stored at 0x20, as seen in the Watch variables.
The BYTE sequence sent from the MASTER starting at 0x20, can be seen in the Decoded protocols.
The 1st CHAR is a '£', but doesn't turn up till near the end of the C/S, and seems random. This is the same as weeks ago! Not consistent!

NOTE: There is more than one DATA STRING in the SLAVE, so S2M must be selected in some way.
C
 

Attachments

Last edited:

Ian Rogers

Joined Dec 12, 2012
1,136
First of all. why does it start at 0x20 when you told me the array is only 35 long surely you need to start at 0. 0x21 is 32 decimal.

The watch window on the left... Is that the slave or the master?.. Are you sending to the slave or reading?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
First of all. why does it start at 0x20 when you told me the array is only 35 long surely you need to start at 0. 0x21 is 32 decimal.

The watch window on the left... Is that the slave or the master?.. Are you sending to the slave or reading?
Hi I,
The watch window on the left is from the OSH SIM and shows where the SLAVE DATA ARRAYs are stored.
I've changed the image in #62 to clarify (I hope)
It starts at 0x20, because that's where the configuration placed if (If I understand correctly)
The Data analyser is set to show ASCII and HEX as seen on the right, starting at 0x20 and the next 0x20 is just below the screen after 35xBYTES.
The D/A is showing the 4x lines of the SPI and each line can be read at the left, C/S, Clock, MOSI and MISO, I can't zoom in, or it would be each side of the room long.
The 0X20 +34 array is sent from the MASTER to READ the SLAVE. I've used simlar to the other Peripherals n the CODE.
C.
 
Last edited:

Ian Rogers

Joined Dec 12, 2012
1,136
Like I said. If you are not using fixed location, then the 1st character will be "S2M(0)" so the master should request address 0 to get the address the slave should respond with
SPISend( S2M(index)) where index is the address of the character in the string.

I feel like I've messed up your though process with the fixed location.

here is a sudo code I would use.
Master
Code:
dim instring(10)

wait until slave is stable...
SPISend(0)
for idx = 0 to 10
   instring(idx)=  SPISend(idx+1)
next
Slave
Code:
dim S2M(10)
clear serial  flag.
when the first character is received.. ( serial flag)
'idx should be 0'
for idx = 0 to 10
   SPISend(S2M(idx))
next
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Like I said. If you are not using fixed location, then the 1st character will be "S2M(0)" so the master should request address 0 to get the address the slave should respond with
SPISend( S2M(index)) where index is the address of the character in the string.

I feel like I've messed up your though process with the fixed location.

here is a sudo code I would use.
MasterMaster
Code:
dim instring(10)

for idx = 0 to 10
   SPISend(idx)

next
Hi I,
If I put my thought process into AI, it would break it ;)

Can you clarify, that this won't READ the other DATA STRINGS in the SLAVE, if you don't 'aim' at S2M? If you look at the 'watch variable window in the image you will see the GPS STRING above the S2M STRING.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Sorry The text was updated before I finished writing.. Please re read.
Hi I,
I'm sure that in tests, I have used that method.
If you look at this MASTER example, I go through each line and try differnt things as suggested over the past weeks, and even years, and have never got it to SYNC, so the MASTER receives the '0' BYTE at the correct time.
I've tried no ADDDR, with only COUNT
------------------------------------------------
adddr = 0x20
For spipsn = 0 To 34 'spipsn To 34 '49 'GPS=31 $-W INC QEI=2 BATVOLT=1 SPARE DATA=1<<£
SSPBUF = adddr
While Not SSPSTAT.BF
Wend
s2m(spipsn) = SSPBUF
adddr = adddr + 1
Next spipsn

(Inside a C/S)
----------------------------------------------------------------
I'll re-try!
There may be gaps in my replies!
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
Hi,
In the same MASTER CODE is a Compass READ, which lookslike this:
----------------------------------------------
wr_adr = 0x0a
compss_cs = 0 'COMPASS ON
WaitUs 1
SSPBUF = wr_adr
While Not SSPSTAT.BF
Wend
WaitUs 1
SSPBUF = wr_byte
While Not SSPSTAT.BF
Wend

While drdy_pin 'AK8963C DRDY PIN
Wend

compss_cs = 1 'COMPASS OFF
----------------------------------------
I've tried copying this, but of course, I can't see what's inside the Compass chip (SLAVE peripheral) This works fine.
So most likely it's the SLAVE we have to concentrate on.
C
 

jjw

Joined Dec 24, 2013
823
Hi,
In the same MASTER CODE is a Compass READ, which lookslike this:
----------------------------------------------
wr_adr = 0x0a
compss_cs = 0 'COMPASS ON
WaitUs 1
SSPBUF = wr_adr
While Not SSPSTAT.BF
Wend
WaitUs 1
SSPBUF = wr_byte
While Not SSPSTAT.BF
Wend

While drdy_pin 'AK8963C DRDY PIN
Wend

compss_cs = 1 'COMPASS OFF
----------------------------------------
I've tried copying this, but of course, I can't see what's inside the Compass chip (SLAVE peripheral) This works fine.
So most likely it's the SLAVE we have to concentrate on.
C
What does your PIC-Slave program do, when it gets a byte ( address) from the PIC-Master?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
What does your PIC-Slave program do, when it gets a byte ( address) from the PIC-Master?
Hi J,
The SLAVE is supposed to receive a BYTE from MASTER and exchange it with one from the relevant Buffer, in this case S2M (SLAVE to MASTER)
So apart from 1x dummy BYTE, MASTER sends the 1st BYTE in M2S(BUFFER), and should exchange it with the 1st BYTE of S2M(BUFFER).
As mentioned I've tried lots of iterations over the months, and while MASTER receives the BYTES, they're not in sync.
C.
 

jjw

Joined Dec 24, 2013
823
The master program should have some delay after each index for the slave to read it and to write the next s2m( index) Into SSPBUF
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
The master program should have some delay after each index for the slave to read it and to write the next s2m( index) Into SSPBUF
Hi J,
In the #70 example a delay can be seen:
--------------------------------------
While Not SSPSTAT.BF (1 = Receive complete, SSPBUF is full)
Wend
--------------------------------------
Is this what you mean?
C
 

jjw

Joined Dec 24, 2013
823
Hi J,
In the #70 example a delay can be seen:
--------------------------------------
While Not SSPSTAT.BF (1 = Receive complete, SSPBUF is full)
Wend
--------------------------------------
Is this what you mean?
C
No.
After that, before sending the next byte.
 

jjw

Joined Dec 24, 2013
823
Hi J,
Do you mean like this:
1xBYTE READ and WRITE?
C
I mean, when the master has sent a byte, the slave needs some time to read the byte and write a new byte ( s2mmsg(index)) into SSPBUF.
This takes about 2us with 32Mhz clock if the program is constantly polling the SPI flag.

If the program in PIC with the slave SPI is doing other things, how does it know when a new byte arrives to SPI?
 

Thread Starter

camerart

Joined Feb 25, 2013
3,831
I mean, when the master has sent a byte, the slave needs some time to read the byte and write a new byte ( s2mmsg(index)) into SSPBUF.
This takes about 2us with 32Mhz clock if the program is constantly polling the SPI flag.

If the program in PIC with the slave SPI is doing other things, how does it know when a new byte arrives to SPI?
Hi J,
I mean, when the master has sent a byte, the slave needs some time to read the byte and write a new byte ( s2mmsg(index)) into SSPBUF.
This takes about 2us with 32Mhz clock if the program is constantly polling the SPI flag.

If the program in PIC with the slave SPI is doing other things, how does it know when a new byte arrives to SPI?
Hi J,
There is a [
[ While Not SSPSTAT.BF (1 = Receive complete, SSPBUF is full)
Wend ]
also in the SLAVE.
C
 
Top