MASTER and SLAVE PICs using SPI in Oshonsoft

ericgibbs

Joined Jan 29, 2010
21,463
However, I think it will break when used live for RC control, because of latency. I may be wrong??
hi C,
As always, write a short debug program to check the functions that your main program will use, before adding the code to the main program.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
As always, write a short debug program to check the functions that your main program will use, before adding the code to the main program.
E
Hi E,
I have a friend helping me, and I delivered his latest PCB yesterday. As you may recall I struggle with programming, so while I mess about getting things to work, he verifies them. Let's see what he comes up with :)Next I've got to integrate what you did yesterday, into the full program, and test it works.
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
Here is the first test of a modified version, live on the PIC, with terminal view.
I assume the oddness is similar to the ASCII thing yesterday?

EDIT: I lowered the BAUD rate to 4800, and here's the result
:)
Just noticed duplicate: [ Define SEROUT_DELAYUS ]
C
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
I'm working through problems with the TEST MASTER/SLAVE program.
I found that on the 18F46K20 the program wouldn't SEROUT and flash LEDS.
1/ Earlier I had to turn down the UART to 4800 Baud, but today depending on the settings, it now only works with 9600 Baud.

2/ I got the SEROUT and the LEDS to work by setting TRISD to %00010000. Why does it need PORTD.4 to be 1?

C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi,
Do understand the TRIS command.?

To drive an LED, the pin has to set as an OUTPUT.
E
Hi E,
The LED is PORTE.2.
At the moment PORTD isn't connected to anything.

This is a simple TEST program, with SPI on PORTC
And the LED

C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
Things have moved on since this #406!

For anyone following, I'm working on REMOTE/SLAVE.
We had 18F46K20 as MASTER and 18F4431 as SLAVE, with SPI running ok.

Since then there have been lots of changes, but the SLAVE now reads and parses a GPS module, and will be driving the MOTOR/SERVO outlets.
My question is: When a slave is not being 'called' by the master (for SPI), does it keep running on the other things?
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
This thread was started 4 years ago, and I've just tried to read as much as I can to see why I still can't get SPI between 2x PICs to work accurately, and according to some, it's quite simple.

I've got SPI 'talking' to other peripherals, but never PIC to PIC.

I can only apologies for all of the effort you have all made.
Cheers, Camerart
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi E,
If you recall, we did this working SPI to SPI link, back in 2019.
E
Hi E,
Yes, I do recall. In fact I posted the link to that section of the thread this morning.
However, that uses "MESSAGE" type strings (successfully), where here the DATA to be exchanged has BEEN PARSED from various sources, GPS etc, into a memory buffer, of 35 BYTES. This morning I asked if your method could be used instead of the buffer.

It appears that the buffer method, needs to sync between the 2x PICs.
Here is an example of a '1' in MASTER and '£' in SLAVE, so they should exchange 1x35 times and £x35 times.. You can see '1's being returned before the £ (163 or A3).
Then more '1' exchanges later. It should simply exchange 35 BYTES within each C/S.
also note a couple of '209' errors in the £ list.
EDITED
C
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi E,
If you recall, we did this working SPI to SPI link, back in 2019.
E
Hi E,
The method you posted in 2019, used a "STRING" where each BYTE was exchanged with a BYTE from the SLAVE, successfully.

If I'm correct I couldn't easily use this method, as the ARRAY of BYTEs needed to be PARSED from other STRINGS and DATA.

This is the method, I'm trying now, and it's working.
I hope you approve.

C.
Code:
------------------------ MASTER -----------------------------------------------------
m2s(0) = 0 '0=DUMMY +35 BYTES =36 BYTES
m2s(1) = 1 '=X for M2S tests.
m2s(2) = 2
m2s(3) = 3
m2s(4) = 4
m2s(5) = 5
m2s(6) = 6
m2s(7) = 7
m2s(8) = 8
m2s(9) = 9
m2s(10) = 10
m2s(11) = 11
m2s(12) = 12
m2s(13) = 13
m2s(14) = 14
m2s(15) = 15
m2s(16) = 16
m2s(17) = 17
m2s(18) = 18
m2s(19) = 19
m2s(20) = 20
m2s(21) = 21
m2s(22) = 22
m2s(23) = 23
m2s(24) = 24
m2s(25) = 25
m2s(26) = 26
m2s(27) = 27
m2s(28) = 28
m2s(29) = 29
m2s(30) = 30
m2s(31) = 31
m2s(32) = 32
m2s(33) = 33
m2s(34) = 34
m2s(35) = 35


slave4431_cs = 0 'CS ON

While Not s2m_ack
Wend

For spipsn = 0 To 35 'spipsn To 35 '=36 BYTES including 1x DUMMY BYTE 'GPS=31 $-W INC QEI=2 BATVOLT=1 SPARE DATA=1<<£
SSPBUF = m2s(spipsn) '(spipsn)
While Not SSPSTAT.BF
Wend
s2m(spipsn) = SSPBUF '(spipsn) = SSPBUF '£ ADDED
WaitMs 1
Next spipsn

slave4431_cs = 1 'CS OFF
-------------------------------------------------------------------------
S2M has been PARSED from a GPS buffer +QEI readings +2xBYTES
---------------------------- SLAVE -----------------------------------------------
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

If slave4431_cs = 0 Then 'if chip select on do the code otherwise skip

s2m_ack = 1 'Tell MASTER that SLAVE is ready.

For spipsn = 0 To 34 'GPS=30 $-W INC, QEI=2 BATVOLT=1 SPARE DATA=1
m2s(spipsn) = SSPBUF '(spipsn) = SSPBUF 'M2S
While Not SSPSTAT.BF
Wend
SSPBUF = s2m(spipsn) '(spipsn)
Next spipsn

s2m_ack = 0 'Set S2M_ack off till next loop

Endif 'slave4431_cs
----------------------------------------------------------------------------------------
 
Top