View previous topic :: View next topic |
Author |
Message |
ocsgPIC
Joined: 23 Apr 2015 Posts: 9 Location: Pretoria
|
SPI and PIC16F877A Microcontrollers |
Posted: Wed May 20, 2015 2:14 pm |
|
|
Hi everyone, I'm trying to setup a two-interfaced gate controller, whereby you input a password on one interface to enter and you input another password on another interface to exit.
Also the exit interface is programmed to send info of its users to a PC. Now the microcontrollers of the two interfaces are connected via SPI (SDI, SDO, CS and CLK).
At the moment i have successfully configured one microcontroller as the master (exit interface) and the other as the slave (entrance interface): User input password, and gate is opened when password is valid, also a 'wait...' message is sent to lcd of entrance interface via SPI while the other interface is busy.
I would like to do same for the entrance interface and have that interface send info of its users to PC as well. That will require making both microcontrollers to be master and slave such that any interface who is reached first makes other interface to wait until user is done using that interface. Isn't it?
Can you please give advice and/or guide me to existing codes? I would greatly appreciate, thank you! |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9215 Location: Greensville,Ontario
|
|
Posted: Wed May 20, 2015 2:55 pm |
|
|
Firstly, I have to suggest that SPI is not the method of communications that you should be using. SPI is a high speed, SHORT distance method! What is your distance between the gates? You'll run into serious 'EMI' and 'timing' issues using SPI over say .3m ( 1 foot).
Before you proceed, we need a few more details, especially the PIC to PIC distance.
Jay |
|
|
ocsgPIC
Joined: 23 Apr 2015 Posts: 9 Location: Pretoria
|
SPI and PIC16F877A Microcontrollers |
Posted: Fri May 22, 2015 4:51 pm |
|
|
Hey Jay, PIC to PIC distance is about 50cm or less. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri May 22, 2015 11:03 pm |
|
|
I think you would get more help if you posted a block diagram that
shows what you want to do.
Also I think we have some doubt about why you need two PICs.
I assume you have one keypad on the outside of a gate, and another
keypad on the inside. Why not just have one PIC that runs them both ?
Then you want a connection to a distant PC. How far away is that ?
Is it close enough to the gate to use RS-232 ?
-----------------------------
How to post an image on the CCS forum:
Go to this website: http://postimage.org/
Upload your image. Select family safe. Then click the first button for
"Hotlink to Forum" to get a link to the image.
Then go to the CCS forum and type Ctrl-V to paste the link into a post.
If postimage.org doesn't work in your country, then use Google to find
another free image hosting site for forums. |
|
|
ocsgPIC
Joined: 23 Apr 2015 Posts: 9 Location: Pretoria
|
SPI and PIC16F877A Microcontrollers |
Posted: Wed May 27, 2015 1:48 pm |
|
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 27, 2015 1:51 pm |
|
|
The image is too small. I think you picked the wrong link to post. |
|
|
ocsgPIC
Joined: 23 Apr 2015 Posts: 9 Location: Pretoria
|
SPI and PIC16F877A Microcontrollers |
Posted: Wed May 27, 2015 1:55 pm |
|
|
|
|
|
ocsgPIC
Joined: 23 Apr 2015 Posts: 9 Location: Pretoria
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed May 27, 2015 11:19 pm |
|
|
The 2nd module can be the SPI slave and the 1st module the master.
If the 2nd module has data available, it can tell the master by using
an attention line. This additional signal (you will need to add a wire)
could interrupt the master, or the master could poll it. Anyway, when
the master gets "tapped" by the slave, the master can read data from
the slave and then send it on to the PC. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Thu May 28, 2015 12:22 am |
|
|
As a comment, consider using I2C, rather than SPI.
Then the actual interface is only two wires, and the third can be used as the 'attention' line, for the slave device to signal 'I want to talk'.
Generally I2C, is slightly better than SPI at handling any distance. Keep the data rate low (after all, even 10000bps, can send a character in under 1/1000th second), and with reasonable wire I2C can happily handle many feet.
It is not really 'worth' the complexity of any form of multi-master communications, just KISS, and have one device as the master, and as PCM_programmer says, 'signal' that the slave wants servicing. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu May 28, 2015 1:48 am |
|
|
I agree that SPI is a bad choice here. SPI is great for high speeds over short distances up to 0.5m. In this setup you would be working at the system limits and requiring 5 wires. (data in, data out, clock, enable, an 'attention' wire).
I2C is designed to work over distances of about 2m but at lower speeds it is known to work over longer distances as well. Requires 3 wires (clock, data and an 'attention' wire).
The method I would choose is the UART. Running at 5V levels you can go about 2m. Optionally add a MAX232 chip and maximum distance goes to 15m. Is full duplex so you don't need the 'attention' wire. Requires 2 wires total (Rx and Tx).
Only disadvantage I see for choosing the UART is that your main controller should have enough hardware UARTS. You didn't specify how the RF units are going to be connected, but when those are using a UART too then choose a PIC model with a hardware UART for each connection. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9215 Location: Greensville,Ontario
|
|
Posted: Thu May 28, 2015 4:39 am |
|
|
Now that you've posted a diagram of the 'design'..
Yet another way to configure it...
Build both the 'outside' and 'inside' 'slave' units the same.Each has LCD,KPD, RF,etc. Code will be nearly identical. Hardware can be identical,just some functions NOT implemented on the 'outside' module.
Then build the 'master' that has RF as well as USB to the PC. The 'master' would access the 'slaves' either by polling or seeing interrupts from them.
If you don't go 'RF' then use 'RS232'. It is far better for noise immunity,EASY to implement and you do not need the speed that I2C or SPI offer. Some commercial alarm systems use RS485 for their 'remote keypad' interfaces,use 4 wires(+12,gnd,xmt,rcv).
just providing options.....
Jay |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Thu May 28, 2015 4:57 am |
|
|
temtronic wrote: | Some commercial alarm systems use RS485 for their 'remote keypad' interfaces,use 4 wires(+12,gnd,xmt,rcv).
|
As RS485 is a differential bi-directional signalling standard it's not transmit (xmt) and receive (rcv), but something like A & B or + and -, or... the standard is not well adhered to in this respect, so usage varies a lot, is confusing, and just to make things extra fun (not), conflicts between different manufacturers of drivers/transceivers.
I'd be tempted to use 485, it's inherently more flexible than 232 as its capable of multi-drop (i.e. potentially allowing extra keypads to be added if required) and more robust as its differential rather than point-to-point and single ended. |
|
|
ocsgPIC
Joined: 23 Apr 2015 Posts: 9 Location: Pretoria
|
SPI and PIC16F877A Microcontrollers |
Posted: Thu May 28, 2015 6:30 am |
|
|
Thank you all for your feedbacks!
Thing is this a demo unversity project intended for display only. It will not be implemented in a house or industry yet. Hardware (PCBs with all components soldered onto them) has been built already and I have to go with SPI-4 wires: SDI, SDO, CLK, CS (I can easily compromise for a distance of less than 0.3m but it will be difficult to add a 5th wire) or maybe I2C at very least.
ocsgPIC |
|
|
ocsgPIC
Joined: 23 Apr 2015 Posts: 9 Location: Pretoria
|
SPI and PIC16F877A Microcontrollers |
Posted: Thu May 28, 2015 6:41 am |
|
|
RF communication link has been implemented, tested and proven to work. Only thing remaining is the SPI communication. I will keep trying to make it work and use I2C as last option. |
|
|
|