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

Communication SPI between 2 18f4550

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



Joined: 18 Jan 2018
Posts: 1

View user's profile Send private message

Communication SPI between 2 18f4550
PostPosted: Thu Jan 18, 2018 12:17 pm     Reply with quote

Hello, I'm trying to make a continuous communication with 2 18F4550. I make one based in another program but i failed when i compiled it.

The main thing that one of my pics it's connected to a dip switch and when i pull up in a combination send to other pic the value and then this other pic returns and answer.
I'm making probes with leds, but it doesn't work.
Can someone help me?
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Thu Jan 18, 2018 12:27 pm     Reply with quote

If you just want to send a number, use I2C.

SPI is the better interface if you need very high speed, but is more complex to get right. Problem is that there is nothing to guarantee initial synchronisation, unless you add a select line. Also remember that it is taking place both ways at once. So when you send a byte you receive 'back' at the same time what was in the slave's buffer register. To then send a reply back, you have to then load the reply, before the master then clocks this back, with suitable timings at each stage.

Now I2C, has in the hardware a synchronisation system, based upon the start and stop, and also using open collector lines, so the slave can delay the clock release. Makes it much simpler to implement....
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 18, 2018 1:10 pm     Reply with quote

Unless it's a requirement to use SPI, use serial, aka RS-232. CCS supplies examples, even single wire communication betwen PICs.
For the short distance that SPI implies, using 'RS-232' will definitely do the job !

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Thu Jan 18, 2018 3:01 pm     Reply with quote

Downside is he won't have hardware receive on these pins. The same pins though will have hardware I2C.
Hence my suggestion.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jan 18, 2018 4:42 pm     Reply with quote

He should hopefully be able to use the hardware UART(RC6 RC7). we really need more information as to what is available and required.
So far he's got 3 or 4 options for the project !
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 18, 2018 7:40 pm     Reply with quote

Here are two SPI slave examples. There are many more in the forum
if you search for: SPI slave (and set it to search for all terms).
http://www.ccsinfo.com/forum/viewtopic.php?t=26888
http://www.ccsinfo.com/forum/viewtopic.php?t=39145

Also look in your CCS examples directory for this program:
ex_spi_slave.c
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