• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Transfering DATA between two pics via SPI OSHONSOFT

camerart

Active Member
Thread starter #1
Hi,
I have a MASTER PIC 18F4620 and a SLAVE PIC 18LF4431.

The MASTER PIC uses SPI for external MODULES.

There are other SLAVES e,g, Compass module, barometer module, each has it's own C/S including the SLAVE PIC.

The SLAVE PIC READs the QEI of an INCREMENTAL ENCODER, and outputs AZIMUTH which is between 0 and 359.

EDIT: Updated.
Camerart.
 
Last edited:

rjenkinsgb

Active Member
#2
The slave device needs to be configured for "slave mode" in its own program.

That configures it so the SPI shift register clock pin is an input rather than an output, allowing the master device to clock data in to the slave's shift register.
 

camerart

Active Member
Thread starter #3
The slave device needs to be configured for "slave mode" in its own program.

That configures it so the SPI shift register clock pin is an input rather than an output, allowing the master device to clock data in to the slave's shift register.
Hi R,
From what you say, for my configuration, both PICs will need to switch rolls, between MASTER and SLAVE.
C.
 

camerart

Active Member
Thread starter #5
Why would they need to switch roles? SPI is bidirectional.

Mike.
Hi M,
Is it possible then that the MASTER can receive DATA from the SLAVE?
EDIT: I've just realised something!!! The master is receiving DATA from all the other SLAVES, and the second PIC is simply another SLAVE. (Is this true?)
C.
 

Pommie

Well-Known Member
Most Helpful Member
#6
When the master sends a byte it also receives a byte from the slave. Only one slave can receive data if two way communication is required.

Mike.
 

camerart

Active Member
Thread starter #8
Hi,
Well I've tried for weeks now, and with SPI between two different type of PIC, while being confused by the SPI/I2C choices, I've realised that this is much too difficult for my skills.

Thanks for all the help.
C.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
#9
Hi M,
Is it possible then that the MASTER can receive DATA from the SLAVE?
EDIT: I've just realised something!!! The master is receiving DATA from all the other SLAVES, and the second PIC is simply another SLAVE. (Is this true?)
C.
How can it?, SPI requires a separate chip select line for each device, only the selected one is active.
 

camerart

Active Member
Thread starter #10
How can it?, SPI requires a separate chip select line for each device, only the selected one is active.
Hi N,
I misnamed it SLAVE, what I should have called it is AZIMUTH on a SLAVE PIC. (Now changed)
Each of the SLAVEs has a C/S including the SLAVE PIC.
C.
 

ronsimpson

Well-Known Member
Most Helpful Member
#12
If you can tell us what is not work it might help. I think you are talking to SPI slave ICs. It is just the micro(slave) is not responding.
I get confused by which pin is data in or data out in slave mode. Does Dout need to be configured as out first. Dose the clock source need to be set as external or is that automatic in slave mode.
 

camerart

Active Member
Thread starter #14
If you can tell us what is not work it might help. I think you are talking to SPI slave ICs. It is just the micro(slave) is not responding.
I get confused by which pin is data in or data out in slave mode. Does Dout need to be configured as out first. Dose the clock source need to be set as external or is that automatic in slave mode.
Hi R,
I'm pretty sure the SLAVE PIC is working. I have two buttons to simulate quadrature counting, and I have put this in memory then READ it and out putted it via HSEROUT, that I can see on a computer terminal.

The MASTER is READing the memories of the external modules, but they have REGISTERs with BYTE sized addresses that are READ successfully. So far I haven't been able to put the AZIMUTH into a BYTE sized area.

The TRISs need to be set accordingly.
MASTER OUT SLAVE IN = MOSI on the D/S it says e,g, SDO of the MASTER and SDI on the SLAVE.

The CLOCK of the MASTER must = OUT and the SLAVE = IN, THE SLAVE uses the MASTER clock.

I'm now testing the SPI OUTPUTs with a digital analyser, but some of the connections aren't working???

I've updated #1 to clarify.

C.
 
Last edited:
#15
Depending on which package you have, SPI data might be shared with I2C functionality

see: Microchip 39626e.pdf, pg 15.

RC4 / SDI / SDA (pin 15)

If you're not using I2C, Perhaps you need to disable it.

I would look and see if any other modules are interfering with SPI, and disable what's not used.
 

camerart

Active Member
Thread starter #16
Depending on which package you have, SPI data might be shared with I2C functionality

see: Microchip 39626e.pdf, pg 15.

RC4 / SDI / SDA (pin 15)

If you're not using I2C, Perhaps you need to disable it.

I would look and see if any other modules are interfering with SPI, and disable what's not used.
Hi M,
When you say PACKAGE, is this the same as PIC? If so see #1

I have both PIC PDFs, would you let me know if you are talking about MASTER or SLAVE please?

As my message #8 I get mixed up with the SPI/I2C choices, which makes it beyond my skills.

This is a test pair of connected PCBs, with no other modules.

I tried the digital analyser, on toggled the PORTs involved, which switched ok, but on actual testing, the CLOCK isn't switching.

C.
 
Last edited:
#17
By "package" I mean that you can get the PIC18F4620 in a 28 pin dip (soic), a 40 pin dip (soic) or a 44 pin TQFN.
That means that some pins are not there in the different packages (i.e. a 28 pin dip won't have as many pins as a 44 pin TQFN).
So, functionality gets moved around, depending on the package.

From what I'm seeing, the PIC18LF4431 is a 3.3v device and the PIC18F4620 is a 5v device.
Could there be some kind of level shifting needed?
 

Nigel Goodwin

Super Moderator
Most Helpful Member
#18
From what I'm seeing, the PIC18LF4431 is a 3.3v device and the PIC18F4620 is a 5v device.
Could there be some kind of level shifting needed?
Voltages aren't 'set in stone', a 5V PIC works perfectly well at 3.3V - I've always thought there's little point in using the LF series devices, the normal F series go plenty low enough.
 

Latest threads

EE World Online Articles

Loading

 
Top