MASTER and SLAVE PICs using SPI in Oshonsoft

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
Set up two 18F4620 PIC's as Master and Slave, using internal 8MHz clock, I am able to exchange data between the two PIC, but for some reason the UART signals are corrupted.
I suspect the UART is trying to use some internal hardware of the PICs that the SPI is using.
As you know the Oshonsoft compiler uses bit switching for SPI control, not the HW SPI.

Been on the problem most of the day, may have another session tomorrow.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Set up two 18F4620 PIC's as Master and Slave, using internal 8MHz clock, I am able to exchange data between the two PIC, but for some reason the UART signals are corrupted.
I suspect the UART is trying to use some internal hardware of the PICs that the SPI is using.
As you know the Oshonsoft compiler uses bit switching for SPI control, not the HW SPI.

Been on the problem most of the day, may have another session tomorrow.

E
Hi E,
1/
As I don't really know how Oshonsoft does SPI, or indeed, the meaning of HW (I almost know, but it doesn't register)
Are you using:
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

---------------------------------------------------------------------------------------------------------------
2/
It's good to know that you're moving DATA between two PICs, are you using SPI, not UART?
In my case the UART is not needed on the SLAVE
-----------------------------------------------------------------------------------------------------------------
3/ I'm trying to test my PCBs using [ SLAVE BIT ON = MASTER BIT ON for each TRACK of SPI. ] then HSEROUT different numbers, for each TRACK.
So far I'm getting odd results, but I think that programming errors. I've been out all day, and having a quick go till

C.
 

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
Rem your Thread Title, Master <> Slave SPI,:rolleyes:
That was the content of my last post, I can transfer data to and from PIC Master to Slave, using the set up I explained.
BUT, I know your project does use the PIC UART, so I tried testing the UART with SPI running, initial results show the UART data is corrupted.
I will try to determine the cause, if I get time later today.

I thought you knew that HW and SW are the shortened way of saying HardWare and SoftWare.
HW components refer to the physical modules within the MCU, ie: A HW SPI setup uses the inbuilt modules, SW SPI requires software/program Bit switching and Timing.
E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Rem your Thread Title, Master <> Slave SPI,:rolleyes:
That was the content of my last post, I can transfer data to and from PIC Master to Slave, using the set up I explained.
BUT, I know your project does use the PIC UART, so I tried testing the UART with SPI running, initial results show the UART data is corrupted.
I will try to determine the cause, if I get time later today.

I thought you knew that HW and SW are the shortened way of saying HardWare and SoftWare.
HW components refer to the physical modules within the MCU, ie: A HW SPI setup uses the inbuilt modules, SW SPI requires software/program Bit switching and Timing.
E
Hi E,
I know that software is programming, and hardware are components, but when it comes to PIC HW /SW/BITBANGING, I get mixed up. Thanks for the explanation.

I want to make sure that if we get the SPI MASTER/SLAVE/ working, it will be compatible with this type of CODE:
SPICSOn
For i = 0 To 5 'READ XYZ Xx2 Yx2 Zx2
compss = 0 'CHIP SELECT COMPASS ON
addr = 0x83 + i
SPISend addr
SPIReceive data
b(i) = data
compss = 1 'CHIP SELECT COMPASS OFF
Next i
SPICSOff

-------------------------------------------------------------------------------------------------------
On the PCB I'm checking, I've found 2x HIGH PINS. 1x is the SCK, the other is the C/S which has a pull-up resistor, which I'm about to remove. I can't see why the SCK is HIGH, nothing is connected, and the adjacent PINS are LOW.

EDIT: To clarify my tests! I have 2x minimal test programs.
I removed the pull-up resistor, set both PICs to OUTPUT all [ 0 ] and now all the relevant PINS show low.
(Off outside to build a brick gate post.)
C
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
All I intend doing at the first stage is get reliable SPI data exchange between the Master and Slave MCU's, using the HW SPI, with Oshonsoft Basic coding, also hopefully fix the UART corruption.

There is no point in asking will it work with that code snippet you posted, that is not the problem we are trying to solve.
I am not using SW SPI Bit switching in my tests.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
All I intend doing at the first stage is get reliable SPI data exchange between the Master and Slave MCU's, using the HW SPI, with Oshonsoft Basic coding, also hopefully fix the UART corruption.

There is no point in asking will it work with that code snippet you posted, that is not the problem we are trying to solve.
I am not using SW SPI Bit switching in my tests.

E
Hi E,
(I've just EDITED my last post)

1/ Only the 18F4620 MASTER uses UART in the TRANSMITTER. The 19F4431 SLAVE uses the same PIN for HSEROUT/UART and TX, so no UART needed here.

I think that from what I now understand it will all be compatible, as they both use HW SPI :)
C
 

ericgibbs

Joined Jan 29, 2010
18,872
1/ Only the 18F4620 MASTER uses UART in the TRANSMITTER. The 19F4431 SLAVE uses the same PIN for HSEROUT/UART and TX, so no UART needed here.
I think that from what I now understand it will all be compatible, as they both use HW SPI

Hi C,
You are missing my point.:)
The UART appears not to be usable in the 18F4620 when HW SPI is being used... I am working on a solution.

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
1/ Only the 18F4620 MASTER uses UART in the TRANSMITTER. The 19F4431 SLAVE uses the same PIN for HSEROUT/UART and TX, so no UART needed here.
I think that from what I now understand it will all be compatible, as they both use HW SPI

Hi C,
You are missing my point.:)
The UART appears not to be usable in the 18F4620 when HW SPI is being used... I am working on a solution.

E
Hi E,
Ok.

The UART been working for me ok, in 18F460, also in the 18F4431, but I had to cheat, by using switch over wires. (In other words, either UART or CC)
C.
 

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
I have two 18F4620 PIC's running at 8MHz reliably exchanging SPI data using Oshonsoft Basic, also the two PICs have UART 9600 Baud communication to two external PC's for data validation.

For the next step I need to know from you, what,when and how the SPI, the two PIC's are using the SPI link.??

Please don't post any program code, just a text description explaining what data is being exchanged, how often etc............

E
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
I have two 18F4620 PIC's running at 8MHz reliably exchanging SPI data using Oshonsoft Basic, also the two PICs have UART 9600 Baud communication to two external PC's for data validation.

For the next step I need to know from you, what,when and how the SPI, the two PIC's are using the SPI link.??

Please don't post any program code, just a text description explaining what data is being exchanged, how often etc............

E
Hi E,

Excellent! You've had better results than I have.

I've been trying PIN to PIN tests, (18F4620 to 18F4431 and 18F4431 to 18F4620) but I've had odd results, it could be my fault or my suspicion is with the 18F4431 PIC.

Would you like to test using an 18F4431 (QEI) PIC? If so I can post one to you. (surface mount on a test PCB)

What does SPI link mean?

C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi C,
You are not answering my questions, so I cannot offer any further help you with your project.

E
Hi E,
I've obviously annoyed you, sorry.

I was clarifying your question to me regarding the "SPI link" before composing my answers, also I didn't want to waste your efforts, if there is an issue with the 18F4431 PICs

Thanks for trying, and testing with 'live' PICs, I'm glad you've proved it is possible.
EDIT: Today it is clear that "SPI LINK" means HW SPI. (Old slow brain:rolleyes:)
C.
 
Last edited:

ericgibbs

Joined Jan 29, 2010
18,872
Hi C,
Whichever way you intend to transfer data between two PIC's it is important that you post details of the data being transferred.
eg:
Is the Master sending data to the Slave, which the Slave will use in its program or is it just dummy data in order to receive usable data from the Slave.?

Is the Slave sending data to the Master, which the Master will use in its program or is it just dummy data in order to receive usable data from the Master.?

What form is the data, is Hex , ASCII .?

What is the length of the exchanged data block/s.?

If it is ASCII, is it terminated with <crlf> .?

What is the data exchange rate between the Master and Slave.?

Will the Master be using Polling or Interrupts controlled pin in order to start a Slave read cycle.?
or
will the Master set the SS pin Enable out to the Slave and so read whatever is in the Slave SSPBUF.?
or
will the Master set the SS pin which initiate a Slave update of its SSPBUF and when ready the Slave sets the Poll/Interrupt line back to the Master.??

Will the data exchange between Master and Slave have error checking and also use the SSPSTAT OVFL bit. if Yes ,what is the next step in the program.

Answers to these basic questions are required on order for any 'helper' to give you guidance on the project.

Eric.

Footnote:
Ran two 18F4620 for 5 hours yesterday, 16Mhz clock rate, SPI hardware data exchange, Oshonsoft Basic compiled,
Data was 4, ASCII bytes <crlf>

Transferred a total of 280K of data without one drop out

Serial 9600 baud, monitoring of the data received at the Master and the Slave.

Update:
These images show the Master and Slave data exchange, [ from two separate laptops monitoring the UART serial 9600 baud outputs]
At start up Master has one string and the Slave the other, when running they keep swapping the strings and send back the string they have just received.

As the 18F4431 does not have *4 PLL clock option when using the Internal clock, I have used a 20MHz external xtal. This makes the Slave faster than the Master which is a 18F4620 is at 16MHz. [ internal 4MHz and *4 PLL]

The higher clock rate in the Slave is an advantage...
 

Attachments

Last edited:

Thread Starter

camerart

Joined Feb 25, 2013
3,730
Hi E,
Impressive stuff as usual.

TRANSMITTER:
MASTER 18F4431 READs all of the modules (GPS,COMPASS etc) using CS-OSH-SPI-HW. and the SLAVE 18F4431 READs the Incremental encoder, that OUTPUTs 0-359 DEG, which is SENT to the MASTER for calculations.

RECEIVER:
The MASTER RECEIVES DATA via a radio, carries out calculations, then SENDs DATA to the SLAVE to operate the SERVOS/PROPELLORS. (I haven't started to think about any of these calculations yet)

Is the Master sending data to the Slave, which the Slave will use in its program or is it just dummy data in order to receive usable data from the Slave.?
A: RECEIVER: The MASTER is sending DATA to the SLAVE for use in the program.

Is the Slave sending data to the Master, which the Master will use in its program or is it just dummy data in order to receive usable data from the Master.?
A: TRANSMITTER: The SLAVE is sending DATA to the MASTER for use in the program.

What form is the data, is Hex , ASCII .?
A: I'm not sure!

What is the length of the exchanged data block/s.?
A: TRANSMITTER 3xdigits. RECEIVER: I'm not sure, perhaps 20-40 Digits?

If it is ASCII, is it terminated with <crlf> .?

What is the data exchange rate between the Master and Slave.?
A: I'm not sure

1/ Will the Master be using Polling or Interrupts controlled pin in order to start a Slave read cycle.?
or

2/ will the Master set the SS pin Enable out to the Slave and so read whatever is in the Slave SSPBUF.?
or

3/ will the Master set the SS pin which initiate a Slave update of its SSPBUF and when ready the Slave sets the Poll/Interrupt line back to the Master.??
A: TRANSMITTER: 2/ RECEIVER: I'm not sure.

Will the data exchange between Master and Slave have error checking and also use the SSPSTATOVFL bit. if Yes ,what is the next step in the program.
A: I don't see the SSPSTATOVFL BIT. I don't think it will have error checking.

Q: Does the 18F4431 have to run at a high speed? Can 2x PICs run on 1x XTL?

C.
 

Thread Starter

camerart

Joined Feb 25, 2013
3,730
hi C,
Reading your last post, I read it as describing this block diagram of the project, please confirm.

E
Hi E,
Here's a clarification.

I'm not sure whether the BASE TRANSMITTER would need a COMPASS or the REMOTE would need a SCREEN.
IMAGE EDIT:
C.
 

Attachments

Last edited:

ericgibbs

Joined Jan 29, 2010
18,872
hi C,
Looking at all the additional inputs to these PIC's and the way they are all cross connected in that edited drawing, shows IMHO it is too complex a project for you to develop/complete using the Oshonsoft IDE

I would recommend that you review the project specification and its purpose.

Eric
 
Top