View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
Capacitor on SCLK in SPI-Confused |
Posted: Thu Jun 14, 2007 4:58 am |
|
|
Hi
I have an SD card attached to my PIC18LF2550, and I would like to write data to it. Things work well in SPI mode using:
Code: |
setup_spi(SPI_MASTER | SPI_L_H | SPI_CLK_DIV_4);
|
However I do require a 27pF cap fromm the SCLK line to ground.
However when I attach a commercial reader to the card (the SD card is in the circuit still), the card cannot be read. Only when I take out the 27pF cap does it work.
Can anyone please tell me how I can get rid of this capacitor in SPI mode?
Also is this the fastest that SPI can operate at? Will:
Code: |
setup_spi(SPI_MASTER | SPI_L_H);
|
be faster?
Thank you in advance for your help.
a. |
|
|
mskala
Joined: 06 Mar 2007 Posts: 100 Location: Massachusetts, USA
|
|
Posted: Thu Jun 14, 2007 6:38 am |
|
|
I don't understand from your post what is the reason you need a 27pf cap?
More capacitance will limit the max speed of the bus.
Also are you saying the PIC and the commercial reader are connected to the card at the same time? There should not be two SPI masters. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Jun 14, 2007 8:24 am |
|
|
Capacitance on any bus line is a bad thing. Designers need to worry about stray capacitance as the more there is the longer it will take for the bus to change state.
Like mskala, I can't imagine why you would need a cap on that signal line.
Ronald |
|
|
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Thu Jun 14, 2007 8:41 am |
|
|
That's not always true, it depends on the application
I designed an LVDS display driver that needed a 22pf cap on the clock line, running at 20+ mhz, to stabilize the image. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Jun 14, 2007 11:26 am |
|
|
Hi
Thank you for your replies.
I would like not to have the cap on the SCLK line at all. However, if I remove it, no writting to card takes place. Reducing the cap to say 15pF also no writting takes place.
It seems that the problem is occuring upon the SETUP_SPI. But I am not sure that this is true.
How would you remove the stray capacitance?
Regards
a. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 14, 2007 11:29 am |
|
|
Anytime you have to stick a cap on a signal to make it work, look for a
timing problem. It's a bandaid. It's wrong to do it.
Hint:
Look closely at your SPI mode. Check the SD card specification.
Look at sample code on this forum. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Thu Jun 14, 2007 2:23 pm |
|
|
The cap simply makes the SCLK signal reach it's new state slower. Like PCM stated, this indicates a timing problem. Your SCLK must be getting there before it should. If you have access to an oscilloscope see what's happening there. Try taking out the cap and slowing the SCLK down. Don't bandaid. If you do, and you want to change a design, things may not work for the new design.
Ronald |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jun 14, 2007 4:49 pm |
|
|
MMC cards are specified to work for SPI modes 0 and 3.
Code: | setup_spi(SPI_MASTER | SPI_L_H | SPI_CLK_DIV_4); | I don't know the definition of SPI_L_H, in my compiler there is a SPI_L_TO_H.
Assuming you made a typing error this configures the port for SPI mode 1, an invalid configuration for the MMC card and hence your need for a capacitor.
For easy configuration of the SPI modes I've added the following defines Code: | // MOTOROLA MICROCHIP CCS
//---------------------------------------------------------------------------------
// SPI Mode 0,0 == CKP = 0, CKE = 1 == SPI_L_TO_H | SPI_XMIT_L_TO_H
// SPI Mode 0,1 == CKP = 0, CKE = 0 == SPI_L_TO_H
// SPI Mode 1,0 == CKP = 1, CKE = 1 == SPI_H_TO_L
// SPI Mode 1,1 == CKP = 1, CKE = 0 == SPI_H_TO_L | SPI_XMIT_L_TO_H
//
#define SPI_MODE_0_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_0_1 (SPI_L_TO_H)
#define SPI_MODE_1_0 (SPI_H_TO_L)
#define SPI_MODE_1_1 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
Example:
setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_4 ); |
Quote: | Also is this the fastest that SPI can operate at? Will:
Code: | setup_spi(SPI_MASTER | SPI_L_H); |
|
Check the defined value for SPI_CLK_DIV_4 in the header file for your processor. It is defined as 0.
Code: | setup_spi(SPI_MASTER | SPI_L_H | SPI_CLK_DIV_4);
setup_spi(SPI_MASTER | SPI_L_H); | Both lines are equal. The maximum clock frequency for the SPI bus is at Fosc / 4. This means a PIC running at 40MHz has a maximum SPI data rate of 10MHz. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Fri Jun 15, 2007 6:32 am |
|
|
Hi
Thank you for all your replies.
I changed the SPI setup from:
Code: |
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4 );
|
to:
Code: |
setup_spi(SPI_MASTER | (SPI_L_TO_H | SPI_XMIT_L_TO_H) | SPI_CLK_DIV_4 );
|
and it now does not need a cap!--I really appreciate all your help.
(I still dont know what SPI_XMIT_L_TO_H does- but it seems to work!)
Regards
a. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Jun 15, 2007 7:24 am |
|
|
Quote: | (I still dont know what SPI_XMIT_L_TO_H does- but it seems to work!) | When Motorola invented the SPI-bus they left some options open to the hardware designers:
1) Output data on the up-going or down-going edge.
2) Idle state for the clock is high or low.
The various combinations of these two parameters gives a total of 4 operating modes for the SPI bus, called SPI-mode 0 to 3, or binary 00 to 11.
It is important for the transmitter and receiver to have compatible SPI-modes where some receivers can accept only one SPI-mode and some others do accept two modes.
Probably because of copyright reasons Microchip and CCS decided to make things even more complicated by inventing new names for the same bus logic. Microchip calls the two configuration options CKP and CKE, whereas CCS comes with defines like SPI_XMIT_L_TO_H. Check the table I posted earlier for a comparison between all names.
MMC cards are specified to work in both SPI mode 0 and 3. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Wed Jun 20, 2007 7:04 am |
|
|
Hi
I have another question on capacitance. The SPI mode works well and I am interfacing my PIC with an MMC+ card at 3.0V.
Unfortunatley I now need to have my PIC operate at 5.0V (since my sensor requires that to operate). Thus I need to shift the output of my PIC 5.0V to 3.0V input to the MMC+ card.
I have read on this forum that the 74LVC125A chip will do the shifting. I have two questions on this chip:
(a) will I have a capacitance problem when I insert this chip between the PIC and the MMC+ in the SPI mode? The spec sheet says that the power dissipation capacitance per gate is 12pF and the CL can be as high as 50pF?
The data sheet can be found here:
http://www.nxp.com/acrobat_download/datasheets/74LVC125A_4.pdf
(b)will the chip be fast enough if I have a 12MHz Xstal on the PIC and the SPI is running at SPI_CLK_DIV_4? The data sheet says tPH=4.8ns?
Thank you in advance for all your help- its greately appreciated.
Regards
a. |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Jun 20, 2007 8:42 am |
|
|
I've used a MAX3371 to convert between the two voltage levels. It is bi-directional and worked quite well for me.
Ronald |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Wed Jun 20, 2007 10:32 am |
|
|
Hi Ronald
Thank you for your experience.
I have ordered some samples of the MAX3378 (which has 4 level shifters in one package). It gives me some reassurance that it will work!
Regards
a. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
|
Posted: Wed Jun 20, 2007 12:31 pm |
|
|
Be careful with the MAX3371 as it is only rated up to 2Mbps. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Wed Jun 27, 2007 2:50 am |
|
|
Hi
Just an update:
I have obtained a sample of the MAX3378 and it has worked really well in shifting voltage levels from 5V to 3.0V.
Thank you for all your help.
Regards
a. |
|
|
|