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 for MCP23S17

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



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

SPI for MCP23S17
PostPosted: Fri Feb 22, 2008 5:35 pm     Reply with quote

Hello everybody,

Did someone have already used the GPIO MCP23S17?

I'm trying to set the SPI SFR of a pic 24HJ to communicate with this GPIO but I have some problem to understand the MCP23S17 datasheet.
I can't determine the SCK idle state, when the input have to be sample, etc...

It would be helpful if someone have already set the SPI register of a pic (doesn't matter which pic) to use this component.

Thanks for your help.

Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 5:55 pm     Reply with quote

Download the MCP23S17 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/21952b.pdf
Look at Figure 2-5, on page 32. Look at the line where it says
"SCK" on the left side. It tells you the two SPI modes that are
supported by the chip. The modes are given in binary notation.
You can then use the MODE parameter in the #use spi() statement
to specify the spi mode.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 7:27 pm     Reply with quote

Thanks for your reply,
I've already downloaded the datasheet (and the AN), but I haven't understand what means MODE 1,1 and MODE 0,0...
And I haven't find anything about it in the datasheet. Is it a general term to specify the SPI?

About the #use spi(), I would like to keep the software compatible with oher compiler, so I prefer to work directly with the SFR.

Can you tell me more about MODE ?

Thanks,
Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 22, 2008 7:42 pm     Reply with quote

There are four SPI modes, based on the clock to data timing relationship
and the clock idle state. See this page for an explanation:
http://elm-chan.org/docs/spi_e.html

See my post near the end of this thread. It shows how to specify the
SPI mode with the CCS setup_spi() function.
http://www.ccsinfo.com/forum/viewtopic.php?t=33255
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Sat Feb 23, 2008 2:04 pm     Reply with quote

Thanks for the explanation.

I've tried the defined shown on your post (http://www.ccsinfo.com/forum/viewtopic.php?t=33255):
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)


Unfortunately SPI_XMIT_L_TO_H and SPI_XMIT_L_TO_H are not reconized by the compiler (PCD 4.068).
I did a search in the PCD files and there are not defined anywhere.
Can you give me the values of these 2 #defined?

Thanks,
Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Feb 23, 2008 2:19 pm     Reply with quote

I don't have the PCD compiler, so I can't really help. I only have PCB,
PCM, and PCH.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Sat Feb 23, 2008 3:00 pm     Reply with quote

OK, that's fine,
Can you just tell me if SPI_XMIT_L_TO_H is a parameter to control the polarity of the clock pin or of the data pin?

Thanks,
Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 3:45 pm     Reply with quote

In a 16F or 18F PIC, the SPI_XMIT_L_TO_H parameter sets
the CKE bit = 1. Here is the definition of the CKE bit for those PICs:
Quote:

bit 6 CKE: SPI Clock Select bit
1 = Transmit occurs on transition from active to Idle clock state
0 = Transmit occurs on transition from Idle to active clock state
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Sun Feb 24, 2008 3:58 pm     Reply with quote

OK, Thanks,
I have the CKE bit too in the 24H SFR.
I will try that this week.

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