SPI Master / Slave

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

SPI Master / Slave

Post by JLeith »

Hello All

I was reading a MATRIX Blog on SPI Master and it mentioned that a SPI "Slave" was in the works ?

I looked in my Flowcode 6 "Comms" and only see the SPI Master ?

Can I use the SPI Master in a Slave Module ?

John
Attachments
SPI Master.jpg
SPI Master.jpg (16.51 KiB) Viewed 14260 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: SPI Master / Slave

Post by LeighM »

Unfortunately not.
We currently have I2C master and slave, but not SPI slave

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Hello LeighM

Thank you for the info

LeighM I plan on setting PIC16F1983 with SPI Master and having it to TX only with the SPI using MOSI to a Wireless NFR095

Then have the RX NFR905 connected to the Slave PIC16F1983 and setting it to read the MISO input.

Here is my picture.
Do you beleive it will work ?

John
Attachments
PIC to NFR905.jpg
PIC to NFR905.jpg (61.49 KiB) Viewed 14221 times

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: SPI Master / Slave

Post by Jay Dee »

Hi John,
A) Just my 2 cents, as I've done something similar. Both PICs are the masters to their respective slave RF modules. So that's your SPI Master/Slave relationship.
B) You do have a Local and Remote devices. So the end user may consider the remote device to be a slave of the master, but that is a separate issue to the SPI relationship.
C) I'm not 100% but I can't remember having a pull down resistor on my SPI Clock, MOSI and MISO lines... certainly with values of 330R the system would have to work hard to drive them
D) I also use in-line resistors to attenuate any ringing but check with a scope your not overly damping the rapidly transitioning signal levels.
J.

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Hello Jay

I rellay appreciate you taking the time and every penny will help me with the SPI world.
1. Yes I had a messge indicating there is no SPI Slave module in the New Flowcode 6. So in my case I beleive I have in case two Masters Just 1 as TX and the Slave as a RX. The MOSI and MISO on the PIC should work. I have started a Bench circuit. My Wireless units are still in transit. They say April 8th they should be here.
but that is a separate issue to the SPI relationship.
2, Jay you mention 'Seperate Issue" do you think I will have concern in the development ?

3. On the resistors I had a terrible time geting any information on using a PIC with SPI to Wireless NFR905. I more or less copied 4 different designs from NFR905 documentation.

4. I beleive your are correct that I realy don't need the Serial resistors to attenuate. For the MISO ,MOSI I don't need the pull down. On the CS/SS I beleve I will set that a LOW state seeing I only have 1 slave. This way the slave will be ready to receive constinitly.

Now I still have many hours of Bench testing seeing this Wireless is all new. And only wireless connects I have found are with Audrino uses no PIC.

Jay did use wireless in you past project or wired ?

John

User avatar
Jay Dee
Posts: 398
Joined: Tue Aug 18, 2009 6:42 pm
Has thanked: 121 times
Been thanked: 154 times
Contact:

Re: SPI Master / Slave

Post by Jay Dee »

Hi,
I dont see any issue with the basic idea but you don't need a PIC to be a Slave SPI in your application.
You have two PICs, each one is the master to a NFR905, this is the correct way to do this project.

The NFR905 specification does not call for pull up/down resistors.
I have not worked with the NFR905 but in other SPI projects there were no pull up/down resistors. You do however need to check you have the correct idle state and the data is clocked in on the correct edge. You need to carefully read the datasheet to make sure everything is right. It can take lots of time and scoping! :D

With every new wireless chip I have spent many days working out the correct control code and getting to work correctly. :)
The best products I have found so far are
The eRIC module from www.LPRS.co.uk - I got around 150m range.
The Bravo module from www.RFSolutions.co.uk - I got around 200m range.
The GAMMA module from RF Solutions - Its not as quick a responce as the Bravo but I got over 500m range.
The Bravo and Gamma modules have a super simple digital Input/Outputs or can also be made to handle simple serial data. They have to be one of the easiest RF modules to use.
Best of luck with your project.
J.

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Thank you Jay Dee for the info

The project is a Baseball Pitch counter. I have the Master as the box at the scorekeepers area with the ability to enter each pitch the pitcher pitches and it also p[ost messages on the LCD for bench maks in the Pitchers pitches.

The Master just send the pitch count to the Salev units.

There is actully 2 slaves receiveing the same info.

The Slave receives the Pitch count and the PIC generates the LCD display and also displays a warning when the pitchers reach diffrent pitch counts.

I will post here once the NFR905 arrive.

Thanks again for the help.

John

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Hello All

I have Master PIC16F1937 with SPI transmission to a Slave PIC16F1937 Hard Wired

I'm puzzled on what Flowcode component material.

This is what I have found
I'm confused on 3 items
Master
1. "Transmit Write Command ( Ox5A ) ??
2. "Transmit Internal Address ( IntAddress ) ??
3. Transmit Data ( Not sure what Data to send )

And on the Slave
1. Transmit Read Command ( OcA5 ) ---- Why would the Slave "Transmit ???
2. Transmit Internal Address ( ( IntAddress ) ---- Why would the Slave "Transmit ???
3. Receive Data 'Get Data" Now this makes some sense.

I really can't find a clean image of Flowcode example of the coding for the Master then Slave.

Can't even find 'You Tube" help.

John
Attachments
SPI Flowcode example.jpg
SPI Flowcode example.jpg (70.97 KiB) Viewed 13988 times

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: SPI Master / Slave

Post by kersing »

John,

As Jay already tried to explain in previous messages, the PIC is SPI master for both the receiver and the transmitter. The RF modules are the slaves that need telling what they should do. For the data flow one of the modules (transmitter) is 'master', sending the data to the (receiver) 'slave', however that relation has no impact on the SPI roles for the PICs and the RF modules.

So the flow is:
PIC (SPI master) tells RF module (SPI slave) to transmit data (data master).
The second PIC (SPI master) tells the second RF module (SPI slave) to receive data (data slave),
And on the Slave
1. Transmit Read Command ( OcA5 ) ---- Why would the Slave "Transmit ???
2. Transmit Internal Address ( ( IntAddress ) ---- Why would the Slave "Transmit ???
3. Receive Data 'Get Data" Now this makes some sense.
If you look at the flow I've provided above the quote this should make sense. The PIC (SPI master) needs to tell the RF module (SPI slave) what operation to perform and which address to use. If the PIC (SPI master) did not tell the RF module (SPI slave) what to do, how would it know what needs to be done? It can not be configured by the transmitter as they might be several transmitters in range and the receiver would not know which transmitted it should be paired with. So the local microcontroller (PIC, SPI master) needs to tell it (RF module, SPI slave) what to do.

Hope this helps and does not confuses you even more ;-)

Best regards,

Jac
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Hello Jac

Thank you for responding.
In my case I have ( 1 Master ) ---- ( 2 Slaves which have the exact same action )

I don't know if you follow baseball. In my grandson baseball league for 8 & 9 yr olds they have what is called pitch counts for the pitchers. They can oly pitch so many pitches in a day.

Today they keep manual records and have to call out when the pitcher reach each level.

My design works 100% for the master. The Master has a push button and a LCD to display the pitch count. The master in this case has a buzzer that signals when the pitcher reaches a level.

Now the tricky part my vision was to have a "Wireless" receiver ( SLAVE ) in each of the teams dugouts so the Pitch count could be displayed on the Quad LED display. They would see their pitcher and also the opposition.

The problem I'm having is I entered the ( OxC5 ) as a "Variable" and the ( IntAddress ) as a variable. On the Master. And then on the Slave.

I'm not 100% sure why I had to list them as a Variable and also what value I would place in the Variable.

Then on the Slave the same Variables ?
I can see the action for "Send Character" and " Receive Character"

Yes I follow the steps that the Master uses the "CS" to signal which Slave to communicate. In my case the CS will trigger both 'Slaves" to listen.

My seach for info is so thin as to what the Ox5A and intAddress do ?

I have my PICKIT2 as a logic setting and seeing when I see the CS go low. It does but not when I beleive it should trigger. It shoud trigger every digit.

Jac is the Flowcode I have found I didn't write the code it was from a Matrix Blog on SPI. Will it work ?

So far a quick test and nothing is showing on the Slave.

John

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: SPI Master / Slave

Post by GTF »

Hi John,

As has per the other explanations here, you should relabel your image with both PICs as Masters and both NRF905s as slaves, then it should make more sense. You have no slave PICs. Think of it as working with just 1 PIC and 1 NRF905. The only difference is each PIC is sending different configuration settings and instructions to the connected NRF905. The NRF905 datasheet will define the address, configuration, send/receive instructions and data format that need to be sent by the PICs to the NRF905s. Each PIC is always a master. One PIC is not controlling the other PIC via the NRF905s. One is sending data to a NRF905 and the other is reading data from a NRF905 and outputting that data to a LCD.

If you had 2 PICs wired together directly via SPI, then 1 could be the master and the other the slave. SPI communication only occurs over wires/PCB traces.

You can remove all the resistors from your drawing. At least the the master-slave pair on the receiving end is going to need 4 wires as it will need MOSI to send instructions to the NRF905 and MISO to receive data from the NRF905. The other pair may also need 4 wires, depending on how you intend to use it. I haven't had a chance to look at the NRF905 datasheet yet...too busy trying to sort out my own problems in the little free time I have. I need to be retired too!

Grant
Last edited by GTF on Mon Mar 28, 2016 2:25 pm, edited 1 time in total.

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Hello Grant

Thank you for taking the time to help me.

Yes you are 1000% correct I don't need the resistors after searching and serching for as much info I can on SPI.

My mystery is the ( Ox5A and INTAddress )
I have set them as Variables but I don't follow as what value I would place for the variable. Variable contain values for actions.

They are a total mystery on how they fit into the SPI world.

For the definition of Master / Slave yes the Master PIC to the NFR905 would be Master /Slave and the same in the other PIC. I was listing the NFR905 as more or less and "wire" for the drawings.

I'm currently wiring the PIC's together and using the 'logic" analyser on the PICKIT2 to capture the timing.

More when I have the readings.

John

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: SPI Master / Slave

Post by kersing »

JLeith wrote: The problem I'm having is I entered the ( OxC5 ) as a "Variable" and the ( IntAddress ) as a variable. On the Master. And then on the Slave.
Can we please stop using master and slave for both the units and the SPI devices? Can we use sender for the unit sending updates and receiver for the units getting the updates? And reserve master for the micro controllers driving the SPI bus and slave for the nRF905 units?
JLeith wrote: I'm not 100% sure why I had to list them as a Variable and also what value I would place in the Variable.

Then on the Slave the same Variables ?
I can see the action for "Send Character" and " Receive Character"
As I haven't seen your flowchart (apart from the two snippets) I don't have a clue what you are referring to. However the nRF905 data sheet should contain the information you need to configure the modules and read the data. (Page 21 lists the commands, also check page 20 for the required wiring between controller and nRF module)
JLeith wrote: Yes I follow the steps that the Master uses the "CS" to signal which Slave to communicate. In my case the CS will trigger both 'Slaves" to listen.
CS (actually NCS) signals to the module it should listen to the SPI bus. When NCS is 1 the module ignores the SPI bus. So it does nothing with regards to sender/receiver.
JLeith wrote: My seach for info is so thin as to what the Ox5A and intAddress do ?
Where did you find these values? I don't see anything like it in the data sheet...
JLeith wrote: Jac is the Flowcode I have found I didn't write the code it was from a Matrix Blog on SPI. Will it work ?
The Matrix example will work for the device is was designed for. The chances of the commands being the same for you slave (nRF905) are close to zero. You will need to check the data sheet for your device.

Aha, checking the BLOG is see a remarkable resemblance with your code. The code on the blog is an example for a specific device and it will NOT work for your modules. You need to read the data sheet of the modules to see what SPI sequences to use. (Or find example code on the internet and borrow the commands used). Did you notice the lines just below the diagram?
Matrix blog wrote: Again there may be additional address bytes or differing protocol for your device so refer to the device datasheet for the exact specifics.
Reading the data sheet (or borrowing working code from the internet) will be required.


A quick search for example code provides this C code. It shows you need to send the following data to the nRF to configure it (note this set up assumes the module is used in 868/915MHz mode, not 434MHz):

Code: Select all

10,
0x01, //byte# 0 : set the channel # to 1
0x0e, //byte# 1 : 0bxx[AUTO_RETRAN<5>][RX_RED_PWR<4>][PA_PWR<3:2>][HFREQ_PLL<1>][CH_NO[8]<0>]
// 0b00001100 => AUTO_RETRAN=0; No retransmission of data packet
// RX_RED_PWR=0; Normal operation
// PA_PWR=11; +10dBm output power
// HFREQ_PLL=1; chip operating in 868 MHz band
// CH_NO[8]=0; 9th bit of CH_NO is zero
0x44, //byte# 2 : TX_AFW[2:0]=100 => 4 byte TX address field width
// RX_AFW[2:0]=100 => 4 byte RX address field width
0x20, //byte# 3 : RX_payload width of 32 bytes
0x20, //byte# 4 : TX_payload width of 32 bytes
0xcc, //byte# 5 : RX_ADDRESS byte 0
0xcc, //byte# 6 : RX_ADDRESS byte 1
0xcc, //byte# 7 : RX_ADDRESS byte 2
0xcc, //byte# 8 : RX_ADDRESS byte 3; thus the RX ADDRESS is configured to 0xcccccccc in this example
//remarks : The default value is 0xE7E7E7E7
0x58 //byte# 9 : Set the CRC_MODE, CRC_EN, XOF[2:0], UP_CLK_EN, UP_CLK_FREQ[1:0] bit values
// In this configuration, we are doing CRC enable for 8 CRC check bit, 16MHz crystal freq,
// and output clock disable
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

GTF
Posts: 170
Joined: Sat Dec 10, 2011 7:21 pm
Location: Canada
Has thanked: 20 times
Been thanked: 52 times
Contact:

Re: SPI Master / Slave

Post by GTF »

Looking at the NRF905 datasheet, there are a half dozen more pins that need to be wired to the PIC. A couple may simply need pullups if you want the NRF905 to be always powered up. Ensure that both the PIC and NRF905 are running on 3V. NRF905 needs 3V. You will need a level shifter on all lines between the two if the PIC is 5V. Actually, it appears that this was the purpose of the resistors in your drawing above....they are arranged as voltage dividers to bring down 5V to 3V.
Attachments
NRF905.png
(61.36 KiB) Downloaded 3743 times

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Wonderful news Grant

Your image is in color comparded to the one in the NFR905 page 35

In Kersing message the question of calling them Master / Slave is really only my way in keeping the (2) pics with totaly seperate programs.
The "Master" has (Push Buttons) ( LCD for messages ) ( QUAD display )
The Slave PIC ( QUAD Display )

Yes I have it in my drawings that the NFR905 is the "Slave" device with SPI configurations.

Grant on the Extra leads this what I see
Master PIC outbound to NFR905
TXEN
TRX_CE
Pwr_UP
MOSI
SCK
CSN

NFR905 to Team PIC
UPCLK
CD
AM
DR
MISO

I going to print off the PIC16F1937 PDF Document so I hope I can find these leads
TXEN
TRK_CE
UPCLK
CD
AM
DR

480 pages it off to Staples to have it printed and coil bonded.

I see that 100% the NFR905 needs 3 Volts and I suspect the MOSI and MISO supply logic 1 at 5volts.

I suspect I have endless hours of reading and If I need a few extra leads I will have to get rid of either my LCD or work out something.

Your knowledge is spot on Grant.

More when I have a liitle more coffee and my reading glass polished.

John

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: SPI Master / Slave

Post by kersing »

JLeith wrote: I going to print off the PIC16F1937 PDF Document so I hope I can find these leads
TXEN
TRK_CE
UPCLK
CD
AM
DR
Don't bother trying to find them on a PIC controller, those pins are nRF module specific and are not available on the PIC. Use generic digital I/O pins on the PIC if your design requires them. As Grant stated not all may be required. Check the nRF data sheet to see which you need and which can be pulled up/down.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Thank you Kersing

I just got back from printing 472 pages.

Yes I did some reading and I think I have many more pages.
I think I will need the Pwr_UP there will be times when I don't need to waste the battery.
MOSI
SCK
CSN
MISO

Odd I don't see a CS lead on the NFR905 Maybe the PWR_UP could be the CS ?

John

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: SPI Master / Slave

Post by kersing »

CSN, pin 13 is the Chip Select Negative (Low) active. Other vendors call this CS.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

User avatar
JLeith
Posts: 537
Joined: Wed Nov 14, 2012 7:49 pm
Location: British Columbia Canada
Has thanked: 146 times
Been thanked: 26 times
Contact:

Re: SPI Master / Slave

Post by JLeith »

Thank you Kersing

It would be nice if all the vendors used the same naming.

John

Post Reply