View previous topic :: View next topic |
Author |
Message |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
SPI for MCP23S17 |
Posted: Fri Feb 22, 2008 5:35 pm |
|
|
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
|
|
Posted: Fri Feb 22, 2008 5:55 pm |
|
|
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
|
|
Posted: Fri Feb 22, 2008 7:27 pm |
|
|
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
|
|
|
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Sat Feb 23, 2008 2:04 pm |
|
|
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
|
|
Posted: Sat Feb 23, 2008 2:19 pm |
|
|
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
|
|
Posted: Sat Feb 23, 2008 3:00 pm |
|
|
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
|
|
Posted: Sun Feb 24, 2008 3:45 pm |
|
|
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
|
|
Posted: Sun Feb 24, 2008 3:58 pm |
|
|
OK, Thanks,
I have the CKE bit too in the 24H SFR.
I will try that this week.
Franck. |
|
|
|