SPI between two PIC

Forum for problems or queries regarding Flowcode Comms Components. Eg LIN, I2C, SPI, RS232, CAN, IrDA etc

Moderators: Benj, Mods

Post Reply
WalkOver
Posts: 65
Joined: Fri Nov 23, 2007 11:24 pm
Contact:

SPI between two PIC

Post by WalkOver »

Hello the Flowcode Team !

I must send some octet to an other PIC but I already use the RS232 protocol. Is it possible to communicate between two PIC on the same card with the SPI protocol?
Send or reiceive char generates a clock on SCL. I'm afraid there is a conflict. This solution works or I must be something else? How?

Thank you very much !

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: SPI between two PIC

Post by Sean »

It is possible to transfer data between microcontrollers using either SPI. To transfer data, one device must be configured as a MASTER (the default configuration in Flowcode) and the other devices must be configured as SLAVES (the normal configuration for most peripheral devices). The master controls the clock and data out lines, and is in control of the SPI bus even when receiving data.
Flowcode does not currently directly support the configuration of a microcontroller as an SPI slave, though most of the PIC microcontrollers now contain SPI peripherals that can support this mode of operation. In slave mode the SPI clock is an input, allowing data to be clocked in on the SDI line by an external device.

There are several ways to add the SPI slave functionality to a Flowcode program (depending on the required clock speed, function flexibility etc.), some requiring access to the device data sheet to obtain register names and functions. These include:

Using a Flowcode Custom Component to create an SPI Slave component in C.
Using Flowcode C Code blocks to read and write the registers of the SPI peripheral directly.
Writing simple Flowcode routines, or macros, that performs all the SPI receive operations by checking the SPI clock and data lines as normal inputs (bit-banging). Due to the simplicity of the SPI bus, the bit-banged option is often suitble for both master and slave devices, especially if low clock speeds are acceptable.

WalkOver
Posts: 65
Joined: Fri Nov 23, 2007 11:24 pm
Contact:

Re: SPI between two PIC

Post by WalkOver »

Hello and thank you for your answer.

I tried to change your SPI_Code.c file to setup my PIC as a slave.
I just set both SSP1CON1 and SSP1STAT register (I use a PIC 18F6527)
SSP1CON1 = 0b00100100
SSP1STAT = 0b00000000
And I just set the SCK bit but it doesn't work. The simulation doesn't work with Proteus. What i have to do for the slave works well ?

Is it possible to check my file ?

Thank you in advance.
Attachments
Custom_Code.c
(2.88 KiB) Downloaded 457 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: SPI between two PIC

Post by Benj »

Hello

I have modified the custom_code file you have created to configure the SSP1CON1 register with the following value 0b00100101; This disables the slave select pin so that the device is always ready to transmit or receive data,

I have also added a function that will check for a received byte in the incoming buffer. If you wait for this to return a 1 before perfomring a read then that should work fine.
Attachments
Custom_Code.c
(3.15 KiB) Downloaded 622 times

WalkOver
Posts: 65
Joined: Fri Nov 23, 2007 11:24 pm
Contact:

Re: SPI between two PIC

Post by WalkOver »

Thank you very much Benj,

I will test your custom code this evening or tomorow !

Have a nice day !

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: SPI between two PIC

Post by Benj »

Ok let me know how you get on. I am fairly confident in the code but im afraid so far I have been unable to test it out.

Post Reply