View previous topic :: View next topic |
Author |
Message |
Sharock Guest
|
SPI-SLAVE |
Posted: Mon Nov 26, 2007 4:30 am |
|
|
Hi,
in our application we use a PIC as a SPI-MASTER and one PIC as a SPI-SLAVE.
My Setup for the PIC Master is setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
and the SLAVE Setup is
setup_spi(SPI_SLAVE|SPI_SS_DISABLED);
My Problem is that the SLAVE only get correct data if i change the MASTER SETUP to
setup_spi(SPI-MASTER | SPI_H_TO_L | SPI_CLK_DIV_4);
Have someone a idea why i can´t use differnt SPI MODES?
Regards
Sharock |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Nov 26, 2007 4:41 am |
|
|
Code: | setup_spi(SPI_SLAVE|SPI_SS_DISABLED); | Your slave definition is missing the defines for the clock mode. Look at the header file and you will see that SPI_H_TO_L is defined as 0, that is the default mode you are now using.
There are a total of four SPI clock modes. Depending on your device some modes are compatible but for for best comaptibility you choose the same mode for both sender and transmitter.
Quote: | Have someone a idea why i can´t use differnt SPI MODES? | Let's answer this with another question: Can you give me a reason why you would want to mix different SPI modes? |
|
|
Sharock Guest
|
|
Posted: Mon Nov 26, 2007 4:51 am |
|
|
Hi,
at the Master i must use the setup:
(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
For the salve i´m free. I try also already this setup for the slave
(SPI_SLAVE|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
but the i recieved wrong data!
Regards |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Nov 26, 2007 6:19 am |
|
|
Sharock wrote: | at the Master i must use the setup:
(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
For the salve i´m free. I try also already this setup for the slave
(SPI_SLAVE|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
but the i recieved wrong data! | This is strange, with the same SPI mode at both sides it should work.
One problem in your setup is that for the slave you should not set the clock speed (only the master is generating the clock). But for most processors the constant SPI_CLK_DIV_4 is defined as zero, so it doesn't change the setting.
Which processor are you using?
What is your compiler version?
Quote: | at the Master i must use the setup:
(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4); | I do not understand this. Why must you use this setup? Is it because you have more devices on the same SPI bus?
If yes, then do you have a chip-select line for each device? |
|
|
Sharock Guest
|
|
Posted: Mon Nov 26, 2007 6:33 am |
|
|
Hi,
we produce 2 differnt types of "keyboards". ( Car operation Panel for a Elevator ). One of them have Sensorbuttons and the other one works with normal Pushbuttons. The Sensorkeyboard use a special IC to detect the Sensorsbuttons and send the Information by SPI. For this IC we must use the setup
(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_DIV_4);
At the Pushbuttonkeyboard we use a PIC and want to emulate the SensorIC so we just need one Software for the Device which read out the data from the keyboards.
Regards
Sharock |
|
|
Sharock Guest
|
|
Posted: Mon Nov 26, 2007 6:36 am |
|
|
I forgot to answer your Question:
The Compiler is 4.012
The Master PIC is a 18F2520
The Slave PIC is a 16F876
Both running on 20Mhz.
Regards |
|
|
Sharock Guest
|
|
Posted: Mon Nov 26, 2007 6:44 am |
|
|
Hi,
you just solve it. I remove the clock settings on the slave, and it runs now.
Thanks a lot for your hint |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Nov 26, 2007 6:58 am |
|
|
I don't have compiler version v4.012 so can't test differences with and without the clock settings. Like I said, for all processors I checked the DIV_4 clock setting is defined as zero and shouldn't matter.
Are you using the chip select line? It could be a power up problem, like missing pull-up resistors.
Please note that the early v4.0xx compilers had _many_ problems and I strongly advise not to use this version (save everybody a lot of time). Best is to use the older v3.249 or v4.030 and higher. |
|
|
|