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 support@ccsinfo.com

adjusting SPI speeds

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







adjusting SPI speeds
PostPosted: Fri Oct 01, 2004 5:44 am     Reply with quote

Hi, I believe I know why im having a problem interfacing a chip to my PIC. Alas, I do not know how to solve it.. The chip is supposed to signal a busy pulse after It successfully reads a byte send from the PIC (the byte is sent the same time a clock is generated).. However, the busy pulse is not being generated until the first bit of the next sent byte.. This picture will hopefully demonstrate:

[img]www.engr.mun.ca/~rob/stuff/help.GIF[/img]

I think the problem is im using the wrong clock edge (even though the manual for the chip im interfacing with says use the falling edge, which is what I am using).. But I guess i'll try the rising edge and see what I get.

The problem is, which I switch from:
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
to
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
I loose control of the clock speed, and differing the CLK_DIV_# has no bearing when I put it on the second mode... Does anyone know why this could be happening?

I need to set the clock to somewhere between 500kHz and 2Mhz, (I'm using a 20Mhz crystal on a PIC18F452)..

Does anyone know how to fix my problem?? Thanks!
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Oct 01, 2004 7:04 am     Reply with quote

Do a search for SPI_CLK_DIV_16 in your headder file. You will find the slower settings there.
rob norris
Guest







PostPosted: Fri Oct 01, 2004 7:08 am     Reply with quote

I have tried the other speed selections, however they do not change the frequency when I am using SPI_L_TO_H mode. The frequency stays locked at 1.25Mhz no matter what DIV I use.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Oct 03, 2004 11:08 am     Reply with quote

Quote:
The problem is, which I switch from:
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
to
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);
I loose control of the clock speed, and differing the CLK_DIV_# has no
bearing when I put it on the second mode...
Does anyone know why this could be happening?

Compile the test program below, and then post the portion of the .LST
file which begins at main().

More questions:
1. What version of the PCH compiler are you using ?
2. How are you measuring the frequency of the SCLK signal ?
Are you using an oscilloscope ?
3. Also, just to be sure, what pin on the PIC are you probing
when you do this ?
4. What test program are you using to generate an SCLK signal
when you measure it ? You should be using a program similar
to the one that I posted in this thread. It's very simple and all
it does is put out a data stream and clock. That's the kind of
program you need to be using when you test the clock speed.
http://www.ccsinfo.com/forum/viewtopic.php?t=20520



#include <18F452.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)

//====================================
void main()
{

setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);

setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);

while(1);
}

This is the code produced by the above program for PCH 3.188.
Please post the same block of code from your .LST file, after
you compile it.

Code:
0000                00294 .................... void main() 
0000                00295 .................... { 
0004 FFFF           00296 NOP(FFFF)
0006 6AF8           00297 CLRF   FF8
0008 9ED0           00298 BCF    FD0.7
000A 6AEA           00299 CLRF   FEA
000C 6AE9           00300 CLRF   FE9
000E 0E06           00301 MOVLW  06
0010 6EC1           00302 MOVWF  FC1
0000                00303 ....................   
0000                00304 ....................   
0000                00305 .................... setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);   
0012 9AC6           00306 BCF    FC6.5
0014 9A94           00307 BCF    F94.5
0016 9694           00308 BCF    F94.3
0018 0E21           00309 MOVLW  21
001A 6EC6           00310 MOVWF  FC6
001C 0E00           00311 MOVLW  00
001E 6EC7           00312 MOVWF  FC7
0000                00313 ....................   
0000                00314 ....................   
0000                00315 .................... while(1); 
0020 EF10 F000      00316 GOTO   0020
0000                00317 .................... } 
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