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 Select and Interrupt
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bwhiten



Joined: 26 Nov 2003
Posts: 151
Location: Grayson, GA

View user's profile Send private message

SPI Slave Select and Interrupt
PostPosted: Wed May 14, 2008 12:08 pm     Reply with quote

I can't seem to find much information in the forum on SPI Slaves and even less in the CCS help files. In particular I would like to know if the #INT_SSP on a Slave PIC is set by the state of Slave_Select or just by activity on the SPI clock lines. I want to use Slave Select to help frame complete data transfers between PICs.
Second question, I tried to use the SPI1 parameter in the Slave #use spi() statement but it errored out with Option Invalid, Not valid for H/W.
Is this because a slave must use the H/W SPI?

Slave = 16F887
Master = 18F67J50
Version 4.073
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 14, 2008 12:24 pm     Reply with quote

Quote:

I would like to know if the #INT_SSP on a Slave PIC is set by the state of
Slave_Select or just by activity on the SPI clock lines

Look at the following timing diagram in the PIC data sheet.
It shows that SSPIF is set soon after bit 0 is received. This means you
get an interrupt when a complete byte has been received by the slave.
Quote:
FIGURE 13-3: SLAVE SYNCHRONIZATION WAVEFORM



Quote:

I tried to use the SPI1 parameter in the Slave #use spi() statement but it
errored out with Option Invalid, Not valid for H/W.

See this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=34214
bwhiten



Joined: 26 Nov 2003
Posts: 151
Location: Grayson, GA

View user's profile Send private message

PostPosted: Wed May 14, 2008 12:45 pm     Reply with quote

Thanks for the help....again Smile

Quote:

I tried to use the SPI1 parameter in the Slave #use spi() statement but it
errored out with Option Invalid, Not valid for H/W.
See this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=34214


I had found that link and tried adding the MSB_FIRST parameter but it still won't let me add SPI1:

Code:
#use spi(SLAVE, MODE = 0, BITS=8, MSB_FIRST, SPI1)


According to the help file if you use the SPIx parameter that automatically assigns the HW pins as the SPI interface.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 14, 2008 1:14 pm     Reply with quote

I don't know. There has got to be some combination of parameters
that will make it work. Or maybe it's a bug. I've tried for a while and
I don't have any more time to spend on it.
bwhiten



Joined: 26 Nov 2003
Posts: 151
Location: Grayson, GA

View user's profile Send private message

PostPosted: Wed May 14, 2008 1:18 pm     Reply with quote

Thanks very much for the help.
Maybe someone else has seen this. I will submit a question to CCS but I've not had a lot of luck getting responses lately. Plus email notices from posts I'm part of no longer works :(
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed May 14, 2008 3:51 pm     Reply with quote

I can not find a reference to the SPI1 parameter in the manual. Where did you read about it?
Ttelmah
Guest







PostPosted: Thu May 15, 2008 2:32 am     Reply with quote

Look under #USE SPI in the manual.
The 'older' setup_SPI command works fine. I'd suggest just using this, since the only real advantage of the #use form, is when dealing with multiple SPI ports, or wanting to perform software SPI.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 15, 2008 5:54 am     Reply with quote

Ttelmah wrote:
Look under #USE SPI in the manual.
Yes, that's what I figured but I can't find this parameter. A search of the document didn't find it either.
I have the Version 4, August 2007 manual.
I also checked the latest versions of the PCWH and PCWHD manuals on the CCS website and can't find the parameter.

Strange. For the PICs with more than one SPI unit I would expect there to be a parameter to indicate which hardware unit to use.
Ttelmah
Guest







PostPosted: Thu May 15, 2008 7:42 am     Reply with quote

A quick check through some versions:
4.027 - Doesn't even have a #use SPI entry
4.042 - Has the entry, but without SPI1/SPI2
4.051 - Has it mentioned in the 'readme', but not in the manual
4.059 - Has SPI1/SPI2 in the manual.

Critical date, seems to be about October 2007.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 15, 2008 8:47 am     Reply with quote

Can you tell me where you downloaded these manual versions from? The only manual I can find on the CCS download page is the 4-Aug-2007 version.
Ttelmah
Guest







PostPosted: Thu May 15, 2008 9:58 am     Reply with quote

Just the versions that come with the actual compiler downloads. The separate versions available for download, seem to be months out of date...

Best Wishes
bwhiten



Joined: 26 Nov 2003
Posts: 151
Location: Grayson, GA

View user's profile Send private message

No email again
PostPosted: Thu May 15, 2008 11:48 am     Reply with quote

Again, I received no email notice of these responses. I see the SPI1, SPI2 parameter in the help file of the compiler under the #use spi heading.
I was trying to use the #use spi command that allowed me to use the spi_xfer() command instead of spi_read and spi_write.
What method of assigning pins to the correct H/W spi is used if I only declare with the setup_spi() command?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 15, 2008 12:09 pm     Reply with quote

The setup_spi() function automatically uses the hardware SPI pins.
It will only work the those pins. It only does hardware SPI.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu May 15, 2008 12:35 pm     Reply with quote

Ttelmah, thanks for the info. I didn't know in the automatic downloads more up to date versions of the manuals are included.

Bwhiten, thanks for the CCS help function tip. I forgot about that one.

Quote:
What method of assigning pins to the correct H/W spi is used if I only declare with the setup_spi() command?
setup_spi() uses the first HW unit (on pins C3, C4 and C5)
setup_spi2() uses the second hardware unit if present.

For defining the SPI mode I always use the defines below instead of the CCS definitions:
Code:
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)
So setting up your slave becomes:
Code:
setup_spi(SPI_SLAVE | SPI_MODE_0 );
bwhiten



Joined: 26 Nov 2003
Posts: 151
Location: Grayson, GA

View user's profile Send private message

How about the master setup?
PostPosted: Thu May 15, 2008 8:39 pm     Reply with quote

ckielstra wrote:
For defining the SPI mode I always use the defines below instead of the CCS definitions:
Code:
#define SPI_MODE_0  (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1  (SPI_L_TO_H)
#define SPI_MODE_2  (SPI_H_TO_L)
#define SPI_MODE_3  (SPI_H_TO_L | SPI_XMIT_L_TO_H)
So setting up your slave becomes:
Code:
setup_spi(SPI_SLAVE | SPI_MODE_0 );


What is the SPI_XMIT_L_TO_H used for and how would you set up a master using these #defines ?

Thanks again.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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