View previous topic :: View next topic |
Author |
Message |
Tom Jetland
Joined: 23 Jun 2011 Posts: 31 Location: UK
|
pic16f877a spi |
Posted: Thu Oct 25, 2012 4:44 am |
|
|
Hi, just a quickie,
Am I correct in thinking that if two PICs are connected together via spi (one master, the other slave, using SS line), that both of the following examples would be compatible: -
Code: |
setup_spi( SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16 | SPI_XMIT_L_TO_H );
setup_spi( SPI_SLAVE | SPI_L_TO_H | SPI_XMIT_L_TO_H );
|
and
Code: |
setup_spi( SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16 | SPI_XMIT_H_TO_L );
setup_spi( SPI_SLAVE | SPI_L_TO_H | SPI_XMIT_H_TO_L );
|
the difference between the two is the SPI_XMIT_H_TO_L parts.
Cheers,
Tom |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Tom Jetland
Joined: 23 Jun 2011 Posts: 31 Location: UK
|
|
Posted: Fri Oct 26, 2012 9:50 am |
|
|
Thanks PCM programmer. I'll have a look at this lot.
It's weird how I can only get the spi to work using the first example code block I specified, and not the second. My suspicion lies with the pic16f877A though, as microchip has a whole errata document on spi for this chip, clarifiying certain things, i.e.
http://ww1.microchip.com/downloads/en/DeviceDoc/80131e.pdf
If you can spare the time, please have a look at the 2. Module: MSSP (SPI Slave Mode) on page 2 and see if you can work out what they're talking about?
Thanks,
Tom |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Fri Oct 26, 2012 12:08 pm |
|
|
The only one that will cause you problems here, is the level. Basically in your slave code, you need to monitor the SCK pin (by using n input on the pin), and only enable the SPI _after_ the pin goes to the idle state. Obviously for a low idle state, there is a probability the line will be low when the chip wakes, but for the high idle state, you will need to wait, or the slave won't work.
Best Wishes |
|
|
Tom Jetland
Joined: 23 Jun 2011 Posts: 31 Location: UK
|
|
Posted: Mon Oct 29, 2012 3:57 am |
|
|
Thanks guys,
I do sometimes struggle to understand some of the microchip datasheets, so it's great to get a second opinion.
:-)
Tom |
|
|
|