spi pic to pic

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

spi pic to pic

Postby brandonb » Tue Jan 01, 2013 8:34 am

using spi, how would the master get information from another pic acting as a slave? it seems that spi macro has only master functionality, would like to have something simular to uart but with spi as its super fast

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

Re: spi pic to pic

Postby Benj » Wed Jan 02, 2013 11:04 am

Hello Brandon,

We have not yet implemented a SPI slave using Flowcode but this is on the list.

One of our users implemented I2C slave on the following topic.

viewtopic.php?f=7&t=7081

It should be possible to do SPI slave using C icons to modify the setup of the SPI register SSPCON1 though there may be other things that need to be altered to allow this to work.
These users thanked the author Benj for the post:
brandonb (Wed Jan 02, 2013 6:20 pm)
Rating: 5%
 

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: spi pic to pic

Postby brandonb » Sun Jan 06, 2013 9:04 am

We have not yet implemented a SPI slave using Flowcode but this is on the list.

just curious ben, when are we to expect rx receive macros for spi and i2c, is that v6 or sooner, sounds like a lot of work either way

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

Re: spi pic to pic

Postby Benj » Fri Jan 11, 2013 5:16 pm

Hello Brandon,

Certainly won't be a v5 thing I'm afraid unless someone wants to work out all the C code for us :D

Hopefully it will be very easy to make components in v6 so I am hoping we will add loads to this once it has been released and we have a bit more free time.

User avatar
STibor
Posts: 262
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 115 times
Been thanked: 112 times
Contact:

Re: spi pic to pic

Postby STibor » Tue Apr 02, 2013 5:30 pm

Up the topic.
I would be very happy if we had SPI slave configuration. :roll:

User avatar
STibor
Posts: 262
Joined: Fri Dec 16, 2011 3:20 pm
Has thanked: 115 times
Been thanked: 112 times
Contact:

Re: spi pic to pic

Postby STibor » Mon Nov 25, 2013 6:03 pm

SPI Slave example.
Attachments
SPI_slave_1_1_18F6622.fcf
(12.07 KiB) Downloaded 143 times

brandonb
Posts: 438
Joined: Mon Aug 29, 2011 12:26 am
Location: arizona
Has thanked: 175 times
Been thanked: 173 times
Contact:

Re: spi pic to pic

Postby brandonb » Tue Nov 26, 2013 1:17 am

working spi master slave, this is a simple test but you can see how this can be expanded to send and process any instruction, and send back as many bytes the master is programmed to send....
it is important when sending message to slave that at least a 1ms delay is used
here is master code
16f1939 spi master.fcf
(9.5 KiB) Downloaded 178 times

here is slave
16f1939 spi slave.fcf
(13.47 KiB) Downloaded 181 times


operation:
master sends 15, waits 1ms then gets byte
slave is waiting for ss pin(A5) to go low, then clocks in bytes as master provides clock, spi_cnt variable is initialized as zero, in the isr when you'll see if( !(spi_cnt)) what this does is when the first byte comes it it processes the command with if statements by linking variables and writing the sspbuf, when it writes sspbuf on the next message it will send this data out when the clock arrives,
in the isr in this case its a simple example and only expected to see two bytes per message which is instruction followed by one slave sent byte, so a spi_cnt variable is incremented inside the isr as to ensure that if two bytes are followed that the first byte is the instruction and the second byte it sends the data, after it sends the data the spi_cnt variable is >1 so it returns to zero for the next set of data bytes that occur..... all pins config stuff and enable code is done in the interrupt icon code, it can easily be adapted to other pic chips.... cheers