CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SPI and PIC16F877A Microcontrollers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ocsgPIC



Joined: 23 Apr 2015
Posts: 9
Location: Pretoria

View user's profile Send private message

SPI and PIC16F877A Microcontrollers
PostPosted: Wed May 20, 2015 2:14 pm     Reply with quote

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: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed May 20, 2015 2:55 pm     Reply with quote

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

View user's profile Send private message

SPI and PIC16F877A Microcontrollers
PostPosted: Fri May 22, 2015 4:51 pm     Reply with quote

Hey Jay, PIC to PIC distance is about 50cm or less.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 22, 2015 11:03 pm     Reply with quote

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

View user's profile Send private message

SPI and PIC16F877A Microcontrollers
PostPosted: Wed May 27, 2015 1:48 pm     Reply with quote

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 27, 2015 1:51 pm     Reply with quote

The image is too small. I think you picked the wrong link to post.
ocsgPIC



Joined: 23 Apr 2015
Posts: 9
Location: Pretoria

View user's profile Send private message

SPI and PIC16F877A Microcontrollers
PostPosted: Wed May 27, 2015 1:55 pm     Reply with quote

ocsgPIC



Joined: 23 Apr 2015
Posts: 9
Location: Pretoria

View user's profile Send private message

SPI and PIC16F877A Microcontrollers
PostPosted: Wed May 27, 2015 1:56 pm     Reply with quote

http://s30.postimg.org/plm2wu57l/Block_Diagram_of_the_system_2.jpg
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 27, 2015 11:19 pm     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Thu May 28, 2015 12:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 28, 2015 1:48 am     Reply with quote

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: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu May 28, 2015 4:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 28, 2015 4:57 am     Reply with quote

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

View user's profile Send private message

SPI and PIC16F877A Microcontrollers
PostPosted: Thu May 28, 2015 6:30 am     Reply with quote

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

View user's profile Send private message

SPI and PIC16F877A Microcontrollers
PostPosted: Thu May 28, 2015 6:41 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group