MASTER and SLAVE PICs using SPI in Oshonsoft

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi,
Looks promising, the Slave to Master should also be ok.
E

Update:
As you may have noticed, at start up msg1 from M to S is 1234 and the S to M is ABCD

As they receive that msg, they swap over and send back what they received and so on,
Hi E,
I removed the last post smiley, as I thought the PICs were exchanging, but now find it was MASTER's two different MSG1s.

Just going to add the missing SLAVE to MASTER SS wire.
C
 

ericgibbs

Joined Jan 29, 2010
21,462
hi C,
Are you sure about that.??
As I said, the Master has only one msg1 at the start of the run ie: ABCD and the Slave has only one msg1 at the start of the run, so the Master and Slave must be swapping msgs, else you would not get the output you posted

master............ Slave
ABCD..............1234
1234.................ABCD
ABCD...............1234
1234..................ABCD

Alternating

E
 

jjw

Joined Dec 24, 2013
823
Hi E,
I removed the last post smiley, as I thought the PICs were exchanging, but now find it was MASTER's two different MSG1s.

Just going to add the missing SLAVE to MASTER SS wire.
C
Look at the analyser MISO signal.
It is the data coming from the Slave.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
Are you sure about that.??
As I said, the Master has only one msg1 at the start of the run ie: ABCD and the Slave has only one msg1 at the start of the run, so the Master and Slave must be swapping msgs, else you would not get the output you posted

master............ Slave
ABCD..............1234
1234.................ABCD
ABCD...............1234
1234..................ABCD

Alternating

E
Hi E,
No I'm not
Just checking both SS.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi E and J,
How I see it:
There are two MSG1s in MASTER 4620:
___________________________________________________________
msg1 = "1234" + Cr + Lf
msg2 = "ERIC" + Cr + Lf
___________________________________________________
which show on the #339 image as being sent from MASTER
I would hope to see:
_____________________________________________
master............ Slave
ABCD..............1234
1234.................ABCD
ABCD...............1234
1234..................ABCD
_____________________________________________
MASTER
NOTE: Previously I cut the RA5 (SS) track to add [ AN4 ] as a POT INPUT and swapped it with RA4.
I'm just about to re-connect it, and move the POT to another PIN.
This would account for the analyser showing movement on the MISO track but not SSing, so not receiving into MASTER.
(I'll need to double check all this, but results later.)
C
 

ericgibbs

Joined Jan 29, 2010
21,462
hi C,
I can see that my poor description of the msg strings could have caused you some confusion.

I would suggest you keep the M and S files I posted as a reference, make a Copy and modify the copy to suit your tests.
You could easily delete the second SPI send in both M and S, so it will make the results easier to follow.

Could you post a sample of the SPI data that the Master will be sending to the Slave in the actual project.? and at what intervals you expect to send it.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
I can see that my poor description of the msg strings could have caused you some confusion.

I would suggest you keep the M and S files I posted as a reference, make a Copy and modify the copy to suit your tests.
You could easily delete the second SPI send in both M and S, so it will make the results easier to follow.

Could you post a sample of the SPI data that the Master will be sending to the Slave in the actual project.? and at what intervals you expect to send it.

E
Hi E,
I do keep your initial programs separate from mine. I also date and time mine, and if there is a good result put them in a separate folder

Will you comment on my NOTE in #345 regarding my cut track. Will it work without the SS INPUT to MASTER?

EDIT: Does each SS need a separate track?
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
21,462
hi,
The Slave does not input the SS signal to the Master, the Master controls the SS line output and the Slave reads it as an Input.
When the Master sets the SS line Low, the Slave reads it and it should be ready to exchange data as the Master sends it.

The HW SS pin on the Master is designated as PORTA.5 and on the Slave as PORTC.5 [18F2431] .... for the 18F4431 PORTC.6

E

BTW: have you tested the set up using the Test programs I posted.
 

Attachments

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi,
The Slave does not input the SS signal to the Master, the Master controls the SS line output and the Slave reads it as an Input.
When the Master sets the SS line Low, the Slave reads it and it should be ready to exchange data as the Master sends it.

The HW SS pin on the Master is designated as PORTA.5 and on the Slave as PORTC.5 [18F2431] .... for the 18F4431 PORTC.6

E

BTW: have you tested the set up using the Test programs I posted.
Hi E,
Here's the results from this morning::) (Smiley back in)

Correct me if I'm wrong:
From previous questions, CS can be a variable or a parallel port routine, but not SPI.
SS (SPI SLAVE Select) is an INPUT to the SLAVE whichever PIC it is.
SS OUTPUT can be any OUTPUT PIN on the MASTER.

As my settings are for my PCB, posting my programs may confuse others, as your programs are fine. I'll post mine if asked.

Excellent stuff, thanks again for setting up your PICs and efforts to answer my question.
Cheers, C.
 

Attachments

ericgibbs

Joined Jan 29, 2010
21,462
hi C,
Don't follow your question ref 'CS'.?

With ref to SPI, look at this clip from the 18F4431 d/s showing that the SPI HW uses dedicated PORT pins.

The Oshonsoft SW SPI uses bit switching [ much slower] so any pins can be assigned for SPI.

E

Info Added to image.
SSPSTAT.SMP = 0 'sample a mid data
SSPSTAT.CKE = 1
SSPSTAT.5 = 0 'I2C only
SSPSTAT.4 = 0 'I2C only
SSPSTAT.3 = 0 'I2C only
SSPSTAT.2 = 0 'I2C only
SSPSTAT.1 = 0 'I2C only
SSPSTAT.BF = 0 'If SSPBUF=1=Full

 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
21,462
hi C,
As I understand the previous block diagram , the Master just talks to the Slave,is it sending servo data.? [only Null data is sent back from the Slave to Master]
If yes, what is the format of the data and its refresh rate.?

If I know what that data is, I can adjust the Master/Slave tests to something more useful.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
hi C,
Don't follow your question ref 'CS'.?

With ref to SPI, look at this clip from the 18F4431 d/s showing that the SPI HW uses dedicated PORT pins.

The Oshonsoft SW SPI uses bit switching [ much slower] so any pins can be assigned for SPI.

E
Morning E,
The CS sentence was from a question a long time ago, where I didn't know the difference between CS and SS. Just clarifying, for any others.

To clarify all of my programs have this:
_____________________________________________________________________
'SPI
''Define SPI_CS_REG = PORTD [USED WHEN IN SLAVE MODE]
''Define SPI_CS_BIT = 4[USED WHEN IN SLAVE MODE]
Define SPI_SCK_REG = PORTC
Define SPI_SCK_BIT = 3
Define SPI_SDI_REG = PORTC
Define SPI_SDI_BIT = 4
Define SPI_SDO_REG = PORTC
Define SPI_SDO_BIT = 5
SPIPrepare
____________________________________________________________
which is Oshonsoft SPI software, not used in these programs. (I did wonder)

Am I correct that the HW SPI method can be used for any SPI chip, such as the compass peripheral instead of the OSH method above?
C
hi C,
As I understand the previous block diagram , the Master just talks to the Slave,is it sending servo data.? [only Null data is sent back from the Slave to Master]
If yes, what is the format of the data and its refresh rate.?

If I know what that data is, I can adjust the Master/Slave tests to something more useful.

E
Hi E,
Ok.
I don't know about refresh rate.
As you have answered this thread question, I'll go back to the main thread and post my programs there, as I build them.
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
The defines are for the sw SPI.
Remove them.
They may interact with the hw SPI, which you are using now.
Hi J,
I've edited a clarification in my reply #352 (Although the post id a bit complicated) as this this question, which you have now answered.
Thanks, C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
Update on the 18F4620/18F4431 PCB programming.

I've almost converted the previous SWSPI program to HWSPI (Altimeter and Compass) I've also switched the GPS, POTS back on, so I now have them all showing in a terminal. There is something wrong with the compass, but there's a lot of setting etc, which I'll look into later. I'll also leave the screen till later.

Next the SLAVE 18F4431, which READs the QEI from the INCREMENTAL ENCODER.
I'm just looking through this thread and my saved programs relating to this, which is a bit complicated. Then I'll add them into the MAIN program.

For anyone who wants a bit of light reading, here's the program:eek::
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
While working on the SWSPI to HWSPI MAIN program in #355, I lost track of the MASTER/SLAVE programs. After working through the programs the first time, I failed to post them here, so I had to start again from #318:oops:
Here are today's new programs, which aren't working. If anyone would like to skim through them for obvious mistakes please?

EDIT: Much later I've learnt, that as this PIC is old, for accurate timing, it needs a CRYSTAL.
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
------------------------------------------------------------------------S--o--m--e----t--i--m--e-------l--a--t--e--r------------:)

I now know how SW and HW works! I've removed all Osh SPI, and set the INs and OUTs, according to the tracks on the PCB, and made an SPI connection cable between the two PICs.

I'll re-check all of the previous posts, to find out whether each program can be simulated, or needs to be 'live', but a quick answer would be welcome.

EDIT: I've just found #275, which answer my 'above' question. No probs, back to the PCB
C.
 
Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
Still trying to get SPI HW to work!
The above programs work and transfer the set-up messages ok, but there seems to be something wrong somewhere.

With a 18LF4620 MASTER connected to an 18F4431 SLAVE via SPI, wth other peripherals on the same SPI bus. Is it possible for the 4620 to be always MASTER, and for the 4431 to READ the data from one of the peripherals? It appears to me that the 4431 will be SLAVE sometimes and MASTER to its peripheral sometimes.
Can someone clarify this please?
C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
After a break, I'm having another go!

After many tries, I'm getting repeated results: I can program the two PICs, and they work. They output READings as previously seen, where the DATA messages are being swapped and shown on a terminal and on the Logic analyser.

I switch off and back on again, and all the messages are gobbledegook. It takes a routine of programming to repeat this test, but it does repeat, and the same thing happens.

I've been re-reading previous posts, and if I'm making an error, the answer may be in the above posts, so I'll keep trying, to find the error.
C
 

Thread Starter

camerart

Joined Feb 25, 2013
3,842
Hi,
Intermittent faults are always difficult to find, but I may have found this one:)

It appears that some the SPI lines don't always give the correct voltage, and only output approx 1V instead of 3.3V

I've come across this before, with the Compass peripherals, and added voltage boosters. Perhaps I'll try with this problem.

I'll keep checking, C.
 
Top