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-SLAVE

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







SPI-SLAVE
PostPosted: Mon Nov 26, 2007 4:30 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 4:41 am     Reply with quote

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







PostPosted: Mon Nov 26, 2007 4:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 6:19 am     Reply with quote

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







PostPosted: Mon Nov 26, 2007 6:33 am     Reply with quote

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







PostPosted: Mon Nov 26, 2007 6:36 am     Reply with quote

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







PostPosted: Mon Nov 26, 2007 6:44 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Nov 26, 2007 6:58 am     Reply with quote

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.
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