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

Capacitor on SCLK in SPI-Confused

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



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

Capacitor on SCLK in SPI-Confused
PostPosted: Thu Jun 14, 2007 4:58 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2007 6:38 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2007 8:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2007 8:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2007 11:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2007 11:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2007 2:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Jun 14, 2007 4:49 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 15, 2007 6:32 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 15, 2007 7:24 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 20, 2007 7:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 20, 2007 8:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 20, 2007 10:32 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Jun 20, 2007 12:31 pm     Reply with quote

Be careful with the MAX3371 as it is only rated up to 2Mbps.
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Wed Jun 27, 2007 2:50 am     Reply with quote

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