View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
SPI - No Clock |
Posted: Mon Dec 27, 2004 12:29 pm |
|
|
I am an SPI newbie, got the RS232 & I2C to work on my 16F88, but not SPI. I am using the simple code below, complier Ver 3.212, and looking for the clock on RB4. I get just a low signal. Any ideas?
Code: |
#include <16F88.h>
#device ICD=TRUE
#fuses NOWDT, NOPROTECT, NOLVP, INTRC_IO
#use delay(clock=8000000)
#use standard_io(A)
#use standard_io(B)
void main(){
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
while (1) {
spi_write(0x55);
delay_ms(100);
}
}
|
Thanks Barney |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 27, 2004 2:02 pm |
|
|
The CCS setup_spi() function doesn't produce correct code for the 16F88
in that version. Try the following test program, which has a substitute
routine to setup the spi port. The routine attempts to copy the same
method used by CCS to setup the SPI.
This substitute routine is just for setting up the SPI Master mode.
I didn't attempt to make it work for setting up Slave mode.
I don't have a 16F88 to test, but the new routine should work.
Code: | #include <16F88.h>
#device ICD=TRUE
#fuses NOWDT, NOPROTECT, NOLVP, INTRC_IO
#use delay(clock=8000000)
#byte SSPCON = 0x14
#byte SSPSTAT = 0x94
#bit SPIEN = SSPCON.5
#define SDI_PIN PIN_B1
#define SDO_PIN PIN_B2
#define SCK_PIN PIN_B4
void my_setup_spi(int16 value)
{
SPIEN = 0;
output_low(SDO_PIN);
output_float(SDI_PIN);
output_low(SCK_PIN);
SSPCON = value;
SSPSTAT = (char)(value >> 8);
}
//=======================
void main()
{
my_setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4);
while(1)
{
spi_write(0x55);
delay_ms(100);
}
} |
|
|
|
Guest Guest
|
|
Posted: Mon Dec 27, 2004 11:04 pm |
|
|
Thanks, worked like a champ.
Is there a known bug list anywhere? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 27, 2004 11:09 pm |
|
|
No, just what you read on this forum. They have a version list
but they don't put everything in it. I'll inform CCS about this bug. |
|
|
arrow
Joined: 17 May 2005 Posts: 213
|
|
Posted: Thu Jun 09, 2005 7:13 am |
|
|
Hi PCM programmer
Do you know if
SETUP_SPI(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_4);
has a problem for the 16F873 chip in
PICC version: 2.686?
All the best
arrow |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jun 09, 2005 1:59 pm |
|
|
View the output on the SPI pins with an oscilloscope and see if looks OK. |
|
|
|