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

SPI MODE NOT WORK .... WHY?

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







SPI MODE NOT WORK .... WHY?
PostPosted: Thu Apr 20, 2006 5:04 pm     Reply with quote

I used ossiloscope measure clock signal but NO SIGNAL
Why not work?please help me.




// Configure chip and compiler
#include "18F458.h"
#fuses EC_IO,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP
#use delay(clock=16000000)
#use rs232(baud=57600, xmit=PIN_C6, rcv=PIN_C7)
#zero_ram

// Aliases for the pins used
#define F88_Servo_CS PIN_B5

#define F88_Aquire_Time 100

// Function prototypes
int readF88(void);

void main(void)
{
// Variables
int data;

// Configure pin direction, format is port X, pin 7 => pin 0; 1 is in, 0 is out
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)
set_tris_a(0b00000000);
set_tris_b(0b10000000);
set_tris_c(0b10010000);
set_tris_d(0b00000000);
set_tris_e(0b00000000);

// Initially set all SPI chip selects to disable
output_high(F88_Servo_CS); // F88 CS is active low

// Setup the SPI port
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_16);

while(1)
{
data = readF88();
printf("This is the data from F88: %d\n",data);
delay_us(100);
}

return;
}

int readF88(void)
{
int F88data;

output_low(F88_Servo_CS); // select the F88 to begin aquisition of data from external source
delay_us(F88_Aquire_Time); // wait the prescribed aquisition delay
F88data = spi_read(0); // aquire the data from the F88 by sending out a clock
output_high(F88_Servo_CS); // disable the F88

return F88data;
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 20, 2006 5:50 pm     Reply with quote

Please don't do a double post. We see every post on this board.

Your program works on my 18F458 test board. I changed the clock
speed to 4 MHz, XT mode, and also the baud rate to 9600 to fit
my test setup.

The printf statement will cause a delay of several milli-seconds between
the groups of SPI clock pulses on pin C3. Depending on your
oscilloscope setting, this delay might make it difficult to see the pulses.
I suggest that you comment out the printf statement, as shown in
bold below. Then you should see the clock pulses.
Quote:
while(1)
{
data = readF88();
// printf("This is the data from F88: %d\n",data);
delay_us(100);
}
tsupuntu
Guest







Thank alot
PostPosted: Fri Apr 21, 2006 8:43 am     Reply with quote

Thank alot
tsupuntu
Guest







Not work this command "F88data = spi_read(0);"
PostPosted: Fri Apr 21, 2006 9:13 am     Reply with quote

I cannot use this command.compile It on error.
But test run to this command It HANK!.Because not work command under it.please help me.

F88data = spi_read(0);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 21, 2006 11:40 am     Reply with quote

I am not sure what you mean.

In your first post, you said the problem is that you have no SPI clock.

Then in your most recent post, you say the problem is that the compiler
gives an error message on this line: F88data = spi_read(0);

If that's true, then how did you test it before and decide that the
problem is no SPI clock ? How did you compile the program before ?

Your program compiles OK with PCH vs. 3.249. What is your compiler
version ?
tsupuntu
Guest







command spi_read() not work
PostPosted: Fri Apr 21, 2006 3:28 pm     Reply with quote

I compiles OK with PCH vs. 3.210.
I thinks command "spi_read(0)" in master mode It made the clock
but now NO Clock.I never SPI interface. Please suggest to me Thank in advance
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 21, 2006 3:42 pm     Reply with quote

Post a link to the website for the "F88" device.
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