View previous topic :: View next topic |
Author |
Message |
D_Portgas
Joined: 18 Jan 2018 Posts: 1
|
Communication SPI between 2 18f4550 |
Posted: Thu Jan 18, 2018 12:17 pm |
|
|
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: 19520
|
|
Posted: Thu Jan 18, 2018 12:27 pm |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Thu Jan 18, 2018 1:10 pm |
|
|
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: 19520
|
|
Posted: Thu Jan 18, 2018 3:01 pm |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Thu Jan 18, 2018 4:42 pm |
|
|
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
|
|
|
|