View previous topic :: View next topic |
Author |
Message |
tsupuntu Guest
|
SPI MODE NOT WORK .... WHY? |
Posted: Thu Apr 20, 2006 5:04 pm |
|
|
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;
} |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 20, 2006 5:50 pm |
|
|
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);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
tsupuntu Guest
|
Thank alot |
Posted: Fri Apr 21, 2006 8:43 am |
|
|
Thank alot |
|
![](templates/subSilver/images/spacer.gif) |
tsupuntu Guest
|
Not work this command "F88data = spi_read(0);" |
Posted: Fri Apr 21, 2006 9:13 am |
|
|
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); |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 21, 2006 11:40 am |
|
|
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 ? |
|
![](templates/subSilver/images/spacer.gif) |
tsupuntu Guest
|
command spi_read() not work |
Posted: Fri Apr 21, 2006 3:28 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Apr 21, 2006 3:42 pm |
|
|
Post a link to the website for the "F88" device. |
|
![](templates/subSilver/images/spacer.gif) |
|